diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-08-15 14:53:18 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-08-15 14:53:18 +0000 |
commit | 2f24a0b188d55837e7c11fcbef53153702560699 (patch) | |
tree | 94db942df28cfcb4c37846be58ddc67c84df2dc6 /pjlib/src/pjlib-test/mutex.c | |
parent | dda962837e8e9d4c28c0d5bb7f30ffebc79f4db8 (diff) |
Ticket #595: Broken semaphore implementation on MacOS X (thanks Viktor Krikun for the report)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2217 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pjlib-test/mutex.c')
-rw-r--r-- | pjlib/src/pjlib-test/mutex.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/pjlib/src/pjlib-test/mutex.c b/pjlib/src/pjlib-test/mutex.c index 81565c57..0c507609 100644 --- a/pjlib/src/pjlib-test/mutex.c +++ b/pjlib/src/pjlib-test/mutex.c @@ -148,6 +148,59 @@ static int recursive_mutex_test(pj_pool_t *pool) return PJ_SUCCESS; } +#if PJ_HAS_SEMAPHORE +static int semaphore_test(pj_pool_t *pool) +{ + pj_sem_t *sem; + pj_status_t status; + + PJ_LOG(3,("", "...testing semaphore")); + + status = pj_sem_create(pool, NULL, 0, 1, &sem); + if (status != PJ_SUCCESS) { + app_perror("...error: pj_sem_create()", status); + return -151; + } + + status = pj_sem_post(sem); + if (status != PJ_SUCCESS) { + app_perror("...error: pj_sem_post()", status); + pj_sem_destroy(sem); + return -153; + } + + status = pj_sem_trywait(sem); + if (status != PJ_SUCCESS) { + app_perror("...error: pj_sem_trywait()", status); + pj_sem_destroy(sem); + return -156; + } + + status = pj_sem_post(sem); + if (status != PJ_SUCCESS) { + app_perror("...error: pj_sem_post()", status); + pj_sem_destroy(sem); + return -159; + } + + status = pj_sem_wait(sem); + if (status != PJ_SUCCESS) { + app_perror("...error: pj_sem_wait()", status); + pj_sem_destroy(sem); + return -161; + } + + status = pj_sem_destroy(sem); + if (status != PJ_SUCCESS) { + app_perror("...error: pj_sem_destroy()", status); + return -163; + } + + return 0; +} +#endif /* PJ_HAS_SEMAPHORE */ + + int mutex_test(void) { pj_pool_t *pool; @@ -163,6 +216,12 @@ int mutex_test(void) if (rc != 0) return rc; +#if PJ_HAS_SEMAPHORE + rc = semaphore_test(pool); + if (rc != 0) + return rc; +#endif + pj_pool_release(pool); return 0; |