A helper class that acquires the given Lock while the AutoLock is in scope.
| 122 | |
| 123 | // A helper class that acquires the given Lock while the AutoLock is in scope. |
| 124 | class AutoLock { |
| 125 | public: |
| 126 | struct AlreadyAcquired {}; |
| 127 | |
| 128 | explicit AutoLock(Lock& lock) : lock_(lock) { lock_.Acquire(); } |
| 129 | |
| 130 | AutoLock(Lock& lock, const AlreadyAcquired&) : lock_(lock) { |
| 131 | lock_.AssertAcquired(); |
| 132 | } |
| 133 | |
| 134 | ~AutoLock() { |
| 135 | lock_.AssertAcquired(); |
| 136 | lock_.Release(); |
| 137 | } |
| 138 | |
| 139 | private: |
| 140 | Lock& lock_; |
| 141 | DISALLOW_COPY_AND_ASSIGN(AutoLock); |
| 142 | }; |
| 143 | |
| 144 | // AutoUnlock is a helper that will Release() the |lock| argument in the |
| 145 | // constructor, and re-Acquire() it in the destructor. |
nothing calls this directly
no outgoing calls
no test coverage detected