diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-06-17 20:31:42 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-06-17 20:31:42 +0400 |
commit | 2a21701f6c0f80d2a56639e7e2c156ed7179f0dd (patch) | |
tree | 1152585de8f27ad05fcd7494bbfddf940d1f3e2a /src/mem_pool.c | |
parent | bca226772e9747a4587866a50122d4a8f7973b26 (diff) | |
download | rspamd-2a21701f6c0f80d2a56639e7e2c156ed7179f0dd.tar.gz rspamd-2a21701f6c0f80d2a56639e7e2c156ed7179f0dd.zip |
* Improve locking by using asm 'pause' command
* Try to fix read locking in rwlock
Diffstat (limited to 'src/mem_pool.c')
-rw-r--r-- | src/mem_pool.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/mem_pool.c b/src/mem_pool.c index e034ea652..e8be6a95c 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -343,17 +343,17 @@ __mutex_spin (memory_pool_mutex_t *mutex) /* Spin again */ g_atomic_int_set (&mutex->spin, MUTEX_SPIN_COUNT); } -#ifdef HAVE_NANOSLEEP +#ifdef HAVE_ASM_PAUSE + __asm __volatile("pause"); +#elif defined(HAVE_SCHED_YIELD) + (void)sched_yield (); +#elif defined(HAVE_NANOSLEEP) struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = MUTEX_SLEEP_TIME; /* Spin */ while (nanosleep (&ts, &ts) == -1 && errno == EINTR); -#endif -#ifdef HAVE_SCHED_YIELD - (void)sched_yield (); -#endif -#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_SCHED_YIELD) +#else # error No methods to spin are defined #endif return 1; @@ -552,7 +552,9 @@ memory_pool_wlock_rwlock (memory_pool_rwlock_t *lock) void memory_pool_runlock_rwlock (memory_pool_rwlock_t *lock) { - memory_pool_unlock_mutex (lock->__r_lock); + if (g_atomic_int_get (&lock->__r_lock->lock)) { + (void)g_atomic_int_dec_and_test (&lock->__r_lock->lock); + } } void |