0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeMaintenanceGuard.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; version 3 of the
9  * 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 this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hypertable_RangeServer_RangeMaintenanceGuard_h
23 #define Hypertable_RangeServer_RangeMaintenanceGuard_h
24 
25 #include <condition_variable>
26 #include <mutex>
27 
28 namespace Hypertable {
29 
31  public:
32 
34 
35  void activate() {
36  std::lock_guard<std::mutex> lock(m_mutex);
37  if (m_disabled)
39  if (m_in_progress)
41  m_in_progress = true;
42  }
43 
44  void deactivate() {
45  std::lock_guard<std::mutex> lock(m_mutex);
46  m_in_progress = false;
47  m_cond.notify_all();
48  }
49 
50  void wait_for_complete(bool disable=false) {
51  std::unique_lock<std::mutex> lock(m_mutex);
52  m_cond.wait(lock, [this](){ return !m_in_progress; });
53  if (disable)
54  m_disabled = true;
55  }
56 
57  bool in_progress() {
58  std::lock_guard<std::mutex> lock(m_mutex);
59  return m_in_progress;
60  }
61 
62  void disable() {
63  std::lock_guard<std::mutex> lock(m_mutex);
64  m_disabled = true;
65  }
66 
67  void enable() {
68  std::lock_guard<std::mutex> lock(m_mutex);
69  m_disabled = false;
70  }
71 
72  class Activator {
73  public:
75  m_guard->activate();
76  }
79  }
80  private:
82  };
83 
84  private:
86  std::condition_variable m_cond;
87  bool m_in_progress {};
88  bool m_disabled {};
89  };
90 
91 }
92 
93 
94 #endif // Hypertable_RangeServer_RangeMaintenanceGuard_h
static std::mutex mutex
Definition: Logger.cc:43
void wait_for_complete(bool disable=false)
Hypertable definitions
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478