xtd 0.2.0
Loading...
Searching...
No Matches
semaphore.h
Go to the documentation of this file.
1
4#pragma once
6#include "wait_handle.h"
7#include "../icomparable.h"
8#include "../iequatable.h"
9#include "../int32_object.h"
10
12namespace xtd {
14 namespace threading {
36 class core_export_ semaphore : public wait_handle, public icomparable<semaphore>, public iequatable<semaphore> {
37 class semaphore_base;
38 class named_semaphore;
39 class unnamed_semaphore;
40 struct data;
41 public:
43
57 explicit semaphore(const ustring& name);
68 explicit semaphore(const ustring& name, bool& created_new);
74 explicit semaphore(int32 initial_count);
86 semaphore(int32 initial_count, const ustring& name);
99 semaphore(int32 initial_count, const ustring& name, bool& created_new);
107 semaphore(int32 initial_count, int32 maximum_count);
122 semaphore(int32 initial_count, int32 maximum_count, const ustring& name);
137 semaphore(int32 initial_count, int32 maximum_count, const ustring& name, bool& created_new);
139
141 template <typename char_t>
142 explicit semaphore(const char_t* name) : semaphore(ustring(name)) {}
143 ~semaphore();
145
147
149 intptr handle() const noexcept override;
150 void handle(intptr value) override;
152
154
156 void close() override;
157
158 int32 compare_to(const semaphore& value) const noexcept override;
159
160 bool equals(const semaphore& value) const noexcept override;
161
168 int32 release();
176 int32 release(int32 release_count);
178
180
190 static semaphore open_existing(const ustring& name);
191
199 static bool try_open_existing(const ustring& name, semaphore& result) noexcept;
201
202 protected:
204
206 bool signal() override;
207
208 bool wait(int32 milliseconds_timeout) override;
210
211 private:
212 void create(int32 initial_count, int32 maximum_count, bool& created_new);
213 std::shared_ptr<semaphore_base> semaphore_;
214 std::shared_ptr<data> data_;
215 };
216 }
217}
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.h:17
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:18
Limits the number of threads that can access a resource or pool of resources concurrently.
Definition semaphore.h:36
semaphore(int32 initial_count, const ustring &name)
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of en...
semaphore(int32 initial_count, int32 maximum_count, const ustring &name, bool &created_new)
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of en...
semaphore(int32 initial_count, int32 maximum_count)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
semaphore()
Initializes a new instance of the xtd::threading::semaphore class.
semaphore(const ustring &name)
nitializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying th...
intptr handle() const noexcept override
Gets the native operating system handle.
semaphore(const ustring &name, bool &created_new)
nitializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying th...
semaphore(int32 initial_count)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
semaphore(int32 initial_count, int32 maximum_count, const ustring &name)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
semaphore(int32 initial_count, const ustring &name, bool &created_new)
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of en...
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.h:50
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
#define core_export_
Define shared library export.
Definition core_export.h:13
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
intmax_t intptr
Represent a pointer or a handle.
Definition types.h:153
signal
Specifies signals that can interrupt the current process.
Definition signal.h:18
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::threading::semaphore_full_exception exception.
Contains xtd::threading::wait_handle exception.