Loading...
Searching...
No Matches
QoreCondition.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreCondition.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_QORECONDITION_H
#define _QORE_QORECONDITION_H
#include <pthread.h>
#include <sys/time.h>
#include <qore/QoreThreadLock.h>
class QoreCondition {
public:
DLLEXPORT QoreCondition();
DLLEXPORT ~QoreCondition();
DLLEXPORT int signal();
DLLEXPORT int broadcast();
DLLEXPORT int wait(pthread_mutex_t* m);
DLLEXPORT int wait(pthread_mutex_t* m, int timeout_ms);
DLLEXPORT int wait2(pthread_mutex_t* m, int64 timeout_ms);
DLLLOCAL int wait(QoreThreadLock* l) {
return wait(&l->ptm_lock);
}
DLLLOCAL int wait(QoreThreadLock* l, int timeout_ms) {
return wait(&l->ptm_lock, timeout_ms);
}
DLLLOCAL int wait2(QoreThreadLock* l, int64 timeout_ms) {
return wait2(&l->ptm_lock, timeout_ms);
}
DLLLOCAL int wait(QoreThreadLock& l) {
return wait(&l);
}
DLLLOCAL int wait(QoreThreadLock& l, int timeout_ms) {
return wait(&l, timeout_ms);
}
DLLLOCAL int wait2(QoreThreadLock& l, int64 timeout_ms) {
return wait2(&l, timeout_ms);
}
private:
pthread_cond_t c;
DLLLOCAL QoreCondition(const QoreCondition&);
DLLLOCAL QoreCondition& operator=(const QoreCondition&);
};
#endif // QORE_CONDITION
QoreCondition
a thread condition class implementing a wrapper for pthread_cond_t
Definition: QoreCondition.h:45
QoreCondition::~QoreCondition
DLLEXPORT ~QoreCondition()
destroys the condition object
QoreCondition::wait
DLLLOCAL int wait(QoreThreadLock &l, int timeout_ms)
blocks a thread on a lock for a certain number of milliseconds until the condition is signaled
Definition: QoreCondition.h:140
QoreCondition::wait2
DLLLOCAL int wait2(QoreThreadLock &l, int64 timeout_ms)
blocks a thread on a lock for a certain number of milliseconds until the condition is signaled
Definition: QoreCondition.h:151
QoreCondition::wait
DLLEXPORT int wait(pthread_mutex_t *m)
blocks a thread on a mutex until the condition is signaled
QoreCondition::wait2
DLLEXPORT int wait2(pthread_mutex_t *m, int64 timeout_ms)
blocks a thread on a mutex for a certain number of milliseconds until the condition is signaled
QoreCondition::wait
DLLLOCAL int wait(QoreThreadLock *l, int timeout_ms)
blocks a thread on a lock for a certain number of milliseconds until the condition is signaled
Definition: QoreCondition.h:106
QoreCondition::signal
DLLEXPORT int signal()
signals a single waiting thread to wake up
QoreCondition::wait
DLLLOCAL int wait(QoreThreadLock *l)
blocks a thread on a lock until the condition is signaled
Definition: QoreCondition.h:93
QoreCondition::wait
DLLLOCAL int wait(QoreThreadLock &l)
blocks a thread on a lock until the condition is signaled
Definition: QoreCondition.h:127
QoreCondition::wait
DLLEXPORT int wait(pthread_mutex_t *m, int timeout_ms)
blocks a thread on a mutex for a certain number of milliseconds until the condition is signaled
QoreCondition::wait2
DLLLOCAL int wait2(QoreThreadLock *l, int64 timeout_ms)
blocks a thread on a lock for a certain number of milliseconds until the condition is signaled
Definition: QoreCondition.h:117
QoreCondition::broadcast
DLLEXPORT int broadcast()
singles all threads blocked on this condition to wake up
QoreCondition::QoreCondition
DLLEXPORT QoreCondition()
creates the condition object
QoreThreadLock
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260