Changes: Christian Thalinger
Edwin Steiner
- $Id: threads.c 4728 2006-04-04 09:17:05Z twisti $
+ $Id: threads.c 4865 2006-05-01 12:40:18Z edwin $
*/
#endif /* MUTEXSIM */
+/* threads_sem_wait ************************************************************
+
+ Wait for a semaphore, non-interruptible.
+
+ IMPORTANT: Always use this function instead of `sem_wait` directly, as
+ `sem_wait` may be interrupted by signals!
+
+ IN:
+ sem..............the semaphore to wait on
+
+*******************************************************************************/
+
+void threads_sem_wait(sem_t *sem)
+{
+ int r;
+
+ do {
+ r = sem_wait(sem);
+ if (r == 0)
+ return;
+ } while (errno == EINTR);
+
+ fprintf(stderr,"error: sem_wait returned unexpected error %d: %s\n",
+ errno, strerror(errno));
+ abort();
+}
+
static void setPriority(pthread_t tid, int priority)
{
struct sched_param schedp;
#else
count = cast_sendsignals(GC_signum1(), 0);
for (i=0; i<count; i++)
- sem_wait(&suspend_ack);
+ threads_sem_wait(&suspend_ack);
#endif
pthread_mutex_unlock(&threadlistlock);
}
/* Seems like we've encountered a situation where info->tid was not set by
* pthread_create. We alleviate this problem by waiting for pthread_create
* to return. */
- sem_wait(startup->psem_first);
+ threads_sem_wait(startup->psem_first);
t = NULL;
#if defined(__DARWIN__)
/* wait here until the thread has entered itself into the thread list */
- sem_wait(&sem);
+ threads_sem_wait(&sem);
sem_destroy(&sem);
sem_destroy(&sem_first);
}
MEMORY_BARRIER_AFTER_ATOMIC();
if (lr->o == o)
- sem_wait(&lr->queueSem);
+ threads_sem_wait(&lr->queueSem);
atomic_add(&lr->queuers, -1);
}
/* if the object still refers to lr, replace it by the new mlr */
MEMORY_BARRIER_BEFORE_ATOMIC();
- nlr = (void*) compare_and_swap((long*) &o->monitorPtr, (long) lr, (long) mlr);
+ nlr = (monitorLockRecord *) compare_and_swap((long*) &o->monitorPtr, (long) lr, (long) mlr);
}
if (nlr == lr) {