MongoDB  2.7.0
concurrency/value.h
1 /* @file value.h
2  concurrency helpers DiagStr
3 */
4 
33 #pragma once
34 
35 #include "spin_lock.h"
36 
37 namespace mongo {
38 
39  // todo: rename this to ThreadSafeString or something
43  class DiagStr {
44  mutable SpinLock m;
45  string _s;
46  public:
47  DiagStr(const DiagStr& r) : _s(r.get()) { }
48  DiagStr(const string& r) : _s(r) { }
49  DiagStr() { }
50  bool empty() const {
51  scoped_spinlock lk(m);
52  return _s.empty();
53  }
54  string get() const {
55  scoped_spinlock lk(m);
56  return _s;
57  }
58  void set(const char *s) {
59  scoped_spinlock lk(m);
60  _s = s;
61  }
62  void set(const string& s) {
63  scoped_spinlock lk(m);
64  _s = s;
65  }
66  operator string() const { return get(); }
67  void operator=(const string& s) { set(s); }
68  void operator=(const DiagStr& rhs) {
69  set( rhs.get() );
70  }
71 
72  // == is not defined. use get() == ... instead. done this way so one thinks about if composing multiple operations
73  bool operator==(const string& s) const;
74  };
75 
76 }
Definition: spin_lock.h:82
The spinlock currently requires late GCC support routines to be efficient.
Definition: spin_lock.h:45
there is now one mutex per DiagStr.
Definition: concurrency/value.h:43