mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-05-31 02:43:32 +00:00
blah
This commit is contained in:
parent
ac3758df70
commit
e3dd169d63
@ -431,6 +431,7 @@ struct ks_rwl {
|
|||||||
SRWLOCK rwlock;
|
SRWLOCK rwlock;
|
||||||
ks_hash_t *read_lock_list;
|
ks_hash_t *read_lock_list;
|
||||||
ks_mutex_t *read_lock_mutex;
|
ks_mutex_t *read_lock_mutex;
|
||||||
|
ks_mutex_t *write_lock_mutex;
|
||||||
#else
|
#else
|
||||||
pthread_rwlock_t rwlock;
|
pthread_rwlock_t rwlock;
|
||||||
#endif
|
#endif
|
||||||
@ -484,6 +485,10 @@ KS_DECLARE(ks_status_t) ks_rwl_create(ks_rwl_t **rwlock, ks_pool_t *pool)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ks_mutex_create(&check->write_lock_mutex, KS_MUTEX_FLAG_DEFAULT, pool) != KS_STATUS_SUCCESS) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
InitializeSRWLock(&check->rwlock);
|
InitializeSRWLock(&check->rwlock);
|
||||||
#else
|
#else
|
||||||
if ((pthread_rwlock_init(&check->rwlock, NULL))) {
|
if ((pthread_rwlock_init(&check->rwlock, NULL))) {
|
||||||
@ -502,6 +507,7 @@ KS_DECLARE(ks_status_t) ks_rwl_read_lock(ks_rwl_t *rwlock)
|
|||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
|
ks_mutex_lock(rwlock->write_lock_mutex);
|
||||||
ks_mutex_lock(rwlock->read_lock_mutex);
|
ks_mutex_lock(rwlock->read_lock_mutex);
|
||||||
|
|
||||||
int count = (int)(intptr_t)ks_hash_remove(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id());
|
int count = (int)(intptr_t)ks_hash_remove(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id());
|
||||||
@ -509,6 +515,7 @@ KS_DECLARE(ks_status_t) ks_rwl_read_lock(ks_rwl_t *rwlock)
|
|||||||
if (count) {
|
if (count) {
|
||||||
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)++count);
|
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)++count);
|
||||||
ks_mutex_unlock(rwlock->read_lock_mutex);
|
ks_mutex_unlock(rwlock->read_lock_mutex);
|
||||||
|
ks_mutex_unlock(rwlock->write_lock_mutex);
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,6 +527,7 @@ KS_DECLARE(ks_status_t) ks_rwl_read_lock(ks_rwl_t *rwlock)
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)(int)1);
|
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)(int)1);
|
||||||
ks_mutex_unlock(rwlock->read_lock_mutex);
|
ks_mutex_unlock(rwlock->read_lock_mutex);
|
||||||
|
ks_mutex_unlock(rwlock->write_lock_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
@ -536,6 +544,7 @@ KS_DECLARE(ks_status_t) ks_rwl_write_lock(ks_rwl_t *rwlock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
ks_mutex_lock(rwlock->write_lock_mutex);
|
||||||
AcquireSRWLockExclusive(&rwlock->rwlock);
|
AcquireSRWLockExclusive(&rwlock->rwlock);
|
||||||
#else
|
#else
|
||||||
pthread_rwlock_wrlock(&rwlock->rwlock);
|
pthread_rwlock_wrlock(&rwlock->rwlock);
|
||||||
@ -548,6 +557,10 @@ KS_DECLARE(ks_status_t) ks_rwl_write_lock(ks_rwl_t *rwlock)
|
|||||||
KS_DECLARE(ks_status_t) ks_rwl_try_read_lock(ks_rwl_t *rwlock)
|
KS_DECLARE(ks_status_t) ks_rwl_try_read_lock(ks_rwl_t *rwlock)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
if (ks_mutex_trylock(rwlock->write_lock_mutex) != KS_STATUS_SUCCESS) {
|
||||||
|
return KS_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
ks_mutex_lock(rwlock->read_lock_mutex);
|
ks_mutex_lock(rwlock->read_lock_mutex);
|
||||||
|
|
||||||
int count = (int)(intptr_t)ks_hash_remove(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id());
|
int count = (int)(intptr_t)ks_hash_remove(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id());
|
||||||
@ -555,11 +568,13 @@ KS_DECLARE(ks_status_t) ks_rwl_try_read_lock(ks_rwl_t *rwlock)
|
|||||||
if (count) {
|
if (count) {
|
||||||
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)++count);
|
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)++count);
|
||||||
ks_mutex_unlock(rwlock->read_lock_mutex);
|
ks_mutex_unlock(rwlock->read_lock_mutex);
|
||||||
|
ks_mutex_unlock(rwlock->write_lock_mutex);
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TryAcquireSRWLockShared(&rwlock->rwlock)) {
|
if (!TryAcquireSRWLockShared(&rwlock->rwlock)) {
|
||||||
ks_mutex_unlock(rwlock->read_lock_mutex);
|
ks_mutex_unlock(rwlock->read_lock_mutex);
|
||||||
|
ks_mutex_unlock(rwlock->write_lock_mutex);
|
||||||
return KS_STATUS_FAIL;
|
return KS_STATUS_FAIL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -571,6 +586,7 @@ KS_DECLARE(ks_status_t) ks_rwl_try_read_lock(ks_rwl_t *rwlock)
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)(int)1);
|
ks_hash_insert(rwlock->read_lock_list, (void *)(intptr_t)ks_thread_self_id(), (void *)(intptr_t)(int)1);
|
||||||
ks_mutex_unlock(rwlock->read_lock_mutex);
|
ks_mutex_unlock(rwlock->read_lock_mutex);
|
||||||
|
ks_mutex_unlock(rwlock->write_lock_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return KS_STATUS_SUCCESS;
|
return KS_STATUS_SUCCESS;
|
||||||
@ -635,6 +651,7 @@ KS_DECLARE(ks_status_t) ks_rwl_write_unlock(ks_rwl_t *rwlock)
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
ReleaseSRWLockExclusive(&rwlock->rwlock);
|
ReleaseSRWLockExclusive(&rwlock->rwlock);
|
||||||
|
ks_mutex_unlock(rwlock->write_lock_mutex);
|
||||||
#else
|
#else
|
||||||
pthread_rwlock_unlock(&rwlock->rwlock);
|
pthread_rwlock_unlock(&rwlock->rwlock);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user