int pthread_mutex_unlock(pthread_mutex_t *m) { int r = mutex_ref_unlock(m); if(r) return r; mutex_t *_m = (mutex_t *)*m; if (_m->type == PTHREAD_MUTEX_NORMAL) { if (!COND_LOCKED(_m)) return mutex_unref(m,EPERM); } else if (!COND_LOCKED(_m) || !COND_OWNER(_m)) return mutex_unref(m,EPERM); if (_m->type == PTHREAD_MUTEX_RECURSIVE) { if(InterlockedDecrement(&_m->count)) return mutex_unref(m,0); } #if defined USE_MUTEX_Mutex UNSET_OWNER(_m); if (_m->h != NULL && !ReleaseSemaphore(_m->h, 1, NULL)) { SET_OWNER(_m); /* restore our own bookkeeping */ return mutex_unref(m,EPERM); } #else /* USE_MUTEX_CriticalSection */ UNSET_OWNER(_m); LeaveCriticalSection(&_m->cs.cs); #endif return mutex_unref(m,0); }
int pthread_mutex_unlock(pthread_mutex_t *m) { mutex_t *_m; int r = mutex_ref_unlock(m); if(r) { #if 0 printf("thread %d, la pool, no user unset in mutex %p\n", GetCurrentThreadId(), m); #endif return r; } _m = (mutex_t *)*m; if (_m->type == PTHREAD_MUTEX_NORMAL) { if (!COND_LOCKED(_m)) { #if 0 printf("thread %d, mutex %p never locked, actually :p\n", GetCurrentThreadId(), m); #endif return mutex_unref(m, EPERM); } } else if (!COND_LOCKED(_m) || !COND_OWNER(_m)) { #if 0 printf("thread %d, mutex %p never locked or not owner, actually :p\n", GetCurrentThreadId(), m); #endif return mutex_unref(m,EPERM); } if (_m->type == PTHREAD_MUTEX_RECURSIVE) { if(InterlockedDecrement(&_m->count)) { #if 0 printf("thread %d, mutex %p decreasing recursive\n", GetCurrentThreadId(), m); #endif return mutex_unref(m,0); } } #if 0 printf("thread %d,unsetting owner of mutex %p\n", GetCurrentThreadId(), m); #endif UNSET_OWNER(_m); if (_m->h != NULL && !ReleaseSemaphore(_m->h, 1, NULL)) { SET_OWNER(_m); #if 0 printf("Error, not released! thread %d, setting owner of mutex m\n", GetCurrentThreadId(), m); #endif /* restore our own bookkeeping */ return mutex_unref(m,EPERM); } return mutex_unref(m,0); }
int pthread_mutex_unlock(pthread_mutex_t *m) { mutex_t *_m; int r = mutex_ref_unlock(m); if(r) { return r; } _m = (mutex_t *)*m; if (_m->type == PTHREAD_MUTEX_NORMAL) { if (!COND_LOCKED(_m)) { return mutex_unref(m, EPERM); } } else if (!COND_LOCKED(_m) || !COND_OWNER(_m)) { return mutex_unref(m,EPERM); } if (_m->type == PTHREAD_MUTEX_RECURSIVE) { if(InterlockedDecrement(&_m->count)) { return mutex_unref(m,0); } } UNSET_OWNER(_m); if (_m->h != NULL && !ReleaseSemaphore(_m->h, 1, NULL)) { SET_OWNER(_m); /* restore our own bookkeeping */ return mutex_unref(m,EPERM); } return mutex_unref(m,0); }