Permalink
Browse files

make our AtomicCounter 64 bit on 64 bit machines

  • Loading branch information...
1 parent 0072493 commit 297bb6acf7902068693a4aae1443c424d0e8dd52 @ahupowerdns ahupowerdns committed Nov 28, 2014
Showing with 10 additions and 10 deletions.
  1. +10 −10 pdns/misc.hh
View
@@ -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);
}

0 comments on commit 297bb6a

Please sign in to comment.