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
00029 template<typename T>
00030 class AtomicPtr {
00031 public:
00032 inline AtomicPtr()
00033 { g_atomic_pointer_set(static_cast<volatile gpointer*>(&_val), NULL); }
00034
00035 inline AtomicPtr(const AtomicPtr& copy)
00036 { g_atomic_pointer_set(static_cast<volatile gpointer*>(&_val),
00037 static_cast<gpointer>(copy.get())); }
00038
00039 inline T* get() const
00040 { return static_cast<T*>(g_atomic_pointer_get(static_cast<volatile gpointer*>(&_val))); }
00041
00042 inline void operator=(T* val)
00043 { g_atomic_pointer_set(&_val, static_cast<gpointer>(val)); }
00044
00046 inline bool compare_and_exchange(gpointer oldval, gpointer newval)
00047 { return g_atomic_pointer_compare_and_exchange(&_val, oldval, newval); }
00048
00049 private:
00050 mutable volatile gpointer _val;
00051 };
00052
00053
00054 }
00055
00056 #endif // RAUL_ATOMIC_PTR_HPP