summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt7
-rw-r--r--config.h.in2
-rw-r--r--src/mem_pool.c16
3 files changed, 18 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 754b2200a..676119827 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,7 @@ OPTION(ENABLE_GPERF_TOOLS "Enable google perftools [default: OFF]"
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
+INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckLibraryExists)
INCLUDE(FindPkgConfig)
@@ -229,6 +230,12 @@ CHECK_SYMBOL_EXISTS(_SC_NPROCESSORS_ONLN unistd.h HAVE_SC_NPROCESSORS_ONLN)
CHECK_SYMBOL_EXISTS(CLOCK_PROCESS_CPUTIME_ID time.h HAVE_CLOCK_PROCESS_CPUTIME_ID)
CHECK_SYMBOL_EXISTS(CLOCK_VIRTUAL time.h HAVE_CLOCK_VIRTUAL)
+CHECK_C_SOURCE_COMPILES ("#include <sys/types.h>
+ int main (int argc, char **argv) {
+ __asm __volatile(\"pause\");
+ return 0;
+ }" HAVE_ASM_PAUSE)
+
IF(NOT HAVE_COMPATIBLE_QUEUE_H)
INCLUDE_DIRECTORIES(compat)
ENDIF(NOT HAVE_COMPATIBLE_QUEUE_H)
diff --git a/config.h.in b/config.h.in
index 61bbc6068..12593da61 100644
--- a/config.h.in
+++ b/config.h.in
@@ -103,6 +103,8 @@
#cmakedefine WITH_GPERF_TOOLS 1
+#cmakedefine HAVE_ASM_PAUSE 1
+
#define RVERSION "${RSPAMD_VERSION}"
#define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}"
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