From: bert hubert Date: Fri, 28 Nov 2014 14:17:16 +0000 (+0100) Subject: make our AtomicCounter 64 bit on 64 bit machines X-Git-Tag: rec-3.7.0-rc1~159^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=297bb6acf7902068693a4aae1443c424d0e8dd52;p=thirdparty%2Fpdns.git make our AtomicCounter 64 bit on 64 bit machines --- diff --git a/pdns/misc.hh b/pdns/misc.hh index 803532df6e..4c5ad0d2be 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -356,25 +356,25 @@ inline bool pdns_iequals_ch(const char a, const char b) class AtomicCounter { public: + typedef unsigned long native_t; + explicit AtomicCounter( native_t v = 0) : value_( v ) {} - explicit AtomicCounter( unsigned int v = 0) : value_( v ) {} - - unsigned int operator++() + native_t operator++() { return atomic_exchange_and_add( &value_, +1 ) + 1; } - unsigned int operator++(int) + native_t operator++(int) { return atomic_exchange_and_add( &value_, +1 ); } - unsigned int operator--() + native_t operator--() { return atomic_exchange_and_add( &value_, -1 ) - 1; } - operator unsigned int() const + operator native_t() const { return atomic_exchange_and_add( &value_, 0); } @@ -384,11 +384,11 @@ public: } private: - mutable unsigned int value_; + mutable native_t value_; // the below is necessary because __sync_fetch_and_add is not universally available on i386.. I 3> RHEL5. - #if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) - static int atomic_exchange_and_add( unsigned int * pw, int dv ) +#if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) + static int atomic_exchange_and_add( native_t * pw, int dv ) { // int r = *pw; // *pw += dv; @@ -408,7 +408,7 @@ private: return r; } #else - static int atomic_exchange_and_add( unsigned int * pw, int dv ) + static int atomic_exchange_and_add( native_t * pw, int dv ) { return __sync_fetch_and_add(pw, dv); }