summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/Shared.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2008-03-18 13:12:44 +1000
committerMichi Henning <michi@zeroc.com>2008-03-18 13:12:44 +1000
commit966e8d1c824fc25c3b1f6e8a5e74de97c8d7d9b4 (patch)
tree100c6841990db43100c7d6c5ac1328d2fa919d3b /cpp/src/IceUtil/Shared.cpp
parentfixes for a number of demo README files (diff)
downloadice-966e8d1c824fc25c3b1f6e8a5e74de97c8d7d9b4.tar.bz2
ice-966e8d1c824fc25c3b1f6e8a5e74de97c8d7d9b4.tar.xz
ice-966e8d1c824fc25c3b1f6e8a5e74de97c8d7d9b4.zip
Bug 2429--previous fix didn't compile with -O2. Also fixed minor style issues.
Diffstat (limited to 'cpp/src/IceUtil/Shared.cpp')
-rw-r--r--cpp/src/IceUtil/Shared.cpp88
1 files changed, 7 insertions, 81 deletions
diff --git a/cpp/src/IceUtil/Shared.cpp b/cpp/src/IceUtil/Shared.cpp
index 5c30967bc35..f18b9385798 100644
--- a/cpp/src/IceUtil/Shared.cpp
+++ b/cpp/src/IceUtil/Shared.cpp
@@ -9,80 +9,6 @@
#include <IceUtil/Shared.h>
-namespace IceUtilInternal
-{
-#ifdef ICE_HAS_ATOMIC_FUNCTIONS
-
-/*
- * atomicSet - set ice_atomic variable
- * @v: pointer of type AtomicCounter
- * @i: required value
- *
- * Atomically sets the value of @v to @i. Note that the guaranteed
- * useful range of an AtomicCounter is only 24 bits.
- */
-inline void atomicSet(AtomicCounter* v, int i)
-{
- v->counter = i;
-}
-
-/*
- * atomicInc - increment ice_atomic variable
- * @v: pointer of type AtomicCounter
- *
- * Atomically increments @v by 1. Note that the guaranteed useful
- * range of an AtomicCounter is only 24 bits.
- *
- * Inlined because this operation is performance critical.
- */
-inline void atomicInc(AtomicCounter *v)
-{
- __asm__ __volatile__(
- "lock ; incl %0"
- :"=m" (v->counter)
- :"m" (v->counter));
-}
-
-/**
- * atomicDecAndTest - decrement and test
- * @v: pointer of type AtomicCounter
- *
- * 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 AtomicCounter is only 24 bits.
- *
- * Inlined because this operation is performance critical.
- */
-inline int atomicDecAndTest(AtomicCounter *v)
-{
- unsigned char c;
- __asm__ __volatile__(
- "lock ; decl %0; sete %1"
- :"=m" (v->counter), "=qm" (c)
- :"m" (v->counter) : "memory");
- return c != 0;
-}
-
-/**
- * atomicExchangeAdd - 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 atomicExchangeAdd(int i, AtomicCounter* v)
-{
- int tmp = i;
- __asm__ __volatile__(
- "lock ; xadd %0,(%2)"
- :"+r"(tmp), "=m"(v->counter)
- :"r"(v), "m"(v->counter)
- : "memory");
- return tmp + i;
-}
-#endif
-}
-
using namespace IceUtil;
using namespace IceUtilInternal;
@@ -105,7 +31,7 @@ IceUtil::Shared::Shared() :
_noDelete(false)
{
#ifdef ICE_HAS_ATOMIC_FUNCTIONS
- atomicSet(&_ref, 0);
+ _ref.atomicSet(0);
#endif
}
@@ -116,7 +42,7 @@ IceUtil::Shared::Shared(const Shared&) :
_noDelete(false)
{
#ifdef ICE_HAS_ATOMIC_FUNCTIONS
- atomicSet(&_ref, 0);
+ _ref.atomicSet(0);
#endif
}
@@ -127,8 +53,8 @@ IceUtil::Shared::__incRef()
assert(InterlockedExchangeAdd(&_ref, 0) >= 0);
InterlockedIncrement(&_ref);
#elif defined(ICE_HAS_ATOMIC_FUNCTIONS)
- assert(atomicExchangeAdd(0, &_ref) >= 0);
- atomicInc(&_ref);
+ assert(_ref.atomicExchangeAdd(&_ref) >= 0);
+ _ref.atomicInc();
#else
_mutex.lock();
assert(_ref >= 0);
@@ -148,8 +74,8 @@ IceUtil::Shared::__decRef()
delete this;
}
#elif defined(ICE_HAS_ATOMIC_FUNCTIONS)
- assert(atomicExchangeAdd(0, &_ref) > 0);
- if(atomicDecAndTest(&_ref) && !_noDelete)
+ assert(_ref.atomicExchangeAdd(0) > 0);
+ if(_ref.atomicDecAndTest() && !_noDelete)
{
_noDelete = true;
delete this;
@@ -177,7 +103,7 @@ IceUtil::Shared::__getRef() const
#if defined(_WIN32)
return InterlockedExchangeAdd(const_cast<LONG*>(&_ref), 0);
#elif defined(ICE_HAS_ATOMIC_FUNCTIONS)
- return atomicExchangeAdd(0, const_cast<AtomicCounter*>(&_ref));
+ return const_cast<IceUtilInternal::AtomicCounter*>(&_ref)->atomicExchangeAdd(0);
#else
_mutex.lock();
int ref = _ref;