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
RevLine 
[a75f3e49]1/*
[b57ba05]2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
[a75f3e49]3 *
[b57ba05]4 * SPDX-License-Identifier: BSD-3-Clause
[a75f3e49]5 */
6
7#include <mutex>
8
9namespace std
10{
11 void mutex::lock()
12 {
[9283830]13 aux::threading::mutex::lock(mtx_);
[a75f3e49]14 }
15
16 bool mutex::try_lock()
17 {
[9283830]18 return aux::threading::mutex::try_lock(mtx_);
[a75f3e49]19 }
20
21 void mutex::unlock()
22 {
[9283830]23 aux::threading::mutex::unlock(mtx_);
[a75f3e49]24 }
25
26 mutex::native_handle_type mutex::native_handle()
27 {
[ecb072d]28 return &mtx_;
[a75f3e49]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 {
[9283830]38 aux::threading::mutex::lock(mtx_);
[a75f3e49]39 owner_ = this_thread::get_id();
40 lock_level_ = 1;
41 }
42 else
43 ++lock_level_;
44 }
45
[857d4cc]46 bool recursive_mutex::try_lock() noexcept
[a75f3e49]47 {
48 if (owner_ != this_thread::get_id())
49 {
[9283830]50 bool res = aux::threading::mutex::try_lock(mtx_);
[a75f3e49]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)
[9283830]70 aux::threading::mutex::unlock(mtx_);
[a75f3e49]71 }
72
73 recursive_mutex::native_handle_type recursive_mutex::native_handle()
74 {
[ecb072d]75 return &mtx_;
[a75f3e49]76 }
[befead8]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 }
[857d4cc]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
[a97b838]122 bool recursive_timed_mutex::try_lock() noexcept
[857d4cc]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 }
[a75f3e49]153}
Note: See TracBrowser for help on using the repository browser.