|
static FORCE_INLINE int | preIncrement (volatile int *variable) |
| Increment variable, return value after increment. More...
|
|
static FORCE_INLINE int | postIncrement (volatile int *variable) |
| Increment variable, return value before increment. More...
|
|
static FORCE_INLINE int | increment (volatile int *variable, int incrementValue) |
| Increment variable by incrementValue, return value before increment. More...
|
|
static FORCE_INLINE int | preDecrement (volatile int *variable) |
| Decrement variable, return value after increment. More...
|
|
static FORCE_INLINE int | postDecrement (volatile int *variable) |
| Decrement variable, return value before decrement. More...
|
|
static FORCE_INLINE int | decrement (volatile int *variable, int decrementValue) |
| Decrement variable by decrementValue, return value before decrement. More...
|
|
static FORCE_INLINE int | set (volatile int *variable, int newValue) |
| Set variable to newValue, return value of variable before set. More...
|
|
static FORCE_INLINE int | compareAndSwap (volatile int *variable, int compareValue, int swapValue) |
| Compare variable with compareValue and if the values are equal, sets *variable equal to swapValue. More...
|
|
Methods for atomic operations.
The MAtomic class implements several cross-platform atomic operations which are useful when writing a multithreaded application. Atomic operations are those that appear to happen as a single operation when viewed from other threads.
As a usage example, during reference counting in an SMP environment, it is important to ensure that decrementing and testing the counter against zero happens atomically. If coded this way:
then another thread could modify the value of counter between the decrement and the if test. The above code would therefore get the wrong value. This class provides a routine to perform the decrement and return the previous value atomically, so the above snippet could be written as: