0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Mutex.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
26 #ifndef Common_Mutex_h
27 #define Common_Mutex_h
28 
29 #include <Common/Logger.h>
30 
31 #include <atomic>
32 #include <mutex>
33 
34 namespace Hypertable {
35 
43  public:
44  void lock() { if (m_enabled) m_count++; m_mutex.lock();}
45  void unlock() { m_mutex.unlock(); if (m_enabled) m_count--; }
46  int32_t get_waiting_threads() {return (int32_t)((m_enabled && m_count>1) ? m_count-1 : 0);}
47  void set_statistics_enabled(bool val) { m_enabled = val; }
48  private:
49  std::atomic_int_fast32_t m_count {0};
51  bool m_enabled {true};
52  };
53 
56 }
57 
58 #endif // Common_Mutex_h
static std::mutex mutex
Definition: Logger.cc:43
void set_statistics_enabled(bool val)
Definition: Mutex.h:47
Logging routines and macros.
Mutex that maintains wait threads count.
Definition: Mutex.h:42
Hypertable definitions
std::atomic_int_fast32_t m_count
Definition: Mutex.h:49