xtd 0.2.0
Loading...
Searching...
No Matches
mutex.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "wait_handle.hpp"
6#include "../date_time.hpp"
7#include "../icomparable.hpp"
8#include "../iequatable.hpp"
9
11namespace xtd {
13 namespace threading {
15 class thread;
17
50 class core_export_ mutex : public wait_handle, public icomparable<mutex>, public iequatable<mutex> {
51 class mutex_base;
52 class named_mutex;
53 class unnamed_mutex;
54 public:
56
61
63
70 explicit mutex(bool initially_owned);
75 explicit mutex(const string& name);
81 mutex(const string& name, bool& created_new);
86 mutex(bool initially_owned, const string& name);
92 mutex(bool initially_owned, const string& name, bool& created_new);
94
96 template <typename char_t>
97 explicit mutex(const char_t* name) : mutex(string(name)) {}
98 ~mutex();
100
102
104 intptr handle() const noexcept override;
105 void handle(intptr value) override;
106
109 native_handle_type native_handle() const noexcept;
111
113
115 void close() override;
116
117 int32 compare_to(const mutex& value) const noexcept override;
118
119 using object::equals;
120 bool equals(const mutex& value) const noexcept override;
121
126 void lock();
127
130 void release_mutex();
131
138 bool try_lock() noexcept;
139
149 bool try_lock_for(const time_span& timeout) noexcept;
150
160 bool try_lock_until(const date_time& timeout_time) noexcept;
161
166 void unlock();
168
170
177 static mutex open_existing(const string& name);
178
183 static bool try_open_existing(const string& name, mutex& result) noexcept;
185
186 protected:
188
190 bool signal() override;
191
192 bool wait(int32 milliseconds_timeout) override;
194
195 private:
196 friend class thread;
197 void create(bool initially_owned, bool& created_new);
198 xtd::sptr<mutex_base> mutex_;
199 string name_;
200 };
201 }
202}
Represents text as a sequence of character units.
Definition basic_string.hpp:79
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:85
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Provides a mechanism that synchronizes access to objects with xtd::threading::monitor.
Definition lock_guard.hpp:32
A synchronization primitive that can also be used for interprocess synchronization.
Definition mutex.hpp:50
mutex(const string &name, bool &created_new)
Initializes a new instance of the xtd::threading::mutex class with a string that is the name of the m...
mutex(bool initially_owned, const string &name)
Initializes a new instance of the xtd::threading::mutex class with a bool value that indicates whethe...
intptr native_handle_type
Rpresents the native handle type.
Definition mutex.hpp:59
mutex(bool initially_owned)
Initializes a new instance of the xtd::threading::mutex with a bool value that indicates whether the ...
intptr handle() const noexcept override
Gets the native operating system handle.
mutex()
Initializes a new instance of the xtd::threading::mutex class with default properties.
mutex(const string &name)
Initializes a new instance of the xtd::threading::mutex class with a string that is the name of the m...
mutex(bool initially_owned, const string &name, bool &created_new)
Initializes a new instance of the xtd::threading::mutex class with a bool value that indicates whethe...
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:43
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.hpp:33
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.hpp:52
#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
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
signal
Specifies signals that can interrupt the current process.
Definition signal.hpp:18
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Represents a time interval.
Definition time_span.hpp:29
Contains xtd::threading::wait_handle exception.