BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmt::TimedCompletionGuard Class Reference

#include <bslmt_timedcompletionguard.h>

Detailed Description

This class implements a guard for work completion within a specified duration.

See bslmt_timedcompletionguard

Public Types

typedef void(* Handler) (const char *)
 
typedef bsl::allocator allocator_type
 

Public Member Functions

 TimedCompletionGuard ()
 
 TimedCompletionGuard (const allocator_type &basicAllocator)
 
 TimedCompletionGuard (Handler function, const allocator_type &basicAllocator=allocator_type())
 
 ~TimedCompletionGuard ()
 
int guard (const bsls::TimeInterval &duration, const bsl::string_view &text)
 
void release ()
 
int updateText (const bsl::string_view &text)
 
allocator_type get_allocator () const
 
bool isGuarding () const
 

Static Public Member Functions

static BSLS_ANNOTATION_NORETURN void failByAbort (const char *text)
 

Member Typedef Documentation

◆ allocator_type

◆ Handler

typedef void(* bslmt::TimedCompletionGuard::Handler) (const char *)

Handler is an alias for a pointer to a function returning void, and taking, as a parameter, a null-terminated string, which is the structure of the handler function supported by this class – e.g.,

void myHandler(const char *text);

Constructor & Destructor Documentation

◆ TimedCompletionGuard() [1/3]

bslmt::TimedCompletionGuard::TimedCompletionGuard ( )
inline

Create the guard. Optionally specify a handler function that is invoked when a set duration expires. If handler is not specified, failByAbort is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used.

◆ TimedCompletionGuard() [2/3]

bslmt::TimedCompletionGuard::TimedCompletionGuard ( const allocator_type basicAllocator)
inlineexplicit

◆ TimedCompletionGuard() [3/3]

bslmt::TimedCompletionGuard::TimedCompletionGuard ( Handler  function,
const allocator_type basicAllocator = allocator_type() 
)
inline

◆ ~TimedCompletionGuard()

bslmt::TimedCompletionGuard::~TimedCompletionGuard ( )
inline

Invoke release and destroy this guard.

Member Function Documentation

◆ failByAbort()

static BSLS_ANNOTATION_NORETURN void bslmt::TimedCompletionGuard::failByAbort ( const char *  text)
static

(Default Handler) Emulate the invocation of the standard assert macro with a false argument, using the expression text to generate a helpful output message and then, after logging, unconditionally aborting.

Note
Note that this handler function is the default installed assertion handler.

◆ get_allocator()

TimedCompletionGuard::allocator_type bslmt::TimedCompletionGuard::get_allocator ( ) const
inline

Return the allocator used to supply memory.

◆ guard()

int bslmt::TimedCompletionGuard::guard ( const bsls::TimeInterval duration,
const bsl::string_view text 
)

Configure a thread to, at the expiration of the specified duration, invoke the handler assigned at object creation with the specified text, unless the release method is invoked or this guard is rescheduled with a subsequent call to guard. Return 0 on success, and a non-zero value if a thread is not available and could not be created.

Precondition
The behavior is undefined unless duration is a positive value.

◆ isGuarding()

bool bslmt::TimedCompletionGuard::isGuarding ( ) const
inline

Return true if this guard is currently configured with a duration to guard, and false otherwise.

◆ release()

void bslmt::TimedCompletionGuard::release ( )

If a thread is waiting to alert at expiration of the set duration, join the thread, thus preventing any alerting.

◆ updateText()

int bslmt::TimedCompletionGuard::updateText ( const bsl::string_view text)

Use the specified text for alerting when the current duration expires. Return 0 on success, and a non-zero value if false == isGuarding().


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