LLVM 22.0.0git
llvm::JobserverClient Class Referenceabstract

The public interface for a jobserver client. More...

#include "llvm/Support/Jobserver.h"

Inheritance diagram for llvm::JobserverClient:
[legend]

Public Member Functions

virtual ~JobserverClient ()
virtual JobSlot tryAcquire ()=0
 Tries to acquire a job slot from the pool.
virtual void release (JobSlot Slot)=0
 Releases a job slot back to the pool.
virtual unsigned getNumJobs () const =0
 Returns the number of job slots available, as determined on first use.

Static Public Member Functions

static JobserverClientgetInstance ()
 Returns the singleton instance of the JobserverClient.
static void resetForTesting ()
 Resets the singleton instance. For testing purposes only.

Detailed Description

The public interface for a jobserver client.

This client is a lazy-initialized singleton that is created on first use.

Definition at line 135 of file Jobserver.h.

Constructor & Destructor Documentation

◆ ~JobserverClient()

llvm::JobserverClient::~JobserverClient ( )
virtualdefault

Member Function Documentation

◆ getInstance()

JobserverClient * llvm::JobserverClient::getInstance ( )
static

Returns the singleton instance of the JobserverClient.

This is the main entry point for acquiring a jobserver client.

The instance is created on the first call to this function. Returns a nullptr if no jobserver is configured or an error occurs.

It uses a std::call_once to ensure the singleton GJobserver instance is created safely in a multi-threaded environment. On first call, it reads the MAKEFLAGS environment variable, parses it, and attempts to construct and initialize a JobserverClientImpl. If successful, the global instance is stored in GJobserver. Subsequent calls will return the existing instance.

Definition at line 200 of file Jobserver.cpp.

References llvm::dbgs(), llvm::errs(), LLVM_DEBUG, and llvm::toString().

◆ getNumJobs()

virtual unsigned llvm::JobserverClient::getNumJobs ( ) const
pure virtual

Returns the number of job slots available, as determined on first use.

This value is cached. Returns 0 if no jobserver is active.

Implemented in llvm::JobserverClientImpl.

◆ release()

virtual void llvm::JobserverClient::release ( JobSlot Slot)
pure virtual

Releases a job slot back to the pool.

Implemented in llvm::JobserverClientImpl.

◆ resetForTesting()

void llvm::JobserverClient::resetForTesting ( )
static

Resets the singleton instance. For testing purposes only.

For testing purposes only.

This function resets the singleton instance by destroying the existing client and re-initializing the std::once_flag. This allows tests to simulate the first-time initialization of the jobserver client multiple times.

Definition at line 253 of file Jobserver.cpp.

◆ tryAcquire()

virtual JobSlot llvm::JobserverClient::tryAcquire ( )
pure virtual

Tries to acquire a job slot from the pool.

On failure (e.g., if the pool is empty), this returns an invalid JobSlot instance. The first successful call will always return the implicit slot.

Implemented in llvm::JobserverClientImpl.


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