diff options
author | Antonin Kral <a.kral@bobek.cz> | 2011-06-18 21:24:54 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2011-06-18 21:24:54 +0200 |
commit | fefb1e355f6cbe35160f2f73ed68a38d95fa59a2 (patch) | |
tree | faecb2fb6677516c5f6d9edfae8475344ddd73ed /util/concurrency/value.h | |
parent | d95b46b2bbb5b4246213f252010508489b4e5719 (diff) | |
parent | 64b33ee522375a8dc15be2875dfb7db4502259b0 (diff) | |
download | mongodb-fefb1e355f6cbe35160f2f73ed68a38d95fa59a2.tar.gz |
Merge commit 'upstream/1.8.2'
Diffstat (limited to 'util/concurrency/value.h')
-rw-r--r-- | util/concurrency/value.h | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/util/concurrency/value.h b/util/concurrency/value.h index 08d5306..0a0ef85 100644 --- a/util/concurrency/value.h +++ b/util/concurrency/value.h @@ -60,28 +60,31 @@ 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 - diagnostic strings, where their content isn't critical. - */ class DiagStr { - char buf1[256]; - char buf2[256]; - char *p; + string _s; + static mutex m; public: - DiagStr() { - memset(buf1, 0, 256); - memset(buf2, 0, 256); - p = buf1; + DiagStr(const DiagStr& r) : _s(r.get()) { } + DiagStr() { } + bool empty() const { + mutex::scoped_lock lk(m); + return _s.empty(); + } + string get() const { + mutex::scoped_lock lk(m); + return _s; } - - const char * get() const { return p; } void set(const char *s) { - char *q = (p==buf1) ? buf2 : buf1; - strncpy(q, s, 255); - p = q; + mutex::scoped_lock lk(m); + _s = s; + } + void set(const string& s) { + mutex::scoped_lock lk(m); + _s = s; } + operator string() const { return get(); } + void operator=(const string& s) { set(s); } }; } |