29 virtual ~Win32JobserverClient() {
32 ::CloseHandle(handle_);
36 Jobserver::Slot TryAcquire()
override {
38 if (has_implicit_slot_) {
39 has_implicit_slot_ =
false;
43 DWORD ret = ::WaitForSingleObject(handle_, 0);
44 if (ret == WAIT_OBJECT_0) {
49 return Jobserver::Slot();
52 void Release(Jobserver::Slot slot)
override {
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...
static std::unique_ptr< Client > Create(const Config &, std::string *error)
Create a new Client instance from a given configuration.
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.
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.