blob: f947d48799850e4285452f9f5901c3a13e2a3ad5 (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_AUTO_UNLOCK_EXTENSIOn_ABSTRACT_
#ifdef DLIB_AUTO_UNLOCK_EXTENSIOn_ABSTRACT_
#include "threads_kernel_abstract.h"
#include "rmutex_extension_abstract.h"
#include "read_write_mutex_extension_abstract.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
class auto_unlock
{
/*!
INITIAL VALUE
The mutex given in the constructor is associated with this object.
WHAT THIS OBJECT REPRESENTS
This object represents a mechanism for automatically unlocking
a mutex object. It is useful when you already have a locked mutex
and want to make sure it gets unlocked even if an exception is thrown
or you quit the function at a weird spot.
!*/
public:
explicit auto_unlock (
const mutex& m
);
/*!
ensures
- #*this is properly initialized
- does not modify m in any way
!*/
explicit auto_unlock (
const rmutex& m
);
/*!
ensures
- #*this is properly initialized
- does not modify m in any way
!*/
explicit auto_unlock (
const read_write_mutex& m
);
/*!
ensures
- #*this is properly initialized
- does not modify m in any way
!*/
~auto_unlock (
);
/*!
ensures
- all resources allocated by *this have been freed
- calls unlock() on the mutex associated with *this
!*/
private:
// restricted functions
auto_unlock(auto_unlock&); // copy constructor
auto_unlock& operator=(auto_unlock&); // assignment operator
};
// ----------------------------------------------------------------------------------------
class auto_unlock_readonly
{
/*!
INITIAL VALUE
The mutex given in the constructor is associated with this object.
WHAT THIS OBJECT REPRESENTS
This object represents a mechanism for automatically unlocking
a read_write_mutex object. It is useful when you already have a locked mutex
and want to make sure it gets unlocked even if an exception is thrown
or you quit the function at a weird spot. Note that the mutex
is unlocked by calling unlock_readonly() on it.
!*/
public:
explicit auto_unlock_readonly (
const read_write_mutex& m
);
/*!
ensures
- #*this is properly initialized
- does not modify m in any way
!*/
~auto_unlock_readonly (
);
/*!
ensures
- all resources allocated by *this have been freed
- calls unlock_readonly() on the mutex associated with *this
!*/
private:
// restricted functions
auto_unlock_readonly(auto_unlock_readonly&); // copy constructor
auto_unlock_readonly& operator=(auto_unlock_readonly&); // assignment operator
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_AUTO_UNLOCK_EXTENSIOn_ABSTRACT_
|