29 virtual ~Win32JobserverClient() {
32 ::CloseHandle(handle_);
38 if (has_implicit_slot_) {
39 has_implicit_slot_ =
false;
43 DWORD ret = ::WaitForSingleObject(handle_, 0);
44 if (ret == WAIT_OBJECT_0) {
57 assert(!has_implicit_slot_ &&
"Implicit slot cannot be released twice!");
58 has_implicit_slot_ =
true;
63 (void)::ReleaseSemaphore(handle_, 1, NULL);
66 bool InitWithSemaphore(
const std::string& name, std::string* error) {
67 handle_ = ::OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE,
69 if (handle_ == NULL) {
70 *error =
"Error opening semaphore: " + GetLastErrorString();
77 bool IsValid()
const {
79 return handle_ != NULL;
83 bool has_implicit_slot_ =
true;
86 HANDLE handle_ = NULL;
96 std::unique_ptr<Win32JobserverClient>(
new Win32JobserverClient());
98 success = client->InitWithSemaphore(config.
path, error);
100 *error =
"Unsupported jobserver mode";
A Jobserver::Client instance models a client of an external GNU jobserver pool, which can be implemen...
virtual Slot TryAcquire()
Try to acquire a slot from the pool.
static std::unique_ptr< Client > Create(const Config &, std::string *error)
Create a new Client instance from a given configuration.
virtual void Release(Slot slot)
Release a slot to the pool.
A Jobserver::Config models how to access or implement a GNU jobserver implementation.
std::string path
For kModeFifo, this is the path to the Unix FIFO to use.
Mode mode
Implementation mode for the pool.
A Jobserver::Slot models a single job slot that can be acquired from.
static Slot CreateImplicit()
Create instance for the implicit value.
static Slot CreateExplicit(uint8_t value)
Create instance for explicit byte value.
bool IsImplicit() const
Return true if this instance represents an implicit job slot.
bool IsValid() const
Return true if this instance is valid, i.e.