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 auto enter(
const object_t& obj) ->
void {
146 auto lock_taken =
false;
147 enter_ptr(get_ptr(obj), lock_taken);
151 template<
class type_t>
152 static auto enter(
const type_t* str) ->
void {
enter(
string(str));}
160 template<
class object_t>
161 static auto enter(
const object_t& obj,
bool& lock_taken) ->
void {enter_ptr(get_ptr(obj), lock_taken);}
164 template<
class type_t>
165 static auto enter(
const type_t* str,
bool& lock_taken) ->
void {
enter(
string(str), lock_taken);}
172 template<
class object_t>
173 static auto exit(
const object_t& obj) ->
void {exit_ptr(get_ptr(obj));}
176 template<
class type_t>
177 static auto exit(
const type_t* str) ->
void {exit(
string(str));}
185 template<
class object_t>
186 static auto is_entered(
const object_t& obj) ->
bool {
return is_entered_ptr(get_ptr(obj));}
189 template<
class type_t>
190 static auto is_entered(
const type_t* str) ->
bool {
return is_entered(
string(str));}
202 template<
class object_t>
203 static auto pulse(
const object_t& obj) ->
void {pulse_ptr(get_ptr(obj));}
206 template<
class type_t>
207 static auto pulse(
const type_t* str) ->
void {pulse(
string(str));}
218 template<
class object_t>
219 static auto pulse_all(
const object_t& obj) ->
void {pulse_all_ptr(get_ptr(obj));}
222 template<
class type_t>
223 static auto pulse_all(
const type_t* str) ->
void {pulse_all(
string(str));}
231 template<
class object_t>
232 static auto try_enter(
const object_t& obj)
noexcept ->
bool {
233 auto lock_taken =
false;
238 template<
class type_t>
239 static auto try_enter(
const type_t* str) ->
bool {
return try_enter(
string(str));}
249 template<
class object_t>
250 [[nodiscard]]
static auto try_enter(
const object_t& obj,
bool& lock_taken)
noexcept ->
bool {
return try_enter_ptr(get_ptr(obj),
timeout::infinite, lock_taken);}
253 template<
class type_t>
254 [[nodiscard]]
static auto try_enter(
const type_t* str,
bool& lock_taken) ->
bool {
return try_enter(
string(str), lock_taken);}
262 template<
class object_t>
263 [[nodiscard]]
static auto try_enter(
const object_t& obj,
int32 milliseconds_timeout)
noexcept ->
bool {
264 auto lock_taken =
false;
265 return try_enter_ptr(get_ptr(obj), milliseconds_timeout, lock_taken);
269 template<
class type_t>
270 [[nodiscard]]
static auto try_enter(
const type_t* str,
int32 milliseconds_timeout) ->
bool {
return try_enter(
string(str), milliseconds_timeout);}
280 template<
class object_t>
281 [[nodiscard]]
static auto try_enter(
const object_t& obj,
int32 milliseconds_timeout,
bool& lock_taken)
noexcept ->
bool {
return try_enter_ptr(get_ptr(obj), milliseconds_timeout, lock_taken);}
284 template<
class type_t>
285 [[nodiscard]]
static auto try_enter(
const type_t* str,
int32 milliseconds_timeout,
bool& lock_taken) ->
bool {
return try_enter(
string(str), milliseconds_timeout, lock_taken);}
293 template<
class object_t>
294 [[nodiscard]]
static auto try_enter(
const object_t& obj,
int64 milliseconds_timeout)
noexcept ->
bool {
295 auto lock_taken =
false;
296 return try_enter_ptr(get_ptr(obj),
static_cast<int32>(milliseconds_timeout), lock_taken);
300 template<
class type_t>
301 [[nodiscard]]
static auto try_enter(
const type_t* str,
int64 milliseconds_timeout) ->
bool {
return try_enter(
string(str), milliseconds_timeout);}
311 template<
class object_t>
312 [[nodiscard]]
static auto try_enter(
const object_t& obj,
int64 milliseconds_timeout,
bool& lock_taken)
noexcept ->
bool {
return try_enter_ptr(get_ptr(obj),
static_cast<int32>(milliseconds_timeout), lock_taken);}
315 template<
class type_t>
316 [[nodiscard]]
static bool try_enter(
const type_t* str,
int64 milliseconds_timeout,
bool& lock_taken) {
return try_enter(
string(str), milliseconds_timeout, lock_taken);}
324 template<
class object_t>
326 auto lock_taken =
false;
327 return try_enter_ptr(get_ptr(obj),
timeout.total_milliseconds_duration().count(), lock_taken);
331 template<
class type_t>
332 [[nodiscard]]
static auto try_enter(
const type_t* str,
const time_span&
timeout) ->
bool {
return try_enter(
string(str),
timeout);}
342 template<
class object_t>
343 [[nodiscard]]
static auto try_enter(
const object_t& obj,
const time_span&
timeout,
bool& lock_taken)
noexcept ->
bool {
return try_enter_ptr(get_ptr(obj),
timeout.total_milliseconds_duration().count(), lock_taken);}
359 template<
class object_t>
360 static auto wait(
const object_t& obj,
int32 milliseconds_timeout) ->
bool {
return wait_ptr(get_ptr(obj), milliseconds_timeout);}
376 template<
class object_t>
392 template<
class object_t>
397 template<
class type_t>
398 [[nodiscard]]
static auto try_enter(
const type_t* str,
const time_span&
timeout,
bool& lock_taken) ->
bool {
return try_enter(
string(str),
timeout, lock_taken);}
404 static auto get_static_data() -> static_data&;
406 template<
class object_t>
407 [[nodiscard]]
static auto get_ptr(
const object_t& obj)
noexcept -> object_ptr {
410 return std::make_pair(is_string ? get_string_ptr(*(
new string(
as<string>(obj)))) :
reinterpret_cast<intptr>(&obj), is_string);
413 template<
class type_t>
414 [[nodiscard]]
static auto get_ptr(
const type_t* str) -> object_ptr {
return get_ptr(
string(str));}
416 static auto enter_ptr(object_ptr obj) -> void;
417 static auto enter_ptr(object_ptr obj,
bool& lock_taken) -> void;
418 static auto exit_ptr(object_ptr obj) -> void;
419 [[nodiscard]]
static auto get_string_ptr(
const string& str) ->
intptr;
420 static auto is_entered_ptr(object_ptr obj)
noexcept -> bool;
421 static auto pulse_ptr(object_ptr obj) -> void;
422 static auto pulse_all_ptr(object_ptr obj) -> void;
423 static auto try_enter_ptr(object_ptr obj, int32 milliseconds_timeout,
bool& lock_taken)
noexcept -> bool;
424 static auto wait_ptr(object_ptr obj, int32 milliseconds_timeout) -> bool;
Provides a mechanism that synchronizes access to objects with xtd::threading::monitor.
Definition lock.hpp:32
Provides a mechanism that synchronizes access to objects.
Definition monitor.hpp:129
static auto try_enter(const object_t &obj, int64 milliseconds_timeout, bool &lock_taken) noexcept -> bool
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:312
static auto enter(const object_t &obj, bool &lock_taken) -> void
Acquires an exclusive lock on the specified obj.
Definition monitor.hpp:161
static auto is_entered(const object_t &obj) -> bool
Determines whether the current thread holds the lock on the specified object.
Definition monitor.hpp:186
static auto enter(const object_t &obj) -> void
Acquires an exclusive lock on the specified obj.
Definition monitor.hpp:145
static auto exit(const object_t &obj) -> void
Releases an exclusive lock on the specified obj.
Definition monitor.hpp:173
static auto try_enter(const object_t &obj, const time_span &timeout, bool &lock_taken) noexcept -> bool
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.
Definition monitor.hpp:343
static auto try_enter(const object_t &obj, int32 milliseconds_timeout) noexcept -> bool
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:263
static auto try_enter(const object_t &obj, bool &lock_taken) noexcept -> bool
Attempts to acquire an exclusive lock on the specified object.
Definition monitor.hpp:250
static auto try_enter(const object_t &obj, const time_span &timeout) noexcept -> bool
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object.
Definition monitor.hpp:325
static auto try_enter(const object_t &obj) noexcept -> bool
Attempts to acquire an exclusive lock on the specified object.
Definition monitor.hpp:232
static auto pulse(const object_t &obj) -> void
Notifies a thread in the waiting queue of a change in the locked object's state.
Definition monitor.hpp:203
static auto wait(const object_t &obj) -> bool
Releases the lock on an object and blocks the current thread until it reacquires the lock.
Definition monitor.hpp:393
static auto pulse_all(const object_t &obj) -> void
Notifies all waiting threads of a change in the object's state.
Definition monitor.hpp:219
static auto try_enter(const object_t &obj, int32 milliseconds_timeout, bool &lock_taken) noexcept -> bool
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:281
static auto try_enter(const object_t &obj, int64 milliseconds_timeout) noexcept -> bool
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified obj...
Definition monitor.hpp:294
static auto wait(const object_t &obj, int32 milliseconds_timeout) -> bool
Releases the lock on an object and blocks the current thread until it reacquires the lock....
Definition monitor.hpp:360
static auto wait(const object_t &obj, const time_span &timeout) -> bool
Releases the lock on an object and blocks the current thread until it reacquires the lock....
Definition monitor.hpp:377
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.hpp:33
static constexpr int32 infinite
A constant used to specify an infinite waiting period. This field is constant.
Definition timeout.hpp:41
Represents a time interval.
Definition time_span.hpp:29
Contains core_export_ keyword.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
std::intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
auto as(any_object &o) -> type_t
Casts a type into another type.
Definition __as_any_object.hpp:60
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:484
@ enter
The ENTER key.
Definition console_key.hpp:28
Contains xtd::invalid_operation_exception exception.
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::diagnostics::stack_frame class.
Contains xtd::static_object class.
Contains xtd::time_span class.
Contains xtd::threading::timeout class.
Contains xtd fundamental types.