summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2012-11-08 19:29:02 +0100
committermethodus <methodus@web.de>2012-11-08 19:29:02 +0100
commit5510375bdfdca7b73ac6c51920702d38b79ffcca (patch)
tree44231a410b3e1b0cfb20fd8310bf0fdbd53baf7c /include
parentdfbbc0a3c933a4a773c9e57795e25061bc38770e (diff)
downloadvdr-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.h78
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_ */