xtd 1.0.0
Loading...
Searching...
No Matches
semaphore.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "wait_handle.hpp"
6#include "../icomparable.hpp"
7#include "../iequatable.hpp"
8#include "../int32_object.hpp"
9
11namespace xtd {
13 namespace threading {
37 class core_export_ semaphore : public wait_handle, public icomparable<semaphore>, public iequatable<semaphore> {
38 class semaphore_base;
39 class named_semaphore;
40 class unnamed_semaphore;
41 struct data;
42 public:
44
58 explicit semaphore(const string& name);
69 explicit semaphore(const string& name, bool& created_new);
75 explicit semaphore(int32 initial_count);
87 semaphore(int32 initial_count, const string& name);
100 semaphore(int32 initial_count, const string& name, bool& created_new);
108 semaphore(int32 initial_count, int32 maximum_count);
123 semaphore(int32 initial_count, int32 maximum_count, const string& name);
138 semaphore(int32 initial_count, int32 maximum_count, const string& name, bool& created_new);
140
142 template<typename char_t>
143 explicit semaphore(const char_t* name) : semaphore(string(name)) {}
144 ~semaphore();
146
148
150 [[nodiscard]] auto handle() const noexcept -> intptr override;
151 auto handle(intptr value) -> void override;
153
155
157 auto close() -> void override;
158
159 [[nodiscard]] auto compare_to(const semaphore& value) const noexcept -> int32 override;
160
164 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override;
168 [[nodiscard]] auto equals(const semaphore& other) const noexcept -> bool override;
169
176 auto release() -> int32;
184 auto release(int32 release_count) -> int32;
186
188
198 [[nodiscard]] static auto open_existing(const string& name) -> semaphore;
199
207 [[nodiscard]] static auto try_open_existing(const string& name, semaphore& result) noexcept -> bool;
209
210 protected:
212
214 auto signal() -> bool override;
215
216 auto wait(int32 milliseconds_timeout) -> bool override;
218
219 private:
220 auto create(int32 initial_count, int32 maximum_count, bool& created_new) -> void;
221 xtd::sptr<semaphore_base> semaphore_;
222 xtd::sptr<data> data_;
223 };
224 }
225}
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:22
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Limits the number of threads that can access a resource or pool of resources concurrently.
Definition semaphore.hpp:37
semaphore(const string &name, bool &created_new)
Initializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying t...
auto wait(int32 milliseconds_timeout) -> bool override
wait ownership of the specified mutex object.
semaphore(int32 initial_count, const string &name, bool &created_new)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
semaphore(int32 initial_count, int32 maximum_count, const string &name, bool &created_new)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
semaphore(int32 initial_count, int32 maximum_count, const string &name)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
auto handle() const noexcept -> intptr override
Gets the native operating system handle.
semaphore(int32 initial_count, int32 maximum_count)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
auto signal() -> bool override
Releases ownership of the specified wait_handle object.
semaphore(const string &name)
Initializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying t...
semaphore()
Initializes a new instance of the xtd::threading::semaphore class.
semaphore(int32 initial_count, const string &name)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
static auto open_existing(const string &name) -> semaphore
Opens the specified named semaphore, if it already exists.
semaphore(int32 initial_count)
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of e...
static auto try_open_existing(const string &name, semaphore &result) noexcept -> bool
Opens the specified named semaphore, if it already exists, and returns a value that indicates whether...
auto release() -> int32
Exits the semaphore and returns the previous count.
auto close() -> void override
Releases all resources held by the current xtd::threading::wait_handle.
wait_handle()=default
Initializes a new instance of the xtd::threading::wait_handle class.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
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:25
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Contains xtd::int32_object alias.
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
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:197
Contains xtd::threading::wait_handle class.