]> granicus.if.org Git - pdns/commitdiff
make our AtomicCounter 64 bit on 64 bit machines
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 28 Nov 2014 14:17:16 +0000 (15:17 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 28 Nov 2014 14:17:16 +0000 (15:17 +0100)
pdns/misc.hh

index 803532df6ef2724cc2fad4b0cde0d0a3f3976b3e..4c5ad0d2beb01fba63503c198570206f40a8b2e1 100644 (file)
@@ -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);
     }