mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 15:23:02 +01:00
Native Solaris AtomicCounter - required for non-intel build
This commit is contained in:
parent
290533d2ef
commit
26d31f5e2e
@ -205,6 +205,65 @@ private:
|
||||
|
||||
} // namespace Firebird
|
||||
|
||||
#elif defined(SOLARIS)
|
||||
|
||||
#include <atomic.h>
|
||||
|
||||
namespace Firebird {
|
||||
|
||||
// Solaris version - uses Solaris atomic_ops
|
||||
class AtomicCounter
|
||||
{
|
||||
public:
|
||||
typedef uint_t counter_type;
|
||||
|
||||
explicit AtomicCounter(counter_type value = 0) : counter(value) {}
|
||||
~AtomicCounter() {}
|
||||
|
||||
counter_type exchangeAdd(counter_type value)
|
||||
{
|
||||
return atomic_add_int_nv(&counter, value);
|
||||
}
|
||||
|
||||
counter_type operator +=(counter_type value)
|
||||
{
|
||||
return exchangeAdd(value) + value;
|
||||
}
|
||||
|
||||
counter_type operator -=(counter_type value)
|
||||
{
|
||||
return exchangeAdd(-value) - value;
|
||||
}
|
||||
|
||||
counter_type operator ++()
|
||||
{
|
||||
return exchangeAdd(1) + 1;
|
||||
}
|
||||
|
||||
counter_type operator --()
|
||||
{
|
||||
return exchangeAdd(-1) - 1;
|
||||
}
|
||||
|
||||
counter_type value() const { return counter; }
|
||||
|
||||
counter_type setValue(counter_type val)
|
||||
{
|
||||
counter_type old;
|
||||
do
|
||||
{
|
||||
old = counter;
|
||||
} while (!atomic_cas_uint(&counter, old, val));
|
||||
return old;
|
||||
}
|
||||
|
||||
private:
|
||||
counter_type counter;
|
||||
};
|
||||
|
||||
} // namespace Firebird
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#error AtomicCounter: implement appropriate code for your platform!
|
||||
|
Loading…
Reference in New Issue
Block a user