summaryrefslogtreecommitdiff
path: root/cpp/include/IceUtil/Shared.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/include/IceUtil/Shared.h')
-rw-r--r--cpp/include/IceUtil/Shared.h75
1 files changed, 6 insertions, 69 deletions
diff --git a/cpp/include/IceUtil/Shared.h b/cpp/include/IceUtil/Shared.h
index 61b466d9895..b830a550854 100644
--- a/cpp/include/IceUtil/Shared.h
+++ b/cpp/include/IceUtil/Shared.h
@@ -18,6 +18,10 @@
#elif (defined(__linux) || defined(__FreeBSD__)) && (defined(__i386) || defined(__x86_64)) && !defined(__ICC)
# define ICE_HAS_ATOMIC_FUNCTIONS
+
+namespace IceUtilInternal
+{
+
// __ICC: The inline assembler causes problems with shared libraries.
//
// Linux only. Unfortunately, asm/atomic.h builds non-SMP safe code
@@ -32,77 +36,10 @@
* on us. We need to use _exactly_ the address the user gave us,
* not some alias that contains the same information.
*/
-struct ice_atomic_t
+struct AtomicCounter
{
volatile int counter;
};
-
-/*
- * ice_atomic_set - set ice_atomic variable
- * @v: pointer of type ice_atomic_t
- * @i: required value
- *
- * Atomically sets the value of @v to @i. Note that the guaranteed
- * useful range of an ice_atomic_t is only 24 bits.
- */
-inline void ice_atomic_set(ice_atomic_t* v, int i)
-{
- v->counter = i;
-}
-
-/*
- * ice_atomic_inc - increment ice_atomic variable
- * @v: pointer of type ice_atomic_t
- *
- * Atomically increments @v by 1. Note that the guaranteed useful
- * range of an ice_atomic_t is only 24 bits.
- *
- * Inlined because this operation is performance critical.
- */
-inline void ice_atomic_inc(ice_atomic_t *v)
-{
- __asm__ __volatile__(
- "lock ; incl %0"
- :"=m" (v->counter)
- :"m" (v->counter));
-}
-
-/**
- * ice_atomic_dec_and_test - decrement and test
- * @v: pointer of type ice_atomic_t
- *
- * Atomically decrements @v by 1 and returns true if the result is 0,
- * or false for all other cases. Note that the guaranteed useful
- * range of an ice_atomic_t is only 24 bits.
- *
- * Inlined because this operation is performance critical.
- */
-inline int ice_atomic_dec_and_test(ice_atomic_t *v)
-{
- unsigned char c;
- __asm__ __volatile__(
- "lock ; decl %0; sete %1"
- :"=m" (v->counter), "=qm" (c)
- :"m" (v->counter) : "memory");
- return c != 0;
-}
-
-/**
- * ice_atomic_exchange_add - same as InterlockedExchangeAdd. This
- * didn't come from atomic.h (the code was derived from similar code
- * in /usr/include/asm/rwsem.h)
- *
- * Inlined because this operation is performance critical.
- */
-inline int ice_atomic_exchange_add(int i, ice_atomic_t* v)
-{
- int tmp = i;
- __asm__ __volatile__(
- "lock ; xadd %0,(%2)"
- :"+r"(tmp), "=m"(v->counter)
- :"r"(v), "m"(v->counter)
- : "memory");
- return tmp + i;
}
#elif defined(_WIN32)
@@ -207,7 +144,7 @@ protected:
#if defined(_WIN32)
LONG _ref;
#elif defined(ICE_HAS_ATOMIC_FUNCTIONS)
- ice_atomic_t _ref;
+ IceUtilInternal::AtomicCounter _ref;
#else
int _ref;
Mutex _mutex;