Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
mutexlock.h
Go to the documentation of this file.
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 
5 #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
6 #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
7 
8 #include "port/port.h"
10 
11 namespace leveldb {
12 
13 // Helper class that locks a mutex on construction and unlocks the mutex when
14 // the destructor of the MutexLock object is invoked.
15 //
16 // Typical usage:
17 //
18 // void MyClass::MyMethod() {
19 // MutexLock l(&mu_); // mu_ is an instance variable
20 // ... some complex code, possibly with multiple return paths ...
21 // }
22 
24  public:
26  : mu_(mu) {
27  this->mu_->Lock();
28  }
29  ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); }
30 
31  private:
32  port::Mutex *const mu_;
33  // No copying allowed
34  MutexLock(const MutexLock&);
35  void operator=(const MutexLock&);
36 };
37 
38 } // namespace leveldb
39 
40 
41 #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
#define EXCLUSIVE_LOCK_FUNCTION(...)
port::Mutex mu_
Definition: db_test.cc:31
#define SCOPED_LOCKABLE
port::Mutex mu
Definition: db_bench.cc:270
#define UNLOCK_FUNCTION(...)
port::Mutex *const mu_
Definition: mutexlock.h:32
MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
Definition: mutexlock.h:25
~MutexLock() UNLOCK_FUNCTION()
Definition: mutexlock.h:29