6#include "../collections/generic/key_value_pair.h"
7#include "../diagnostics/stack_frame.h"
8#include "../core_export.h"
9#include "../invalid_operation_exception.h"
11#include "../time_span.h"
15#include <unordered_map>
131 class condition_variable;
132 class critical_section;
134 using item_collection = std::unordered_map<intptr, item>;
145 template<
typename object_t>
146 static void enter(
const object_t& obj) {
147 auto lock_taken =
false;
148 enter_ptr(get_ptr(obj), lock_taken);
152 template<
typename type_t>
153 static void enter(
const type_t* str) {
enter(
string(str));}
161 template<
typename object_t>
162 static void enter(
const object_t& obj,
bool& lock_taken) {
163 enter_ptr(get_ptr(obj), lock_taken);
167 template<
typename type_t>
168 static void enter(
const type_t* str,
bool& lock_taken) {
enter(
string(str), lock_taken);}
175 template<
typename object_t>
176 static void exit(
const object_t& obj) {
177 exit_ptr(get_ptr(obj));
181 template<
typename type_t>
182 static void exit(
const type_t* str) {exit(
string(str));}
190 template<
typename object_t>
192 return is_entered_ptr(get_ptr(obj));
196 template<
typename type_t>
197 static bool is_entered(
const type_t* str) {
return is_entered(
string(str));}
209 template<
typename object_t>
210 static void pulse(
const object_t& obj) {
211 pulse_ptr(get_ptr(obj));
215 template<
typename type_t>
216 static void pulse(
const type_t* str) {pulse(
string(str));}
227 template<
typename object_t>
229 pulse_all_ptr(get_ptr(obj));
233 template<
typename type_t>
234 static void pulse_all(
const type_t* str) {pulse_all(
string(str));}
242 template<
typename object_t>
244 auto lock_taken =
false;
245 return try_enter_ptr(get_ptr(obj), timeout::infinite, lock_taken);
249 template<
typename type_t>
250 static bool try_enter(
const type_t* str) {
return try_enter(
string(str));}
260 template<
typename object_t>
261 static bool try_enter(
const object_t& obj,
bool& lock_taken)
noexcept {
262 return try_enter_ptr(get_ptr(obj), timeout::infinite, lock_taken);
266 template<
typename type_t>
267 static bool try_enter(
const type_t* str,
bool& lock_taken) {
return try_enter(
string(str), lock_taken);}
275 template<
typename object_t>
276 static bool try_enter(
const object_t& obj,
int32 milliseconds_timeout)
noexcept {
277 auto lock_taken =
false;
278 return try_enter_ptr(get_ptr(obj), milliseconds_timeout, lock_taken);
282 template<
typename type_t>
283 static bool try_enter(
const type_t* str,
int32 milliseconds_timeout) {
return try_enter(
string(str), milliseconds_timeout);}
293 template<
typename object_t>
294 static bool try_enter(
const object_t& obj,
int32 milliseconds_timeout,
bool& lock_taken)
noexcept {
295 return try_enter_ptr(get_ptr(obj), milliseconds_timeout, lock_taken);
299 template<
typename type_t>
300 static bool try_enter(
const type_t* str,
int32 milliseconds_timeout,
bool& lock_taken) {
return try_enter(
string(str), milliseconds_timeout, lock_taken);}
308 template<
typename object_t>
309 static bool try_enter(
const object_t& obj,
int64 milliseconds_timeout)
noexcept {
310 auto lock_taken =
false;
311 return try_enter_ptr(get_ptr(obj),
static_cast<int32>(milliseconds_timeout), lock_taken);
315 template<
typename type_t>
316 static bool try_enter(
const type_t* str,
int64 milliseconds_timeout) {
return try_enter(
string(str), milliseconds_timeout);}
326 template<
typename object_t>
327 static bool try_enter(
const object_t& obj,
int64 milliseconds_timeout,
bool& lock_taken)
noexcept {
328 return try_enter_ptr(get_ptr(obj),
static_cast<int32>(milliseconds_timeout), lock_taken);
332 template<
typename type_t>
333 static bool try_enter(
const type_t* str,
int64 milliseconds_timeout,
bool& lock_taken) {
return try_enter(
string(str), milliseconds_timeout, lock_taken);}
341 template<
typename object_t>
343 auto lock_taken =
false;
344 return try_enter_ptr(get_ptr(obj),
timeout.total_milliseconds_duration().count(), lock_taken);
348 template<
typename type_t>
359 template<
typename object_t>
361 return try_enter_ptr(get_ptr(obj),
timeout.total_milliseconds_duration().count(), lock_taken);
378 template<
typename object_t>
379 static bool wait(
const object_t& obj,
int32 milliseconds_timeout) {
380 return wait_ptr(get_ptr(obj), milliseconds_timeout);
397 template<
typename object_t>
399 return wait_ptr(get_ptr(obj), as<int32>(
timeout.total_milliseconds()));
415 template<
typename object_t>
416 static bool wait(
const object_t& obj) {
417 return wait_ptr(get_ptr(obj), timeout::infinite);
422 template<
typename type_t>
423 static bool try_enter(
const type_t* str,
const time_span&
timeout,
bool& lock_taken) {
return try_enter(
string(str),
timeout, lock_taken);}
429 static static_data& get_static_data();
431 template<
typename object_t>
432 static object_ptr get_ptr(
const object_t& obj)
noexcept {
433 bool is_string = is<string>(obj);
435 return std::make_pair(is_string ? get_ustring_ptr(*(
new string(as<string>(obj)))) : reinterpret_cast<
intptr>(&obj), is_string);
438 template<
typename type_t>
439 static object_ptr get_ptr(
const type_t* str) {
return get_ptr(
string(str));}
441 static void enter_ptr(object_ptr obj);
442 static void enter_ptr(object_ptr obj,
bool& lock_taken);
443 static void exit_ptr(object_ptr obj);
444 static intptr get_ustring_ptr(
const string& str);
445 static bool is_entered_ptr(object_ptr obj)
noexcept;
446 static void pulse_ptr(object_ptr obj);
447 static void pulse_all_ptr(object_ptr obj);
448 static bool try_enter_ptr(object_ptr obj, int32 milliseconds_timeout,
bool& lock_taken)
noexcept;
449 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.h:32
Provides a mechanism that synchronizes access to objects.
Definition monitor.h:130
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.h:210
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.h:327
static bool try_enter(const object_t &obj) noexcept
Attempts to acquire an exclusive lock on the specified object.
Definition monitor.h:243
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.h:342
static void pulse_all(const object_t &obj)
Notifies all waiting threads of a change in the object's state.
Definition monitor.h:228
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.h:416
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.h:398
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.h:294
static void exit(const object_t &obj)
Releases an exclusive lock on the specified obj.
Definition monitor.h:176
static bool is_entered(const object_t &obj)
Determines whether the current thread holds the lock on the specified object.
Definition monitor.h:191
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.h:276
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.h:360
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.h:379
static void enter(const object_t &obj)
Acquires an exclusive lock on the specified obj.
Definition monitor.h:146
static void enter(const object_t &obj, bool &lock_taken)
Acquires an exclusive lock on the specified obj.
Definition monitor.h:162
static bool try_enter(const object_t &obj, bool &lock_taken) noexcept
Attempts to acquire an exclusive lock on the specified object.
Definition monitor.h:261
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.h:309
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.h:33
std::pair< key_t, value_t > key_value_pair
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.h:29
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.h:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.h:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Represents a time interval.
Definition time_span.h:29
Contains xtd::threading::timeout class.