MongoDB  2.7.0
simplerwlock.h
1 
29 #pragma once
30 
31 #include "mongo/base/string_data.h"
32 #include "mongo/bson/util/atomic_int.h"
33 
34 namespace mongo {
35 
39  class SimpleRWLock : boost::noncopyable {
40 #if defined(NTDDI_VERSION) && defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
41  SRWLOCK _lock;
42 #else
43  RWLockBase m;
44 #endif
45 #if defined(_WIN32) && defined(_DEBUG)
46  AtomicUInt shares;
48  unsigned tid;
49 #endif
50  public:
51  const string name;
52  SimpleRWLock(const StringData& name = "" );
53  void lock();
54  void unlock();
55  void lock_shared();
56  void unlock_shared();
57  class Shared : boost::noncopyable {
58  SimpleRWLock& _r;
59  public:
60  Shared(SimpleRWLock& rwlock) : _r(rwlock) {_r.lock_shared(); }
61  ~Shared() { _r.unlock_shared(); }
62  };
63  class Exclusive : boost::noncopyable {
64  SimpleRWLock& _r;
65  public:
66  Exclusive(SimpleRWLock& rwlock) : _r(rwlock) {_r.lock(); }
67  ~Exclusive() { _r.unlock(); }
68  };
69  };
70 
71 }
Definition: simplerwlock.h:63
Definition: rwlock.h:142
separated out as later the implementation of this may be different than RWLock, depending on OS...
Definition: simplerwlock.h:39
Definition: rwlockimpl.h:104
Definition: simplerwlock.h:57