summaryrefslogtreecommitdiff
path: root/node/AtomicCounter.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/AtomicCounter.hpp')
-rw-r--r--node/AtomicCounter.hpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/node/AtomicCounter.hpp b/node/AtomicCounter.hpp
index a0f29baa..a42a18d4 100644
--- a/node/AtomicCounter.hpp
+++ b/node/AtomicCounter.hpp
@@ -1,6 +1,6 @@
/*
* ZeroTier One - Network Virtualization Everywhere
- * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
+ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,13 +14,20 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * You can be released from the requirements of the license by purchasing
+ * a commercial license. Buying such a license is mandatory as soon as you
+ * develop commercial closed-source software that incorporates or links
+ * directly against ZeroTier software without disclosing the source code
+ * of your own application.
*/
#ifndef ZT_ATOMICCOUNTER_HPP
#define ZT_ATOMICCOUNTER_HPP
#include "Constants.hpp"
-#include "NonCopyable.hpp"
#ifndef __GNUC__
#include <atomic>
@@ -31,12 +38,18 @@ namespace ZeroTier {
/**
* Simple atomic counter supporting increment and decrement
*/
-class AtomicCounter : NonCopyable
+class AtomicCounter
{
public:
- AtomicCounter()
+ AtomicCounter() { _v = 0; }
+
+ inline int load() const
{
- _v = 0;
+#ifdef __GNUC__
+ return __sync_or_and_fetch(const_cast<int *>(&_v),0);
+#else
+ return _v.load();
+#endif
}
inline int operator++()
@@ -58,6 +71,9 @@ public:
}
private:
+ AtomicCounter(const AtomicCounter &) {}
+ const AtomicCounter &operator=(const AtomicCounter &) { return *this; }
+
#ifdef __GNUC__
int _v;
#else