X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fthreads%2Fposix%2Fthread-posix.cpp;h=6db5dfdab5e7d79f6b3ade281e7675469e8ce54c;hb=8cb890651dc1accd5b81418eae55c9b45f8bf8ec;hp=2e0ac45b590658415a9649d8b69149c60831755d;hpb=c0833bef371fdba884acb9976c069ce35e121eea;p=cacao.git diff --git a/src/threads/posix/thread-posix.cpp b/src/threads/posix/thread-posix.cpp index 2e0ac45b5..6db5dfdab 100644 --- a/src/threads/posix/thread-posix.cpp +++ b/src/threads/posix/thread-posix.cpp @@ -109,10 +109,10 @@ extern "C" { from Boehm-GC. */ /* - This is a very simple semaphore implementation for darwin. It + This is a very simple semaphore implementation for Darwin. It is implemented in terms of pthreads calls so it isn't async signal safe. This isn't a problem because signals aren't used to - suspend threads on darwin. + suspend threads on Darwin. */ static int sem_init(sem_t *sem, int pshared, int value) @@ -120,12 +120,9 @@ static int sem_init(sem_t *sem, int pshared, int value) if (pshared) assert(0); - sem->value = value; - sem->mutex = new Mutex(); - - if (pthread_cond_init(&sem->cond, NULL) < 0) - return -1; + sem->cond = new Condition(); + sem->value = value; return 0; } @@ -133,14 +130,8 @@ static int sem_init(sem_t *sem, int pshared, int value) static int sem_post(sem_t *sem) { sem->mutex->lock(); - sem->value++; - - if (pthread_cond_signal(&sem->cond) < 0) { - sem->mutex->unlock(); - return -1; - } - + sem->cond->signal(); sem->mutex->unlock(); return 0; @@ -151,12 +142,10 @@ static int sem_wait(sem_t *sem) sem->mutex->lock(); while (sem->value == 0) { -#error We cannot call pthread_cond_wait on a Mutex-class pointer. - pthread_cond_wait(&sem->cond, &sem->mutex); + sem->cond->wait(sem->mutex); } sem->value--; - sem->mutex->unlock(); return 0; @@ -164,9 +153,7 @@ static int sem_wait(sem_t *sem) static int sem_destroy(sem_t *sem) { - if (pthread_cond_destroy(&sem->cond) < 0) - return -1; - + delete sem->cond; delete sem->mutex; return 0; @@ -1531,7 +1518,7 @@ void threads_thread_interrupt(threadobject *t) /* Interrupt blocking system call using a signal. */ - pthread_kill(t->tid, Signal_THREAD_INTERRUPT); + pthread_kill(t->tid, Signal_INTERRUPT_SYSTEM_CALL); t->waitcond->signal();