Loading...
Searching...
No Matches
QoreCounter.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreCounter.h
Qore Programming Language
Copyright (C) 2005 - 2022 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORECOUNTER_H
#define _QORE_QORECOUNTER_H
#include <qore/Qore.h>
#include <qore/QoreCondition.h>
class QoreCounter {
private:
struct qore_counter_private* priv;
DLLLOCAL QoreCounter(const QoreCounter&);
DLLLOCAL QoreCounter& operator=(const QoreCounter&);
public:
DLLEXPORT QoreCounter(int nc = 0);
DLLEXPORT ~QoreCounter();
DLLEXPORT void destructor(ExceptionSink* xsink);
DLLEXPORT int inc();
DLLEXPORT int dec(ExceptionSink* xsink);
DLLEXPORT int waitForZero(ExceptionSink* xsink, int timeout_ms = 0);
DLLEXPORT int getCount() const;
DLLEXPORT int getWaiting() const;
// internal use only - for internal counters
DLLLOCAL void waitForZero();
DLLLOCAL void dec();
};
#endif
Qore.h
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreCounter
a simple thread-safe counter object; objects can block on it until the counter reaches zero
Definition: QoreCounter.h:40
QoreCounter::~QoreCounter
DLLEXPORT ~QoreCounter()
destroys the object and frees all memory
QoreCounter::dec
DLLEXPORT int dec(ExceptionSink *xsink)
decrements the counter and wakes up any threads if the counter reaches 0
QoreCounter::destructor
DLLEXPORT void destructor(ExceptionSink *xsink)
throws a Qore-language exception if there are any waiting threads and wakes them all up
QoreCounter::getCount
DLLEXPORT int getCount() const
returns the current count
QoreCounter::getWaiting
DLLEXPORT int getWaiting() const
returns the number of threads blocked on this object
QoreCounter::inc
DLLEXPORT int inc()
increments the counter
QoreCounter::waitForZero
DLLEXPORT int waitForZero(ExceptionSink *xsink, int timeout_ms=0)
blocks the calling thread until the counter reaches 0
QoreCounter::QoreCounter
DLLEXPORT QoreCounter(int nc=0)
creates the counter and initializes the count