ChimeraTK-DeviceAccess 03.26.00
Loading...
Searching...
No Matches
CountedRecursiveMutex.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
5
6#include <cassert>
7
8namespace ChimeraTK::detail {
9
10 /********************************************************************************************************************/
11
12 size_t CountedRecursiveMutex::useCount() const {
13 return _useCount;
14 }
15
16 /********************************************************************************************************************/
17
18 void CountedRecursiveMutex::unlock() {
19 assert(_useCount > 0);
20 _useCount--;
21 std::recursive_mutex::unlock();
22 }
23 /********************************************************************************************************************/
24
25 void CountedRecursiveMutex::lock() {
26 std::recursive_mutex::lock();
27 _useCount++;
28 }
29
30 /********************************************************************************************************************/
31
32 bool CountedRecursiveMutex::try_lock() {
33 if(std::recursive_mutex::try_lock()) {
34 _useCount++;
35 return true;
36 }
37 return false;
38 }
39
40 /********************************************************************************************************************/
41} // namespace ChimeraTK::detail