diff --git a/configure.ac b/configure.ac
index 576a26e..0b789ee 100644
a
|
b
|
case "${host}" in |
175 | 175 | *-apple-darwin*) |
176 | 176 | AC_SEARCH_LIBS([dispatch_semaphore_create],[dispatch], |
177 | 177 | [AC_DEFINE([HAVE_LIB_DISPATCH],1,[Defined if we have libdispatch])]) |
| 178 | if test "$ac_cv_search_dispatch_semaphore_create" = no; then |
| 179 | AC_DEFINE(HAVE_NO_POSIX_SEMAPHORE,1,[Define if no good semaphore.]) |
| 180 | fi |
178 | 181 | ;; |
179 | 182 | *-*-aix*) |
180 | 183 | have_fork_unsafe_semaphore=yes |
diff --git a/src/npth.c b/src/npth.c
index 044a291..c7b42df 100644
a
|
b
|
sem_wait (sem_t *sem) |
62 | 62 | dispatch_semaphore_wait (*sem, DISPATCH_TIME_FOREVER); |
63 | 63 | return 0; |
64 | 64 | } |
| 65 | #elif HAVE_NO_POSIX_SEMAPHORE |
| 66 | /* Fallback implementation without POSIX semaphore, |
| 67 | for a system like MacOS Tiger */ |
| 68 | typedef struct { |
| 69 | pthread_mutex_t mutex; |
| 70 | pthread_cond_t cond; |
| 71 | unsigned int value; |
| 72 | } sem_t; |
| 73 | |
| 74 | static int |
| 75 | sem_init (sem_t *sem, int is_shared, unsigned int value) |
| 76 | { |
| 77 | int r; |
| 78 | |
| 79 | (void)is_shared; /* Not supported. */ |
| 80 | r = pthread_mutex_init (&sem->mutex, NULL); |
| 81 | if (r) |
| 82 | return r; |
| 83 | r = pthread_cond_init (&sem->cond, NULL); |
| 84 | if (r) |
| 85 | return r; |
| 86 | sem->value = value; |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static int |
| 91 | sem_post (sem_t *sem) |
| 92 | { |
| 93 | int r; |
| 94 | |
| 95 | r = pthread_mutex_lock (&sem->mutex); |
| 96 | if (r) |
| 97 | return r; |
| 98 | |
| 99 | sem->value++; |
| 100 | pthread_cond_signal (&sem->cond); |
| 101 | |
| 102 | r = pthread_mutex_unlock (&sem->mutex); |
| 103 | if (r) |
| 104 | return r; |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int |
| 109 | sem_wait (sem_t *sem) |
| 110 | { |
| 111 | int r; |
| 112 | |
| 113 | r = pthread_mutex_lock (&sem->mutex); |
| 114 | if (r) |
| 115 | return r; |
| 116 | |
| 117 | while (sem->value == 0) |
| 118 | pthread_cond_wait (&sem->cond, &sem->mutex); |
| 119 | sem->value--; |
| 120 | |
| 121 | r = pthread_mutex_unlock (&sem->mutex); |
| 122 | if (r) |
| 123 | return r; |
| 124 | return 0; |
| 125 | } |
65 | 126 | #else |
66 | 127 | # include <semaphore.h> |
67 | 128 | #endif |