Kea 2.7.5
interprocess_sync.h
Go to the documentation of this file.
1// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef INTERPROCESS_SYNC_H
8#define INTERPROCESS_SYNC_H
9
10#include <string>
11
12namespace isc {
13namespace log {
14namespace interprocess {
15
16class InterprocessSyncLocker; // forward declaration
17
39 // InterprocessSyncLocker is the only code outside this class that
40 // should be allowed to call the lock(), tryLock() and unlock()
41 // methods.
43
44public:
52 InterprocessSync(const std::string& task_name) :
53 task_name_(task_name), is_locked_(false)
54 {}
55
57 virtual ~InterprocessSync() {}
58
59protected:
64 virtual bool lock() = 0;
65
69 virtual bool tryLock() = 0;
70
74 virtual bool unlock() = 0;
75
76 const std::string task_name_;
78};
79
87public:
97
100 if (isLocked())
101 unlock();
102 }
103
108 bool lock() {
109 return (sync_.lock());
110 }
111
116 bool tryLock() {
117 return (sync_.tryLock());
118 }
119
124 bool isLocked() const {
125 return (sync_.is_locked_);
126 }
127
131 bool unlock() {
132 return (sync_.unlock());
133 }
134
135protected:
137};
138
139} // namespace interprocess
140} // namespace log
141} // namespace isc
142
143#endif // INTERPROCESS_SYNC_H
bool isLocked() const
Check if the lock is taken.
bool lock()
Acquire the lock (blocks if something else has acquired a lock on the same task name)
bool tryLock()
Try to acquire a lock (doesn't block)
InterprocessSyncLocker(InterprocessSync &sync)
Constructor.
InterprocessSync & sync_
Ref to underlying sync object.
virtual bool unlock()=0
Release the lock.
InterprocessSync(const std::string &task_name)
Constructor.
virtual bool lock()=0
Acquire the lock (blocks if something else has acquired a lock on the same task name)
const std::string task_name_
The task name.
virtual bool tryLock()=0
Try to acquire a lock (doesn't block)
Defines the logger used by the top-level component of kea-lfc.