0.9.8.10
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
home
doug
src
hypertable
src
cc
Hypertable
RangeServer
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
30
class
RangeMaintenanceGuard
{
31
public
:
32
33
RangeMaintenanceGuard
() {}
34
35
void
activate
() {
36
std::lock_guard<std::mutex> lock(
m_mutex
);
37
if
(
m_disabled
)
38
HT_THROW
(
Error::RANGESERVER_RANGE_NOT_ACTIVE
,
""
);
39
if
(
m_in_progress
)
40
HT_THROW
(
Error::RANGESERVER_RANGE_BUSY
,
""
);
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
:
74
Activator
(
RangeMaintenanceGuard
&guard) :
m_guard
(&guard) {
75
m_guard
->
activate
();
76
}
77
~Activator
() {
78
m_guard
->
deactivate
();
79
}
80
private
:
81
RangeMaintenanceGuard
*
m_guard
;
82
};
83
84
private
:
85
std::mutex
m_mutex
;
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
Hypertable::RangeMaintenanceGuard::Activator
Definition:
RangeMaintenanceGuard.h:72
Hypertable::Logger::mutex
static std::mutex mutex
Definition:
Logger.cc:43
Hypertable::RangeMaintenanceGuard::in_progress
bool in_progress()
Definition:
RangeMaintenanceGuard.h:57
Hypertable::Error::RANGESERVER_RANGE_NOT_ACTIVE
Definition:
Error.h:232
Hypertable::RangeMaintenanceGuard::m_mutex
std::mutex m_mutex
Definition:
RangeMaintenanceGuard.h:85
Hypertable::RangeMaintenanceGuard
Definition:
RangeMaintenanceGuard.h:30
Hypertable::RangeMaintenanceGuard::disable
void disable()
Definition:
RangeMaintenanceGuard.h:62
Hypertable::RangeMaintenanceGuard::deactivate
void deactivate()
Definition:
RangeMaintenanceGuard.h:44
Hypertable::RangeMaintenanceGuard::enable
void enable()
Definition:
RangeMaintenanceGuard.h:67
Hypertable::RangeMaintenanceGuard::m_disabled
bool m_disabled
Definition:
RangeMaintenanceGuard.h:88
Hypertable::RangeMaintenanceGuard::Activator::Activator
Activator(RangeMaintenanceGuard &guard)
Definition:
RangeMaintenanceGuard.h:74
Hypertable::RangeMaintenanceGuard::Activator::~Activator
~Activator()
Definition:
RangeMaintenanceGuard.h:77
Hypertable::RangeMaintenanceGuard::activate
void activate()
Definition:
RangeMaintenanceGuard.h:35
Hypertable::RangeMaintenanceGuard::Activator::m_guard
RangeMaintenanceGuard * m_guard
Definition:
RangeMaintenanceGuard.h:81
Hypertable::RangeMaintenanceGuard::m_in_progress
bool m_in_progress
Definition:
RangeMaintenanceGuard.h:87
Hypertable::Error::RANGESERVER_RANGE_BUSY
Definition:
Error.h:229
Hypertable::RangeMaintenanceGuard::wait_for_complete
void wait_for_complete(bool disable=false)
Definition:
RangeMaintenanceGuard.h:50
Hypertable
Hypertable definitions
Definition:
ApplicationHandler.h:36
Hypertable::RangeMaintenanceGuard::m_cond
std::condition_variable m_cond
Definition:
RangeMaintenanceGuard.h:86
HT_THROW
#define HT_THROW(_code_, _msg_)
Definition:
Error.h:478
Hypertable::RangeMaintenanceGuard::RangeMaintenanceGuard
RangeMaintenanceGuard()
Definition:
RangeMaintenanceGuard.h:33
Generated on Tue Dec 22 2015 18:43:17 for Hypertable by
1.8.8