Lines Matching refs:mtx

56 int mtx_init(mtx_t *mtx, int type)
59 mtx->mAlreadyLocked = FALSE;
60 mtx->mRecursive = type & mtx_recursive;
61 InitializeCriticalSection(&mtx->mHandle);
71 ret = pthread_mutex_init(mtx, &attr);
77 void mtx_destroy(mtx_t *mtx)
80 DeleteCriticalSection(&mtx->mHandle);
82 pthread_mutex_destroy(mtx);
86 int mtx_lock(mtx_t *mtx)
89 EnterCriticalSection(&mtx->mHandle);
90 if (!mtx->mRecursive)
92 while(mtx->mAlreadyLocked) Sleep(1000); /* Simulate deadlock... */
93 mtx->mAlreadyLocked = TRUE;
97 return pthread_mutex_lock(mtx) == 0 ? thrd_success : thrd_error;
101 int mtx_timedlock(mtx_t *mtx, const struct timespec *ts)
104 (void)mtx;
109 int mtx_trylock(mtx_t *mtx)
112 int ret = TryEnterCriticalSection(&mtx->mHandle) ? thrd_success : thrd_busy;
113 if ((!mtx->mRecursive) && (ret == thrd_success) && mtx->mAlreadyLocked)
115 LeaveCriticalSection(&mtx->mHandle);
120 return (pthread_mutex_trylock(mtx) == 0) ? thrd_success : thrd_busy;
124 int mtx_unlock(mtx_t *mtx)
127 mtx->mAlreadyLocked = FALSE;
128 LeaveCriticalSection(&mtx->mHandle);
131 return pthread_mutex_unlock(mtx) == 0 ? thrd_success : thrd_error;;
237 static int _cnd_timedwait_win32(cnd_t *cond, mtx_t *mtx, DWORD timeout)
248 mtx_unlock(mtx);
279 mtx_lock(mtx);
285 int cnd_wait(cnd_t *cond, mtx_t *mtx)
288 return _cnd_timedwait_win32(cond, mtx, INFINITE);
290 return pthread_cond_wait(cond, mtx) == 0 ? thrd_success : thrd_error;
294 int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts)
302 return _cnd_timedwait_win32(cond, mtx, delta);
308 ret = pthread_cond_timedwait(cond, mtx, ts);