Qore Programming Language  0.8.7
 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