Qore Programming Language: include/qore/QoreCounter.h (6585) Source File

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreCounter.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreCounter.h
4
5 Qore Programming Language
6
7 Copyright (C) 2005 - 2013 David Nichols
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _QORE_QORECOUNTER_H
25
26 #define _QORE_QORECOUNTER_H
27
28 #include <qore/Qore.h>
29 #include <qore/QoreCondition.h>
30
32 class QoreCounter {
33 private:
35 struct qore_counter_private* priv;
36
38 DLLLOCAL QoreCounter(const QoreCounter&);
39
41 DLLLOCAL QoreCounter& operator=(const QoreCounter&);
42
43 public:
45 DLLEXPORT QoreCounter(int nc = 0);
46
48 DLLEXPORT ~QoreCounter();
49
51 DLLEXPORT void destructor(ExceptionSink* xsink);
52
54 DLLEXPORT void inc();
55
57
61 DLLEXPORT void dec(ExceptionSink* xsink);
62
64
71 DLLEXPORT int waitForZero(ExceptionSink* xsink, int timeout_ms = 0);
72
74 DLLEXPORT int getCount() const;
75
77 DLLEXPORT int getWaiting() const;
78
79 // internal use only - for internal counters
80 DLLLOCAL void waitForZero();
81 DLLLOCAL void dec();
82 };
83
84 #endif
QoreCounter::getWaiting
DLLEXPORT int getWaiting() const
returns the number of threads blocked on this object
QoreCounter
a simple thread-safe counter object; objects can block on it until the counter reaches zero ...
Definition: QoreCounter.h:32
QoreCounter::inc
DLLEXPORT void inc()
increments the counter
QoreCounter::getCount
DLLEXPORT int getCount() const
returns the current count
QoreCounter::~QoreCounter
DLLEXPORT ~QoreCounter()
destroys the object and frees all memory
QoreCounter::dec
DLLEXPORT void dec(ExceptionSink *xsink)
decrements the counter and wakes up any threads if the counter reaches 0
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
Qore.h
QoreCounter::destructor
DLLEXPORT void destructor(ExceptionSink *xsink)
throws a Qore-language exception if there are any waiting threads and wakes them all up ...
QoreCounter::waitForZero
DLLEXPORT int waitForZero(ExceptionSink *xsink, int timeout_ms=0)
blocks the calling thread until the counter reaches 0