75 #ifdef NCBI_COUNTER_USE_STD_ATOMIC
92 #if defined(NCBI_COUNTER_USE_ASM)
94 # if !defined(NCBI_COUNTER_ADD)
95 # define NCBI_COUNTER_ADD(value, delta) ncbi::CAtomicCounter::x_Add((value), (delta))
145 {
return m_Counter.Get(); }
149 { m_Counter.Set(new_value); }
153 {
return m_Counter.Add(
delta); }
170 #ifdef NCBI_COUNTER_RESERVED_VALUE
173 while (
value == NCBI_COUNTER_RESERVED_VALUE) {
190 #if defined(NCBI_COUNTER_USE_ASM)
197 TValue* nv_value_p =
const_cast<TValue*
>(value_p);
201 TValue old_value = *value_p;
205 asm volatile(
"cas [%3], %2, %1" :
"=m" (*nv_value_p),
"+r" (
result)
206 :
"r" (old_value),
"r" (nv_value_p),
"m" (*nv_value_p));
207 if (
result == old_value) {
213 # elif defined(__sparc)
214 result = NCBI_COUNTER_RESERVED_VALUE;
217 asm volatile(
"swap [%2], %1" :
"=m" (*nv_value_p),
"+r" (
result)
218 :
"r" (nv_value_p),
"m" (*nv_value_p));
219 if (
result != NCBI_COUNTER_RESERVED_VALUE) {
226 # elif defined(__i386) || defined(__x86_64)
228 # ifdef NCBI_COUNTER_64_BIT
229 asm volatile(
"lock; xaddq %1, %0" :
"=m" (*nv_value_p),
"=r" (
result)
232 asm volatile(
"lock; xaddl %1, %0" :
"=m" (*nv_value_p),
"=r" (
result)
233 :
"1" (
delta),
"m" (*nv_value_p));
236 # elif defined(__aarch64__)
237 # ifdef __ARM_FEATURE_ATOMICS
238 asm volatile(
"ldaddal %2, %0, %1" :
"=&r" (
result),
"+Q" (*nv_value_p)
243 register int undone
asm(
"w9") = 1;
245 asm volatile(
"ldxr %1, %2\n\tadd %1, %1, %3\n\tstlxr w9, %1, %2"
246 :
"=&r" (undone),
"=&r" (
result),
"+Q" (*nv_value_p)
254 # error "Unsupported processor type for assembly implementation!"
260 #if !defined(NCBI_COUNTER_NEED_MUTEX) && (!defined(NCBI_COUNTER_USE_EXTERN_ASM) || defined(NCBI_COUNTER_IMPLEMENTATION))
261 # ifndef NCBI_COUNTER_USE_EXTERN_ASM
266 TData* nv_value_p =
const_cast<TData*
>(&m_Value);
CAtomicCounter_WithAutoInit –.
Include a standard set of the NCBI C++ Toolkit most basic headers.
TValue Add(int delta) noexcept
Atomically add value (=delta), and return new counter value.
TValue Get(void) const noexcept
Get atomic counter value.
CAtomicCounter_WithAutoInit(TValue initial_value=0)
TNCBIAtomicValue TValue
Alias TValue for TNCBIAtomicValue.
typedef NCBI_ATOMIC_TYPE(TValue) TData
Define NCBI_COUNTER_ADD if one has not been defined.
void Set(TValue new_value) noexcept
Set atomic counter value.
TValue Add(int delta) const noexcept
Atomically add value (=delta), and return new counter value.
void Set(TValue new_value) const noexcept
Set atomic counter value.
CAtomicCounter m_Counter
Mutable atomic counter value.
TValue Get(void) const noexcept
Get atomic counter value.
volatile TData m_Value
Internal counter value.
CAtomicCounter::TValue TValue
Alias TValue simplifies syntax.
int64_t Int8
8-byte (64-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define NCBI_SCHED_SPIN_INIT()
#define NCBI_SCHED_SPIN_YIELD()
size_t TNCBIAtomicValue
Define platform specific atomic-operations macros/values.
#define NCBI_COUNTER_ADD(p, d)
#define NCBI_XNCBI_EXPORT
const GenericPointer< typename T::ValueType > T2 value
(Highly!) platform-specific configuration for low-level atomic operations (reference-count manipulati...
Int4 delta(size_t dimension_, const Int4 *score_)