File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- /*
2- Copyright (c) 2013 Microsoft Corporation. All rights reserved.
3- Released under Apache 2.0 license as described in the file LICENSE.
41
5- Author: Leonardo de Moura
6- */
7- #pragma once
8- #include " util/thread.h"
9- namespace lean {
10- /* *
11- \brief The class \c unlock_guard is a mutex wrapper that provides a
12- convenient RAII-style mechanism for releasing a mutex for the
13- duration of a scoped block.
14-
15- It is the dual of lock_guard in the standard library.
16-
17- Example:
18- <code>
19- {
20- lock_guard<mutex> lock(m);
21- ...
22- {
23- unlock_guard unlock(m);
24- ...
25- }
26- ...
27- }
28- </code>
29-
30- \warning The calling thread must own the lock to m_mutex
31- */
32- class unlock_guard {
33- mutex & m_mutex;
34- public:
35- explicit unlock_guard (mutex & m):m_mutex(m) { m_mutex.unlock (); }
36- unlock_guard (unlock_guard const &) = delete ;
37- unlock_guard (unlock_guard &&) = delete ;
38- unlock_guard & operator =(unlock_guard const &) = delete ;
39- unlock_guard & operator =(unlock_guard &&) = delete ;
40- ~unlock_guard () { m_mutex.lock (); }
41- };
42- }
You can’t perform that action at this time.
0 commit comments