-
Notifications
You must be signed in to change notification settings - Fork 246
/
lock_guard.h
45 lines (35 loc) · 1 KB
/
lock_guard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* \brief Lock guard
* \author Norman Feske
* \date 2006-07-26
*/
/*
* Copyright (C) 2006-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__LOCK_GUARD_H_
#define _INCLUDE__BASE__LOCK_GUARD_H_
namespace Genode { template <typename> class Lock_guard; }
/**
* Lock guard template
*
* \param LT lock type
*
* A lock guard is instantiated as a local variable. When a lock guard is
* constructed, it acquires the lock that is specified as constructor argument.
* When the control flow leaves the scope of the lock-guard variable via a
* return statement or an exception, the lock guard's destructor gets called,
* freeing the lock.
*/
template <typename LT>
class Genode::Lock_guard
{
private:
LT &_lock;
public:
explicit Lock_guard(LT &lock) : _lock(lock) { _lock.lock(); }
~Lock_guard() { _lock.unlock(); }
};
#endif /* _INCLUDE__BASE__LOCK_GUARD_H_ */