From 62024711e10c2b27e097e0e8876689ae6187e28d Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Thu, 27 Dec 2012 00:29:19 +0000 Subject: [PATCH] opt/nothread: add support for recursion --- opt/nothread/mtx_lock.c | 6 ++---- opt/nothread/mtx_trylock.c | 8 ++------ opt/nothread/mtx_unlock.c | 7 +++---- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/opt/nothread/mtx_lock.c b/opt/nothread/mtx_lock.c index d086986..efe26bd 100644 --- a/opt/nothread/mtx_lock.c +++ b/opt/nothread/mtx_lock.c @@ -3,10 +3,8 @@ int mtx_lock(mtx_t *mtx) { - if(*mtx == 0) { - *mtx = 1; - return thrd_success; - } else return thrd_error; + (*mtx)++; + return thrd_success; } #endif diff --git a/opt/nothread/mtx_trylock.c b/opt/nothread/mtx_trylock.c index bffc8b8..20efc99 100644 --- a/opt/nothread/mtx_trylock.c +++ b/opt/nothread/mtx_trylock.c @@ -3,12 +3,8 @@ int mtx_trylock(mtx_t *mtx) { - if(*mtx) { - return thrd_error; - } else { - *mtx = 1; - return thrd_success; - } + (*mtx)++; + return thrd_success; } #endif diff --git a/opt/nothread/mtx_unlock.c b/opt/nothread/mtx_unlock.c index 214a063..97a93a6 100644 --- a/opt/nothread/mtx_unlock.c +++ b/opt/nothread/mtx_unlock.c @@ -3,10 +3,9 @@ int mtx_unlock(mtx_t *mtx) { - if(*mtx) { - *mtx = 0; - return thrd_success; - } else return thrd_error; + if(--(*mtx) >= 0) + return thrd_success; + return thrd_error; } #endif -- 2.40.0