first commit
This commit is contained in:
49
include/platform/thread/atomic_value.h
Normal file
49
include/platform/thread/atomic_value.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
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__
|
||||
Reference in New Issue
Block a user