From 0be368c425f5dc81a29a0c55799bfd66c041b966 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 11 May 2006 10:33:19 +0000 Subject: Removed rwmutex implementation to os_rwmutex.c git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@434 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/os_core_win32.c | 128 +------------------------------------------ 1 file changed, 2 insertions(+), 126 deletions(-) (limited to 'pjlib/src/pj') diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c index 70cbe136..fbc77dba 100644 --- a/pjlib/src/pj/os_core_win32.c +++ b/pjlib/src/pj/os_core_win32.c @@ -868,134 +868,10 @@ PJ_DEF(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex) #endif /////////////////////////////////////////////////////////////////////////////// - -struct pj_rwmutex_t -{ - pj_mutex_t *read_lock; - /* write_lock must use semaphore, because write_lock may be released - * by thread other than the thread that acquire the write_lock in the - * first place. - */ - pj_sem_t *write_lock; - pj_int32_t reader_count; -}; - -/* - * Create reader/writer mutex. - * - */ -PJ_DEF(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name, - pj_rwmutex_t **p_mutex) -{ - pj_status_t status; - pj_rwmutex_t *rwmutex; - - PJ_ASSERT_RETURN(pool && p_mutex, PJ_EINVAL); - - *p_mutex = NULL; - rwmutex = pj_pool_alloc(pool, sizeof(struct pj_rwmutex_t)); - - status = pj_mutex_create_simple(pool, name, &rwmutex ->read_lock); - if (status != PJ_SUCCESS) - return status; - - status = pj_sem_create(pool, name, 1, 1, &rwmutex->write_lock); - if (status != PJ_SUCCESS) { - pj_mutex_destroy(rwmutex->read_lock); - return status; - } - - rwmutex->reader_count = 0; - *p_mutex = rwmutex; - return PJ_SUCCESS; -} - -/* - * Lock the mutex for reading. - * - */ -PJ_DEF(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex) -{ - pj_status_t status; - - PJ_ASSERT_RETURN(mutex, PJ_EINVAL); - - status = pj_mutex_lock(mutex->read_lock); - if (status != PJ_SUCCESS) { - pj_assert(!"This pretty much is unexpected"); - return status; - } - - mutex->reader_count++; - - pj_assert(mutex->reader_count < 0x7FFFFFF0L); - - if (mutex->reader_count == 1) - pj_sem_wait(mutex->write_lock); - - status = pj_mutex_unlock(mutex->read_lock); - return status; -} - /* - * Lock the mutex for writing. - * + * Win32 lacks Read/Write mutex, so include the emulation. */ -PJ_DEF(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex) -{ - PJ_ASSERT_RETURN(mutex, PJ_EINVAL); - return pj_sem_wait(mutex->write_lock); -} - -/* - * Release read lock. - * - */ -PJ_DEF(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex) -{ - pj_status_t status; - - PJ_ASSERT_RETURN(mutex, PJ_EINVAL); - - status = pj_mutex_lock(mutex->read_lock); - if (status != PJ_SUCCESS) { - pj_assert(!"This pretty much is unexpected"); - return status; - } - - pj_assert(mutex->reader_count >= 1); - - --mutex->reader_count; - if (mutex->reader_count == 0) - pj_sem_post(mutex->write_lock); - - status = pj_mutex_unlock(mutex->read_lock); - return status; -} - -/* - * Release write lock. - * - */ -PJ_DEF(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex) -{ - PJ_ASSERT_RETURN(mutex, PJ_EINVAL); - pj_assert(mutex->reader_count <= 1); - return pj_sem_post(mutex->write_lock); -} - - -/* - * Destroy reader/writer mutex. - * - */ -PJ_DEF(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex) -{ - PJ_ASSERT_RETURN(mutex, PJ_EINVAL); - pj_mutex_destroy(mutex->read_lock); - pj_sem_destroy(mutex->write_lock); - return PJ_SUCCESS; -} +#include "os_rwmutex.c" /////////////////////////////////////////////////////////////////////////////// /* -- cgit v1.2.3