Qore Programming Language 1.19.5
Loading...
Searching...
No Matches
QoreCounter Class Reference

a simple thread-safe counter object; objects can block on it until the counter reaches zero More...

#include <QoreCounter.h>

Inheritance diagram for QoreCounter:
[legend]

Public Member Methods

DLLEXPORT QoreCounter (int nc=0)
 creates the counter and initializes the count
 
DLLEXPORT ~QoreCounter ()
 destroys the object and frees all memory
 
DLLEXPORT int dec (ExceptionSink *xsink)
 decrements the counter and wakes up any threads if the counter reaches 0 More...
 
DLLEXPORT void destructor (ExceptionSink *xsink)
 throws a Qore-language exception if there are any waiting threads and wakes them all up
 
DLLEXPORT int getCount () const
 returns the current count
 
DLLEXPORT int getWaiting () const
 returns the number of threads blocked on this object
 
DLLEXPORT int inc ()
 increments the counter More...
 
DLLEXPORT int waitForZero (ExceptionSink *xsink, int timeout_ms=0)
 blocks the calling thread until the counter reaches 0 More...
 

Detailed Description

a simple thread-safe counter object; objects can block on it until the counter reaches zero

Member Function Documentation

◆ dec()

DLLEXPORT int QoreCounter::dec ( ExceptionSink xsink)

decrements the counter and wakes up any threads if the counter reaches 0

a Qore-language exception will be raised here if QoreCounter::destructor() has already been run before calling this function.

Parameters
xsinkany Qore-language exception thrown will be added here
Returns
the current value after the decrement
Since
Qore 0.8.13 the current value is returned

Referenced by getWaiting().

◆ inc()

DLLEXPORT int QoreCounter::inc ( )

increments the counter

Returns
the current value after the increment
Since
Qore 0.9 the current value is returned

◆ waitForZero()

DLLEXPORT int QoreCounter::waitForZero ( ExceptionSink xsink,
int  timeout_ms = 0 
)

blocks the calling thread until the counter reaches 0

a Qore-language exception will be raised here if QoreCounter::destructor() is run while threads are still blocked

Parameters
xsinkany Qore-language exception thrown will be added here
timeout_msindicates a timeout in milliseconds to wait, 0 means no timeout
Returns
non-zero means an exception was thrown

Referenced by getWaiting().


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