Changeset 1714
- Timestamp:
- 09/11/10 16:09:05 (3 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/misc.hh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/misc.hh
r1698 r1714 351 351 explicit AtomicCounter( unsigned int v = 0) : value_( v ) {} 352 352 353 voidoperator++()353 unsigned int operator++() 354 354 { 355 __sync_add_and_fetch( &value_, 1 );355 return atomic_exchange_and_add( &value_, +1 ) + 1; 356 356 } 357 357 358 358 unsigned int operator--() 359 359 { 360 return __sync_add_and_fetch( &value_, -1 );360 return atomic_exchange_and_add( &value_, -1 ) - 1; 361 361 } 362 362 363 363 operator unsigned int() const 364 364 { 365 return __sync_fetch_and_add( &value_, 0);365 return atomic_exchange_and_add( &value_, 0); 366 366 } 367 367 … … 371 371 372 372 mutable unsigned int value_; 373 374 // the below is necessary because __sync_fetch_and_add is not universally available on i386.. I 3> RHEL5. 375 #if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) 376 static int atomic_exchange_and_add( unsigned int * pw, int dv ) 377 { 378 // int r = *pw; 379 // *pw += dv; 380 // return r; 381 382 int r; 383 384 __asm__ __volatile__ 385 ( 386 "lock\n\t" 387 "xadd %1, %0": 388 "+m"( *pw ), "=r"( r ): // outputs (%0, %1) 389 "1"( dv ): // inputs (%2 == %1) 390 "memory", "cc" // clobbers 391 ); 392 393 return r; 394 } 395 #else 396 static int atomic_exchange_and_add( unsigned int * pw, int dv ) 397 { 398 return __sync_fetch_and_add(pw, dv); 399 } 400 #endif 373 401 }; 374 402