5#include "flutter/fml/synchronization/semaphore.h"
7#include "flutter/fml/build_config.h"
8#include "flutter/fml/logging.h"
11#include <dispatch/dispatch.h>
15class PlatformSemaphore {
18 : sem_(dispatch_semaphore_create(
count)), initial_(
count) {}
21 for (uint32_t
i = 0;
i < initial_; ++
i) {
24 if (sem_ !=
nullptr) {
25 dispatch_release(
reinterpret_cast<dispatch_object_t
>(sem_));
30 bool IsValid()
const {
return sem_ !=
nullptr; }
33 if (sem_ ==
nullptr) {
36 return dispatch_semaphore_wait(sem_, DISPATCH_TIME_FOREVER) == 0;
40 if (sem_ ==
nullptr) {
44 return dispatch_semaphore_wait(sem_, DISPATCH_TIME_NOW) == 0;
48 if (sem_ !=
nullptr) {
49 dispatch_semaphore_signal(sem_);
54 dispatch_semaphore_t sem_;
55 const uint32_t initial_;
67class PlatformSemaphore {
70 : _sem(CreateSemaphore(NULL,
count, LONG_MAX, NULL)) {}
73 if (_sem !=
nullptr) {
79 bool IsValid()
const {
return _sem !=
nullptr; }
82 if (_sem ==
nullptr) {
86 return WaitForSingleObject(_sem, INFINITE) == WAIT_OBJECT_0;
90 if (_sem ==
nullptr) {
94 return WaitForSingleObject(_sem, 0) == WAIT_OBJECT_0;
98 if (_sem !=
nullptr) {
99 ReleaseSemaphore(_sem, 1, NULL);
113#include "flutter/fml/eintr_wrapper.h"
120 : valid_(::sem_init(&sem_, 0 ,
count) == 0) {}
124 int result = ::sem_destroy(&sem_);
178 return impl_->IsValid();
182 return impl_->Wait();
186 return impl_->TryWait();
190 return impl_->Signal();
bool IsValid() const
Check if the underlying semaphore handle could be created. Failure modes are platform specific and ma...
~Semaphore()
Destroy the counting semaphore.
void Signal()
Increment the count by one. Any pending Waits will be resolved at this point.
bool TryWait()
Decrement the counts if it is greater than zero. Returns false if the counter is already at zero.
Semaphore(uint32_t count)
Initializes the counting semaphore to a specified start count.
bool Wait()
Decrements the count and waits indefinitely if the value is less than zero for a Signal.
#define FML_HANDLE_EINTR(x)
#define FML_DCHECK(condition)