int fthread_cond_wait(fthread_cond_t *cond, fthread_mutex_t *mutex) { if (cond->__waitm) { /* there should only be one mutex being used for concurrent waits on a single condition variable */ if (cond->__waitm != mutex) { return EINVAL; } } else { cond->__waitm = mutex; } /* we also need to own the mutex */ int err = fthread_mutex_unlock(mutex); if (err) { return err; } /* can't destroy a mutex while it's being used in a cond_wait: * have to up the use count so any calls to destroy will fail with * EBUSY */ mutex->__usecount++; cond->__usecount++; sched_sleep_on(&cond->__waitq); fthread_mutex_lock(mutex); mutex->__usecount--; cond->__usecount--; return 0; }
DLL_EXPORT int ptt_pthread_mutex_lock(LOCK *mutex, char *loc) { int result; PTTRACE ("lock before", mutex, NULL, loc, PTT_MAGIC); result = fthread_mutex_lock(mutex); if (result == EDEADLK) logmsg("\n ++++++++++++++++ DEADLOCK! %s ++++++++++++++++\n\n",loc); PTTRACE ("lock after", mutex, NULL, loc, result); return result; }