From 582fc32574a3b158c81e49cb00e6ae59205e66ba Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Thu, 17 Mar 2011 00:05:43 +0100 Subject: Imported Upstream version 1.8.0 --- util/concurrency/value.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'util/concurrency/value.h') diff --git a/util/concurrency/value.h b/util/concurrency/value.h index dabeb95..08d5306 100644 --- a/util/concurrency/value.h +++ b/util/concurrency/value.h @@ -20,11 +20,11 @@ #pragma once -namespace mongo { +namespace mongo { extern mutex _atomicMutex; - /** atomic wrapper for a value. enters a mutex on each access. must + /** atomic wrapper for a value. enters a mutex on each access. must be copyable. */ template @@ -33,20 +33,22 @@ namespace mongo { public: Atomic() { } - void operator=(const T& a) { + void operator=(const T& a) { scoped_lock lk(_atomicMutex); - val = a; } + val = a; + } - operator T() const { + operator T() const { scoped_lock lk(_atomicMutex); - return val; } - + return val; + } + /** example: Atomic q; ... { Atomic::tran t(q); - if( q.ref() > 0 ) + if( q.ref() > 0 ) q.ref()--; } */ @@ -58,11 +60,11 @@ namespace mongo { }; }; - /** this string COULD be mangled but with the double buffering, assuming writes - are infrequent, it's unlikely. thus, this is reasonable for lockless setting of + /** this string COULD be mangled but with the double buffering, assuming writes + are infrequent, it's unlikely. thus, this is reasonable for lockless setting of diagnostic strings, where their content isn't critical. */ - class DiagStr { + class DiagStr { char buf1[256]; char buf2[256]; char *p; -- cgit v1.2.3