if (mutex->__m_owner != self) return EINVAL;
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex){  volatile pthread_descr self = thread_self();  pthread_extricate_if extr;  int already_canceled = 0;  /* Set up extrication interface */  extr.pu_object = cond;  extr.pu_extricate_func = cond_extricate_func;  /* Register extrication interface */  __pthread_set_own_extricate_if(self, &extr);  /* Atomically enqueue thread for waiting, but only if it is not     canceled. If the thread is canceled, then it will fall through the     suspend call below, and then call pthread_exit without     having to worry about whether it is still on the condition variable queue.     This depends on pthread_cancel setting p_canceled before calling the     extricate function. */  __pthread_lock(&cond->__c_lock, self);  if (!(THREAD_GETMEM(self, p_canceled)      && THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE))    enqueue(&cond->__c_waiting, self);  else    already_canceled = 1;  __pthread_unlock(&cond->__c_lock);  if (already_canceled) {    __pthread_set_own_extricate_if(self, 0);    pthread_exit(PTHREAD_CANCELED);  }  pthread_mutex_unlock(mutex);  suspend(self);  __pthread_set_own_extricate_if(self, 0);  /* Check for cancellation again, to provide correct cancellation     point behavior */  if (THREAD_GETMEM(self, p_woken_by_cancel)      && THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE) {    THREAD_SETMEM(self, p_woken_by_cancel, 0);    pthread_mutex_lock(mutex);    pthread_exit(PTHREAD_CANCELED);  }  pthread_mutex_lock(mutex);  return 0;}