Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
useCondVar.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
83#ifndef USECONDVAR_H
84#define USECONDVAR_H
85
86#include <pthread.h>
87
102{
103private:
104
105 pthread_cond_t *cond;
106 pthread_mutex_t *mutex;
107
108public:
109
122 UseCondVar(pthread_cond_t *c, pthread_mutex_t *m)
123 {
124 mutex = m;
125 cond = c;
126 }
127
135 int wait()
136 {
137 int retVal = pthread_cond_wait(cond, mutex);
138 return retVal;
139 }
140
147 int signal()
148 {
149 int retVal = pthread_cond_signal(cond);
150 return retVal;
151 }
152
160 {
161 int retVal = pthread_cond_broadcast(cond);
162 return retVal;
163 }
164
167 {
168 //nullptr;
169 }
170};
171#endif
172
Wrapper class for POSIX condition variables.
Definition useCondVar.H:102
int broadcast()
Wake all waiting threads.
Definition useCondVar.H:159
~UseCondVar()
Destructor (does not destroy the condition variable)
Definition useCondVar.H:166
int wait()
Wait for the condition variable to be signaled.
Definition useCondVar.H:135
int signal()
Signal one waiting thread.
Definition useCondVar.H:147
pthread_mutex_t * mutex
Definition useCondVar.H:106
pthread_cond_t * cond
Definition useCondVar.H:105
UseCondVar(pthread_cond_t *c, pthread_mutex_t *m)
Construct wrapper for condition variable and mutex.
Definition useCondVar.H:122