+namespace simgear
+{
+// Typesafe wrapper around SGSwappable
+template <typename T>
+class Swappable : private SGAtomic
+{
+public:
+ Swappable(const T& value) : SGAtomic(static_cast<unsigned>(value))
+ {
+ }
+ T operator() () const
+ {
+ return static_cast<T>(SGAtomic::operator unsigned ());
+ }
+ Swappable& operator=(const Swappable& rhs)
+ {
+ for (unsigned oldval = unsigned(*this);
+ !compareAndExchange(oldval, unsigned(rhs));
+ oldval = unsigned(*this))
+ ;
+ return *this;
+ }
+ bool compareAndSwap(const T& oldVal, const T& newVal)
+ {
+ return SGAtomic::compareAndExchange(static_cast<unsigned>(oldVal),
+ static_cast<unsigned>(newVal));
+ }
+};
+}