6#include "../diagnostics/stack_frame.hpp"
7#include "../core_export.hpp"
8#include "../invalid_operation_exception.hpp"
9#include "../static.hpp"
10#include "../time_span.hpp"
11#include "../types.hpp"
14#include <unordered_map>
130 class condition_variable;
131 class critical_section;
133 using item_collection = std::unordered_map<intptr, item>;
134 using object_ptr = std::pair<intptr, bool>;
144 template<
class object_t>
145 static void enter(
const object_t& obj) {
146 auto lock_taken =
false;
147 enter_ptr(get_ptr(obj), lock_taken);
151 template<
class type_t>
152 static void enter(
const type_t* str) {
enter(
string(str));}
160 template<
class object_t>
161 static void enter(
const object_t& obj,
bool& lock_taken) {
162 enter_ptr(get_ptr(obj), lock_taken);
166 template<
class type_t>
167 static void enter(
const type_t* str,
bool& lock_taken) {
enter(
string(str), lock_taken);}
174 template<
class object_t>
175 static void exit(
const object_t& obj) {
176 exit_ptr(get_ptr(obj));
180 template<
class type_t>
181 static void exit(
const type_t* str) {exit(
string(str));}
189 template<
class object_t>
191 return is_entered_ptr(get_ptr(obj));
195 template<
class type_t>
196 static bool is_entered(
const type_t* str) {
return is_entered(
string(str));}
208 template<
class object_t>
209 static void pulse(
const object_t& obj) {
210 pulse_ptr(get_ptr(obj));
214 template<
class type_t>
215 static void pulse(
const type_t* str) {pulse(
string(str));}
226 template<
class object_t>
228 pulse_all_ptr(get_ptr(obj));
232 template<
class type_t>
233 static void pulse_all(
const type_t* str) {pulse_all(
string(str));}
241 template<
class object_t>
243 auto lock_taken =
false;
244 return try_enter_ptr(get_ptr(obj), timeout::infinite, lock_taken);
248 template<
class type_t>
249 static bool try_enter(
const type_t* str) {
return try_enter(
string(str));}
259 template<
class object_t>
260 static bool try_enter(
const object_t& obj,
bool& lock_taken)
noexcept {
261 return try_enter_ptr(get_ptr(obj), timeout::infinite, lock_taken);
265 template<
class type_t>
266 static bool try_enter(
const type_t* str,
bool& lock_taken) {
return try_enter(
string(str), lock_taken);}
274 template<
class object_t>
275 static bool try_enter(
const object_t& obj,
int32 milliseconds_timeout)
noexcept {
276 auto lock_taken =
false;
277 return try_enter_ptr(get_ptr(obj), milliseconds_timeout, lock_taken);
281 template<
class type_t>
282 static bool try_enter(
const type_t* str,
int32 milliseconds_timeout) {
return try_enter(
string(str), milliseconds_timeout);}
292 template<
class object_t>
293 static bool try_enter(
const object_t& obj,
int32 milliseconds_timeout,
bool& lock_taken)
noexcept {
294 return try_enter_ptr(get_ptr(obj), milliseconds_timeout, lock_taken);
298 template<
class type_t>
299 static bool try_enter(
const type_t* str,
int32 milliseconds_timeout,
bool& lock_taken) {
return try_enter(
string(str), milliseconds_timeout, lock_taken);}
307 template<
class object_t>
308 static bool try_enter(
const object_t& obj,
int64 milliseconds_timeout)
noexcept {
309 auto lock_taken =
false;
310 return try_enter_ptr(get_ptr(obj),
static_cast<int32>(milliseconds_timeout), lock_taken);
314 template<
class type_t>
315 static bool try_enter(
const type_t* str,
int64 milliseconds_timeout) {
return try_enter(
string(str), milliseconds_timeout);}
325 template<
class object_t>
326 static bool try_enter(
const object_t& obj,
int64 milliseconds_timeout,
bool& lock_taken)
noexcept {
327 return try_enter_ptr(get_ptr(obj),
static_cast<int32>(milliseconds_timeout), lock_taken);
331 template<
class type_t>
332 static bool try_enter(
const type_t* str,
int64 milliseconds_timeout,
bool& lock_taken) {
return try_enter(
string(str), milliseconds_timeout, lock_taken);}
340 template<
class object_t>
342 auto lock_taken =
false;
343 return try_enter_ptr(get_ptr(obj),
timeout.total_milliseconds_duration().count(), lock_taken);
347 template<
class type_t>
358 template<
class object_t>
360 return try_enter_ptr(get_ptr(obj),
timeout.total_milliseconds_duration().count(), lock_taken);
377 template<
class object_t>
378 static bool wait(
const object_t& obj,
int32 milliseconds_timeout) {
379 return wait_ptr(get_ptr(obj), milliseconds_timeout);
396 template<
class object_t>
398 return wait_ptr(get_ptr(obj), as<int32>(
timeout.total_milliseconds()));
414 template<
class object_t>
415 static bool wait(
const object_t& obj) {
416 return wait_ptr(get_ptr(obj), timeout::infinite);
421 template<
class type_t>
422 static bool try_enter(
const type_t* str,
const time_span&
timeout,
bool& lock_taken) {
return try_enter(
string(str),
timeout, lock_taken);}
428 static static_data& get_static_data();
430 template<
class object_t>
431 static object_ptr get_ptr(
const object_t& obj)
noexcept {
432 bool is_string = is<string>(obj);
434 return std::make_pair(is_string ? get_string_ptr(*(
new string(as<string>(obj)))) : reinterpret_cast<
intptr>(&obj), is_string);
437 template<
class type_t>
438 static object_ptr get_ptr(
const type_t* str) {
return get_ptr(
string(str));}
440 static void enter_ptr(object_ptr obj);
441 static void enter_ptr(object_ptr obj,
bool& lock_taken);
442 static void exit_ptr(object_ptr obj);
443 static intptr get_string_ptr(
const string& str);
444 static bool is_entered_ptr(object_ptr obj)
noexcept;
445 static void pulse_ptr(object_ptr obj);
446 static void pulse_all_ptr(object_ptr obj);
447 static bool try_enter_ptr(object_ptr obj, int32 milliseconds_timeout,
bool& lock_taken)
noexcept;
448 static bool wait_ptr(object_ptr obj, int32 milliseconds_timeout);
Provides a mechanism that synchronizes access to objects with xtd::threading::monitor.
Definition lock_guard.hpp:32
Provides a mechanism that synchronizes access to objects.
Definition monitor.hpp:129
static void pulse(const object_t &obj)
Notifies a thread in the waiting queue of a change in the locked object's state.
Definition monitor.hpp:209
static bool try_enter(const object_t &obj, int64 milliseconds_timeout, bool &lock_taken) noexcept
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:326
static bool try_enter(const object_t &obj) noexcept
Attempts to acquire an exclusive lock on the specified object.
Definition monitor.hpp:242
static bool try_enter(const object_t &obj, const time_span &timeout) noexcept
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.
Definition monitor.hpp:341
static void pulse_all(const object_t &obj)
Notifies all waiting threads of a change in the object's state.
Definition monitor.hpp:227
static bool wait(const object_t &obj)
Releases the lock on an object and blocks the current thread until it reacquires the lock.
Definition monitor.hpp:415
static bool wait(const object_t &obj, const time_span &timeout)
Releases the lock on an object and blocks the current thread until it reacquires the lock....
Definition monitor.hpp:397
static bool try_enter(const object_t &obj, int32 milliseconds_timeout, bool &lock_taken) noexcept
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:293
static void exit(const object_t &obj)
Releases an exclusive lock on the specified obj.
Definition monitor.hpp:175
static bool is_entered(const object_t &obj)
Determines whether the current thread holds the lock on the specified object.
Definition monitor.hpp:190
static bool try_enter(const object_t &obj, int32 milliseconds_timeout) noexcept
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:275
static bool try_enter(const object_t &obj, const time_span &timeout, bool &lock_taken) noexcept
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.
Definition monitor.hpp:359
static bool wait(const object_t &obj, int32 milliseconds_timeout)
Releases the lock on an object and blocks the current thread until it reacquires the lock....
Definition monitor.hpp:378
static void enter(const object_t &obj)
Acquires an exclusive lock on the specified obj.
Definition monitor.hpp:145
static void enter(const object_t &obj, bool &lock_taken)
Acquires an exclusive lock on the specified obj.
Definition monitor.hpp:161
static bool try_enter(const object_t &obj, bool &lock_taken) noexcept
Attempts to acquire an exclusive lock on the specified object.
Definition monitor.hpp:260
static bool try_enter(const object_t &obj, int64 milliseconds_timeout) noexcept
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:308
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.hpp:33
Represents a time interval.
Definition time_span.hpp:29
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define core_export_
Define shared library export.
Definition core_export.hpp:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::threading::timeout class.