source: mainline/uspace/lib/cpp/src/mutex.cpp@ 8624d1f

Last change on this file since 8624d1f was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <mutex>
8
9namespace std
10{
11 void mutex::lock()
12 {
13 aux::threading::mutex::lock(mtx_);
14 }
15
16 bool mutex::try_lock()
17 {
18 return aux::threading::mutex::try_lock(mtx_);
19 }
20
21 void mutex::unlock()
22 {
23 aux::threading::mutex::unlock(mtx_);
24 }
25
26 mutex::native_handle_type mutex::native_handle()
27 {
28 return &mtx_;
29 }
30
31 recursive_mutex::~recursive_mutex()
32 { /* DUMMY BODY */ }
33
34 void recursive_mutex::lock()
35 {
36 if (owner_ != this_thread::get_id())
37 {
38 aux::threading::mutex::lock(mtx_);
39 owner_ = this_thread::get_id();
40 lock_level_ = 1;
41 }
42 else
43 ++lock_level_;
44 }
45
46 bool recursive_mutex::try_lock() noexcept
47 {
48 if (owner_ != this_thread::get_id())
49 {
50 bool res = aux::threading::mutex::try_lock(mtx_);
51 if (res)
52 {
53 owner_ = this_thread::get_id();
54 lock_level_ = 1;
55 }
56
57 return res;
58 }
59 else
60 ++lock_level_;
61
62 return true;
63 }
64
65 void recursive_mutex::unlock()
66 {
67 if (owner_ != this_thread::get_id())
68 return;
69 else if (--lock_level_ == 0)
70 aux::threading::mutex::unlock(mtx_);
71 }
72
73 recursive_mutex::native_handle_type recursive_mutex::native_handle()
74 {
75 return &mtx_;
76 }
77
78 timed_mutex::timed_mutex() noexcept
79 : mtx_{}
80 {
81 aux::threading::mutex::init(mtx_);
82 }
83
84 timed_mutex::~timed_mutex()
85 { /* DUMMY BODY */ }
86
87 void timed_mutex::lock()
88 {
89 aux::threading::mutex::lock(mtx_);
90 }
91
92 bool timed_mutex::try_lock()
93 {
94 return aux::threading::mutex::try_lock(mtx_);
95 }
96
97 void timed_mutex::unlock()
98 {
99 aux::threading::mutex::unlock(mtx_);
100 }
101
102 timed_mutex::native_handle_type timed_mutex::native_handle()
103 {
104 return &mtx_;
105 }
106
107 recursive_timed_mutex::~recursive_timed_mutex()
108 { /* DUMMY BODY */ }
109
110 void recursive_timed_mutex::lock()
111 {
112 if (owner_ != this_thread::get_id())
113 {
114 aux::threading::mutex::lock(mtx_);
115 owner_ = this_thread::get_id();
116 lock_level_ = 1;
117 }
118 else
119 ++lock_level_;
120 }
121
122 bool recursive_timed_mutex::try_lock() noexcept
123 {
124 if (owner_ != this_thread::get_id())
125 {
126 bool res = aux::threading::mutex::try_lock(mtx_);
127 if (res)
128 {
129 owner_ = this_thread::get_id();
130 lock_level_ = 1;
131 }
132
133 return res;
134 }
135 else
136 ++lock_level_;
137
138 return true;
139 }
140
141 void recursive_timed_mutex::unlock()
142 {
143 if (owner_ != this_thread::get_id())
144 return;
145 else if (--lock_level_ == 0)
146 aux::threading::mutex::unlock(mtx_);
147 }
148
149 recursive_timed_mutex::native_handle_type recursive_timed_mutex::native_handle()
150 {
151 return &mtx_;
152 }
153}
Note: See TracBrowser for help on using the repository browser.