50 lines
1.0 KiB
C++
50 lines
1.0 KiB
C++
/* -----------------------------------------------------------------------------
|
|
GSFramework
|
|
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
#ifndef __ATOMIC_VALUE__
|
|
#define __ATOMIC_VALUE__
|
|
|
|
|
|
namespace GS {
|
|
namespace Threading {
|
|
|
|
/*!
|
|
@short 32bit atomic value.
|
|
@author Emmanuel Julien (ejulien@owloh.com)
|
|
*/
|
|
class Atomic32
|
|
{
|
|
void *v;
|
|
|
|
public:
|
|
|
|
/// Perform atomic increment, return the new value.
|
|
int Inc();
|
|
/// Perform atomic decrement, return the new value.
|
|
int Dec();
|
|
|
|
/// Return the current value.
|
|
int Get() const;
|
|
/// Set new value, return the initial value.
|
|
int Set(int);
|
|
|
|
/*!
|
|
@short Perform an atomic compare and swap operation.
|
|
Compare the current value with the comparand, if they match set the
|
|
new value. Return the initial value.
|
|
*/
|
|
int Cas(int comparand, int value);
|
|
|
|
explicit Atomic32(int value = 0);
|
|
~Atomic32();
|
|
};
|
|
|
|
} // Threading
|
|
} // GS
|
|
|
|
|
|
#endif // __ATOMIC_VALUE__
|