1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#ifndef __UTIL_LOCKFREE_COUNTER_H #define __UTIL_LOCKFREE_COUNTER_H namespace Util { namespace Lockfree { template <typename _T> class Counter { public: Counter() : value(_T()) {}; _T next() { return __sync_fetch_and_add(&value, 1); }; private: _T value; }; }; }; #endif