diff options
author | Andrew Bartlett <abartlet@samba.org> | 2010-11-29 11:24:08 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-12-01 17:00:47 +1100 |
commit | c5bea98ddb2f7967df572160f639da3cba381a87 (patch) | |
tree | e5ca502195932ea7674f03a732fc26dd5427553d /source4/heimdal/base/baselocl.h | |
parent | 9c84f987acb5ffc97a612839e13e8b8042e6120e (diff) | |
download | samba-c5bea98ddb2f7967df572160f639da3cba381a87.tar.gz samba-c5bea98ddb2f7967df572160f639da3cba381a87.tar.bz2 samba-c5bea98ddb2f7967df572160f639da3cba381a87.zip |
s4:heimdal: import lorikeet-heimdal-201012010201 (commit 81fe27bcc0148d410ca4617f8759b9df1a5e935c)
Diffstat (limited to 'source4/heimdal/base/baselocl.h')
-rw-r--r-- | source4/heimdal/base/baselocl.h | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/source4/heimdal/base/baselocl.h b/source4/heimdal/base/baselocl.h index 06806d2762..5f157264c1 100644 --- a/source4/heimdal/base/baselocl.h +++ b/source4/heimdal/base/baselocl.h @@ -33,13 +33,17 @@ * SUCH DAMAGE. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <limits.h> -#include <unistd.h> -#include "config.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif #include "heimqueue.h" #include "heim_threads.h" @@ -50,14 +54,8 @@ #include <dispatch/dispatch.h> #endif -#if HEIM_BASE_NON_ATOMIC -/* non-atomic varients */ -#define heim_base_atomic_inc(x) ++(*(x)) -#define heim_base_atomic_dec(x) --(*(x)) -#define heim_base_atomic_type unsigned int -#define heim_base_atomic_max UINT_MAX +#if defined(__GNUC__) && defined(HAVE___SYNC_ADD_AND_FETCH) -#elif defined(__GNUC__) #define heim_base_atomic_inc(x) __sync_add_and_fetch((x), 1) #define heim_base_atomic_dec(x) __sync_sub_and_fetch((x), 1) #define heim_base_atomic_type unsigned int @@ -65,12 +63,44 @@ #define heim_base_exchange_pointer(t,v) __sync_lock_test_and_set((t), (v)) -#elif 0 /* windows */ +#elif defined(_WIN32) + +#define heim_base_atomic_inc(x) InterlockedIncrement(x) +#define heim_base_atomic_dec(x) InterlockedDecrement(x) +#define heim_base_atomic_type LONG +#define heim_base_atomic_max MAXLONG #define heim_base_exchange_pointer(t,v) InterlockedExchangePointer((t),(v)) #else -#error "provide atomic integer operations for your compiler" + +#define HEIM_BASE_NEED_ATOMIC_MUTEX 1 +extern HEIMDAL_MUTEX _heim_base_mutex; + +#define heim_base_atomic_type unsigned int + +static inline heim_base_atomic_type +heim_base_atomic_inc(heim_base_atomic_type *x) +{ + heim_base_atomic_type t; + HEIMDAL_MUTEX_lock(&_heim_base_mutex); + t = ++(*x); + HEIMDAL_MUTEX_unlock(&_heim_base_mutex); + return t; +} + +static inline heim_base_atomic_type +heim_base_atomic_dec(heim_base_atomic_type *x) +{ + heim_base_atomic_type t; + HEIMDAL_MUTEX_lock(&_heim_base_mutex); + t = --(*x); + HEIMDAL_MUTEX_unlock(&_heim_base_mutex); + return t; +} + +#define heim_base_atomic_max UINT_MAX + #endif /* tagged strings/object/XXX */ |