Ninja
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Jobserver::Client Class Reference

A Jobserver::Client instance models a client of an external GNU jobserver pool, which can be implemented as a Unix FIFO, or a Windows named semaphore. More...

#include <jobserver.h>

Public Member Functions

virtual void Release (Slot slot)
 Release a slot to the pool. More...
 
virtual Slot TryAcquire ()
 Try to acquire a slot from the pool. More...
 
virtual ~Client ()
 

Static Public Member Functions

static std::unique_ptr< ClientCreate (const Config &, std::string *error)
 Create a new Client instance from a given configuration. More...
 

Protected Member Functions

 Client ()=default
 

Detailed Description

A Jobserver::Client instance models a client of an external GNU jobserver pool, which can be implemented as a Unix FIFO, or a Windows named semaphore.

Usage is the following:

Definition at line 189 of file jobserver.h.

Constructor & Destructor Documentation

◆ ~Client()

virtual Jobserver::Client::~Client ( )
inlinevirtual

Definition at line 191 of file jobserver.h.

◆ Client()

Jobserver::Client::Client ( )
protecteddefault

Member Function Documentation

◆ Create()

std::unique_ptr< Jobserver::Client > Jobserver::Client::Create ( const Config config,
std::string *  error 
)
static

Create a new Client instance from a given configuration.

On failure, this returns null after setting |*error|. Note that it is an error to call this function with |config.HasMode() == false|.

Definition at line 119 of file jobserver-posix.cc.

References Jobserver::Config::kModePosixFifo, Jobserver::Config::mode, and Jobserver::Config::path.

Referenced by TEST().

◆ Release()

virtual void Jobserver::Client::Release ( Slot  slot)
inlinevirtual

Release a slot to the pool.

Does nothing if slot is invalid, or if writing to the pool fails (and if this is not the implicit slot). If the pool is destroyed before Ninja, then only the implicit slot can be acquired in the next calls (if it was released). This simply enforces serialization of all commands, instead of blocking.

Definition at line 208 of file jobserver.h.

Referenced by RealCommandRunner::ClearJobTokens().

◆ TryAcquire()

virtual Slot Jobserver::Client::TryAcquire ( )
inlinevirtual

Try to acquire a slot from the pool.

On failure, i.e. if no slot can be acquired, this returns an invalid Token instance.

Note that this will always return the implicit slot value the first time this is called, without reading anything from the pool, as specified by the protocol. This implicit value must be released just like any other one. In general, users of this class should not care about this detail, except unit-tests.

Definition at line 201 of file jobserver.h.


The documentation for this class was generated from the following files: