From 038c2c9678e6c375003ee3cbadd86a082b108315 Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Thu, 9 Dec 2010 17:41:11 +0100 Subject: [PATCH] Added semaphore functions. --- mpsl_f.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/mpsl_f.c b/mpsl_f.c index 7fcda0e..1cb7971 100644 --- a/mpsl_f.c +++ b/mpsl_f.c @@ -1232,6 +1232,7 @@ static mpdm_t F_mutex(F_ARGS) /** * mutex_lock - Locks a mutex (possibly waiting). + * @mtx: the mutex * * Locks a mutex. If the mutex is already locked by * another process, it waits until it's unlocked. @@ -1247,6 +1248,7 @@ static mpdm_t F_mutex_lock(F_ARGS) /** * mutex_unlock - Unlocks a mutex. + * @mtx: the mutex * * Unlocks a mutex. * [Threading] @@ -1259,6 +1261,51 @@ static mpdm_t F_mutex_unlock(F_ARGS) } +/** + * semaphore - Returns a new semaphore. + * cnt: the initial count of the semaphore. + * + * Returns a new semaphore. + * [Threading] + */ +/** var = semaphore(cnt); */ +static mpdm_t F_semaphore(F_ARGS) +{ + return mpdm_new_semaphore(IA0); +} + + +/** + * semaphore_wait - Waits for a semaphore to be ready. + * @sem: the semaphore to wait onto + * + * Waits for the value of a semaphore to be > 0. If it's + * not, the thread waits until it is. + * [Threading] + */ +/** semaphore_wait(sem); */ +static mpdm_t F_semaphore_wait(F_ARGS) +{ + mpdm_semaphore_wait(A0); + return NULL; +} + + +/** + * semaphore_post - Increments the value of a semaphore. + * @sem: the semaphore to increment + * + * Increments by 1 the value of a semaphore. + * [Threading] + */ +/** semaphore_post(mtx); */ +static mpdm_t F_semaphore_post(F_ARGS) +{ + mpdm_semaphore_post(A0); + return NULL; +} + + static struct { wchar_t * name; mpdm_t (* func)(mpdm_t, mpdm_t); @@ -1330,6 +1377,9 @@ static struct { { L"mutex", F_mutex }, { L"mutex_lock", F_mutex_lock }, { L"mutex_unlock", F_mutex_unlock }, + { L"semaphore", F_semaphore }, + { L"semaphore_wait", F_semaphore_wait }, + { L"semaphore_post", F_semaphore_post }, { NULL, NULL } }; -- 2.11.4.GIT