AVPKit
com::avpkit::ferry::AtomicInteger Class Reference

Internal only. More...

#include <AtomicInteger.h>

Public Member Functions

 AtomicInteger (int32_t)
 
int32_t get ()
 
void set (int32_t)
 
int32_t getAndSet (int32_t)
 
int32_t getAndIncrement ()
 
int32_t getAndDecrement ()
 
int32_t getAndAdd (int32_t)
 
int32_t incrementAndGet ()
 
int32_t decrementAndGet ()
 
int32_t addAndGet (int32_t)
 
bool compareAndSet (int32_t expected, int32_t update)
 Compare the current value to expected, and if they are equal, set the current value to update. More...
 
bool isAtomic ()
 

Friends

class JNIHelper
 

Detailed Description

Internal only.

Atomic Integer represents Integers than can be updated atomically from native code.

This object is NOT meant to be called from Java (in fact, that'd be stupid since you'd just be calling from native code back into Java). It's here so that native code inside a JVM can have access to portable thread-safe objects.


And that said, this method is really only Atomic if running inside a Java JVM (or other virtual machine that can provide the functionality). If running in a standalone C++ program there is no current guarantee of Atomicity.

The object just forwards to the Java object: java.util.concurrent.atomic.AtomicInteger

Definition at line 45 of file AtomicInteger.h.

Member Function Documentation

◆ compareAndSet()

bool com::avpkit::ferry::AtomicInteger::compareAndSet ( int32_t  expected,
int32_t  update 
)

Compare the current value to expected, and if they are equal, set the current value to update.

Parameters
expectedthe value expected
updatethe value to update to
Returns
true if equal

Definition at line 275 of file AtomicInteger.cpp.

276  {
277  JNIEnv *env=JNIHelper::sGetEnv();
278  bool retval = false;
279 
280  if (mAtomicValue && env)
281  retval = env->CallBooleanMethod(mAtomicValue,
282  mCompareAndSetMethod, expected, update);
283  else {
284  retval = (mNonAtomicValue == expected);
285  if (retval)
286  {
287  mNonAtomicValue = update;
288  }
289  }
290  return retval;
291  }

◆ isAtomic()

bool com::avpkit::ferry::AtomicInteger::isAtomic ( )
Returns
true if we're actually able to guarantee atomicity; false if we can't.

Definition at line 294 of file AtomicInteger.cpp.

295  {
296  return init() && mAtomicValue != 0;
297  }

The documentation for this class was generated from the following files: