diff options
author | methodus <methodus@web.de> | 2012-11-08 19:29:02 +0100 |
---|---|---|
committer | methodus <methodus@web.de> | 2012-11-08 19:29:02 +0100 |
commit | 5510375bdfdca7b73ac6c51920702d38b79ffcca (patch) | |
tree | 44231a410b3e1b0cfb20fd8310bf0fdbd53baf7c /include | |
parent | dfbbc0a3c933a4a773c9e57795e25061bc38770e (diff) | |
download | vdr-plugin-upnp-5510375bdfdca7b73ac6c51920702d38b79ffcca.tar.gz vdr-plugin-upnp-5510375bdfdca7b73ac6c51920702d38b79ffcca.tar.bz2 |
Added atomic integer class.
Diffstat (limited to 'include')
-rw-r--r-- | include/tools/atomic.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/include/tools/atomic.h b/include/tools/atomic.h new file mode 100644 index 0000000..4e619ee --- /dev/null +++ b/include/tools/atomic.h @@ -0,0 +1,78 @@ +/* + * atomic.h + * + * Created on: 06.11.2012 + * Author: savop + */ + +#ifndef ATOMIC_H_ +#define ATOMIC_H_ + +#include <vdr/thread.h> + +namespace upnp { + +namespace tools { + +namespace atomic { + +class AtomicInteger { +private: + uint32_t value; + cMutex mutex; + +public: + AtomicInteger() + : value(0) + {} + + inline void increment() { + mutex.Lock(); + ++value; + mutex.Unlock(); + } + + inline void decrement() { + mutex.Lock(); + --value; + mutex.Unlock(); + } + + operator unsigned int() const { + return Get(); + } + + unsigned int Get() const { + return value; + } + + AtomicInteger& operator++(){ + increment(); + return *this; + } + + AtomicInteger operator++(int){ + increment(); + return *this; + } + + AtomicInteger& operator--(){ + decrement(); + return *this; + } + + AtomicInteger operator--(int){ + decrement(); + return *this; + } + +}; + +} // namespace atomic + +} // namespace tools + +} // namespace upnp + + +#endif /* ATOMIC_H_ */ |