Skip to content
Browse files

Fix build to use atomic.h for Sun Studio compilers

Change-Id: Ifcd6dd59ae9fe7443706c833e740fbfeabf5cd8c
Reviewed-on: http://review.couchbase.org/14082
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
1 parent 5ca5515 commit 89006aa3ebdc562a4152ecf8216eeb104348d86f @trondn trondn committed Mar 19, 2012
Showing with 26 additions and 3 deletions.
  1. +24 −3 bucket_engine.c
  2. +2 −0 configure.ac
View
27 bucket_engine.c
@@ -1,4 +1,5 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@@ -21,16 +22,36 @@
#include "genhash.h"
#include "topkeys.h"
#include "bucket_engine.h"
+#include "bucket_engine_internal.h"
static rel_time_t (*get_current_time)(void);
static EXTENSION_LOGGER_DESCRIPTOR *logger;
+#if defined(HAVE_ATOMIC_H) && defined(__SUNPRO_C)
+#include <atomic.h>
+static inline int ATOMIC_ADD(volatile int *dest, int value) {
+ return atomic_add_int_nv((volatile unsigned int *)dest, value);
+}
+
+static inline int ATOMIC_INCR(volatile int *dest) {
+ return atomic_inc_32_nv((volatile unsigned int *)dest);
+}
+
+static inline int ATOMIC_DECR(volatile int *dest) {
+ return atomic_dec_32_nv((volatile unsigned int *)dest);
+}
+
+static inline int ATOMIC_CAS(volatile bucket_state_t *dest, int prev, int next) {
+ return (prev == atomic_cas_uint((volatile uint_t*)dest, (uint_t)prev,
+ (uint_t)next));
+}
+#else
#define ATOMIC_ADD(i, by) __sync_add_and_fetch(i, by)
#define ATOMIC_INCR(i) ATOMIC_ADD(i, 1)
#define ATOMIC_DECR(i) ATOMIC_ADD(i, -1)
-#define ATOMIC_CAS(ptr, oldval, newval) __sync_bool_compare_and_swap(ptr, oldval, newval)
-
-#include "bucket_engine_internal.h"
+#define ATOMIC_CAS(ptr, oldval, newval) \
+ __sync_bool_compare_and_swap(ptr, oldval, newval)
+#endif
static ENGINE_ERROR_CODE (*upstream_reserve_cookie)(const void *cookie);
static ENGINE_ERROR_CODE (*upstream_release_cookie)(const void *cookie);
View
2 configure.ac
@@ -33,6 +33,8 @@ ac_cv_func_realloc_0_nonnull=yes
COUCHBASE_GENERIC_COMPILER
+AC_CHECK_HEADERS([atomic.h])
+
AC_ARG_WITH([memcached],
[AS_HELP_STRING([--with-memcached],
[Memcached source location])],

0 comments on commit 89006aa

Please sign in to comment.
Something went wrong with that request. Please try again.