00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_ATOMIC_PTR_HPP
00019 #define RAUL_ATOMIC_PTR_HPP
00020
00021 #include <glib.h>
00022
00023 namespace Raul {
00024
00025
00026 template<typename T>
00027 class AtomicPtr {
00028 public:
00029 inline AtomicPtr()
00030 { g_atomic_pointer_set(static_cast<volatile gpointer*>(&_val), NULL); }
00031
00032 inline AtomicPtr(const AtomicPtr& copy)
00033 { g_atomic_pointer_set(static_cast<volatile gpointer*>(&_val),
00034 static_cast<gpointer>(copy.get())); }
00035
00036 inline T* get() const
00037 { return static_cast<T*>(g_atomic_pointer_get(static_cast<volatile gpointer*>(&_val))); }
00038
00039 inline void operator=(T* val)
00040 { g_atomic_pointer_set(&_val, static_cast<gpointer>(val)); }
00041
00043 inline bool compare_and_exchange(gpointer oldval, gpointer newval)
00044 { return g_atomic_pointer_compare_and_exchange(&_val, oldval, newval); }
00045
00046 private:
00047 mutable volatile gpointer _val;
00048 };
00049
00050
00051 }
00052
00053 #endif // RAUL_ATOMIC_PTR_HPP