#include "gwlib/gwlib.h"#include <semaphore.h>#include <errno.h>Include dependency graph for semaphore.c:

Go to the source code of this file.
Data Structures | |
| struct | Semaphore |
Functions | |
| Semaphore * | semaphore_create (long n) |
| void | semaphore_destroy (Semaphore *semaphore) |
| void | semaphore_up (Semaphore *semaphore) |
| void | semaphore_down (Semaphore *semaphore) |
| long | semaphore_getvalue (Semaphore *semaphore) |
|
|
Definition at line 81 of file semaphore.c. References gwlist_add_producer(), gwlist_create, gwlist_produce(), and panic. Referenced by httpd_emu_create(), init_smsbox(), run_smsbox(), smpp_emu(), and smsc_emu_create(). 00082 {
00083 Semaphore *semaphore;
00084 #ifndef HAVE_SEMAPHORE
00085 static char item;
00086 #endif
00087
00088 semaphore = gw_malloc(sizeof(*semaphore));
00089
00090 #ifdef HAVE_SEMAPHORE
00091 if (sem_init(&semaphore->sem, 0, (unsigned int) n) != 0)
00092 panic(errno, "Could not initialize semaphore.");
00093 #else
00094 semaphore->list = gwlist_create();
00095 gwlist_add_producer(semaphore->list);
00096 while (n-- > 0)
00097 gwlist_produce(semaphore->list, &item);
00098 #endif
00099
00100 return semaphore;
00101 }
|
Here is the call graph for this function:

|
|
Definition at line 104 of file semaphore.c. References gwlist_destroy(), panic, and Semaphore::sem. Referenced by httpd_emu_create(), main(), run_smsbox(), smpp_emu(), and smsc_emu_create(). 00105 {
00106 if (semaphore != NULL) {
00107 #ifdef HAVE_SEMAPHORE
00108 if (sem_destroy(&semaphore->sem) != 0)
00109 panic(errno, "Destroying semaphore while some threads are waiting.");
00110 #else
00111 gwlist_destroy(semaphore->list, NULL);
00112 #endif
00113 gw_free(semaphore);
00114 }
00115 }
|
Here is the call graph for this function:

|
|
Definition at line 132 of file semaphore.c. References gw_assert, gwlist_consume(), and Semaphore::sem. Referenced by boxc_sent_push(), httpd_emu_create(), obey_request(), smpp_emu_writer(), and smsc_emu_create(). 00133 {
00134 gw_assert(semaphore != NULL);
00135 #ifdef HAVE_SEMAPHORE
00136 sem_wait(&semaphore->sem);
00137 #else
00138 gwlist_consume(semaphore->list);
00139 #endif
00140 }
|
Here is the call graph for this function:

|
|
Definition at line 143 of file semaphore.c. References gw_assert, gwlist_len(), panic, and Semaphore::sem. 00144 {
00145 gw_assert(semaphore != NULL);
00146 #ifdef HAVE_SEMAPHORE
00147 {
00148 int val;
00149 if (sem_getvalue(&semaphore->sem, &val) != 0)
00150 panic(errno, "Could not get semaphore value.");
00151 return val;
00152 }
00153 #else
00154 return gwlist_len(semaphore->list);
00155 #endif
00156 }
|
Here is the call graph for this function:

|
|
Definition at line 118 of file semaphore.c. References error(), gw_assert, gwlist_produce(), and Semaphore::sem. Referenced by boxc_sent_pop(), httpd_emu(), obey_request(), run_smsbox(), smpp_emu(), smpp_emu_handle_pdu(), and url_result_thread(). 00119 {
00120 #ifndef HAVE_SEMAPHORE
00121 static char item;
00122 gw_assert(semaphore != NULL);
00123 gwlist_produce(semaphore->list, &item);
00124 #else
00125 gw_assert(semaphore != NULL);
00126 if (sem_post(&semaphore->sem) != 0)
00127 error(errno, "Value for semaphore is out of range.");
00128 #endif
00129 }
|
Here is the call graph for this function:
