Skip to content

Commit

Permalink
add win32 mutex handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed May 11, 2022
1 parent 3c443a1 commit 08de57a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/thread/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,47 @@ int cnd_wait(cnd_t *cnd, mtx_t *mtx)

return thrd_success;
}


int mtx_init(mtx_t *mtx, int type)
{
(void)type;

if (!mtx)
return thrd_error;

InitializeCriticalSection(mtx);

return thrd_success;
}


int mtx_lock(mtx_t *mtx)
{
if (!mtx)
return thrd_error;

EnterCriticalSection(mtx);

return thrd_success;
}


int mtx_trylock(mtx_t *mtx)
{
if (!mtx)
return thrd_error;

return TryEnterCriticalSection(mtx) ? thrd_success : thrd_busy;
}


int mtx_unlock(mtx_t *mtx)
{
if (!mtx)
return thrd_error;

LeaveCriticalSection(mtx);

return thrd_success;
}

0 comments on commit 08de57a

Please sign in to comment.