From b1677882708e931c32f9a501ebe9d737b02d62c1 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 24 Jun 2012 10:37:18 +0200 Subject: [PATCH] cache: use optimized futexes on i386 and amd64 arch only on Linux Optimized futexes are only available on i386 and amd64 on Linux since they use inline assembly. It is difficult to come with a generic way to tell which arch we are using from the Makefile and therefore, additional checks are put in the preprocessor before using those futexes. --- Makefile | 1 + shctx.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index eba3e9c..1548f0f 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ all: realall # Shared cache feature ifneq ($(USE_SHARED_CACHE),) CFLAGS += -DUSE_SHARED_CACHE -DUSE_SYSCALL_FUTEX +LDFLAGS += -Wl,--as-needed -lpthread OBJS += shctx.o ebtree/libebtree.a ALL += ebtree diff --git a/shctx.c b/shctx.c index 081c08d..611dcf7 100644 --- a/shctx.c +++ b/shctx.c @@ -7,7 +7,7 @@ * */ #include -#ifdef USE_SYSCALL_FUTEX +#if defined USE_SYSCALL_FUTEX && (defined __i386__ || defined __x86_64__) && defined __linux__ #include #include #include @@ -30,7 +30,7 @@ struct shared_session { struct shared_context { -#ifdef USE_SYSCALL_FUTEX +#if defined USE_SYSCALL_FUTEX && (defined __i386__ || defined __x86_64__) && defined __linux__ unsigned int waiters; #else /* USE_SYSCALL_FUTEX */ pthread_mutex_t mutex; @@ -47,7 +47,7 @@ static void (*shared_session_new_cbk)(unsigned char *session, unsigned int sessi /* Lock functions */ -#ifdef USE_SYSCALL_FUTEX +#if defined USE_SYSCALL_FUTEX && (defined __i386__ || defined __x86_64__) && defined __linux__ static inline unsigned int xchg(unsigned int *ptr, unsigned int x) { __asm volatile("lock xchgl %0,%1" @@ -344,7 +344,7 @@ int shared_context_init(SSL_CTX *ctx, int size) if (!shctx) { int i; -#ifndef USE_SYSCALL_FUTEX +#if !(defined USE_SYSCALL_FUTEX && (defined __i386__ || defined __x86_64__) && defined __linux__) pthread_mutexattr_t attr; #endif /* USE_SYSCALL_FUTEX */ struct shared_session *prev,*cur; @@ -354,7 +354,7 @@ int shared_context_init(SSL_CTX *ctx, int size) if (!shctx || shctx == MAP_FAILED) return -1; -#ifdef USE_SYSCALL_FUTEX +#if defined USE_SYSCALL_FUTEX && (defined __i386__ || defined __x86_64__) && defined __linux__ shctx->waiters = 0; #else pthread_mutexattr_init(&attr);