1 /* src/threads/posix/condition-posix.hpp - POSIX condition variable
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #ifndef _CONDITION_POSIX_HPP
27 #define _CONDITION_POSIX_HPP
39 * POSIX condition variable.
43 // POSIX condition structure.
52 void timedwait(Mutex* mutex, const struct timespec* abstime);
53 void wait(Mutex* mutex);
58 * Initialize a POSIX condition variable.
60 inline Condition::Condition()
64 result = pthread_cond_init(&_cond, NULL);
67 VM::get_current()->abort_errnum(result, "Condition::Condition(): pthread_cond_init failed");
73 * Destroys a POSIX condition variable.
75 inline Condition::~Condition()
79 result = pthread_cond_destroy(&_cond);
82 VM::get_current()->abort_errnum(result, "Condition::~Condition(): pthread_cond_destroy failed");
88 * Restarts all the threads that are waiting on the condition
91 inline void Condition::broadcast()
95 result = pthread_cond_broadcast(&_cond);
98 VM::get_current()->abort_errnum(result, "Condition::broadcast(): pthread_cond_broadcast failed");
104 * Restarts one of the threads that are waiting on this condition
107 inline void Condition::signal()
111 result = pthread_cond_signal(&_cond);
114 VM::get_current()->abort_errnum(result, "Condition::signal(): pthread_cond_signal failed");
120 * Waits on the condition variable, as wait() does, but it also bounds
121 * the duration of the wait.
123 inline void Condition::timedwait(Mutex* mutex, const struct timespec* abstime)
125 // This function can return return values which are valid.
126 (void) pthread_cond_timedwait(&_cond, &(mutex->_mutex), abstime);
131 * Waits for the condition variable.
133 inline void Condition::wait(Mutex* mutex)
137 result = pthread_cond_wait(&_cond, &(mutex->_mutex));
140 VM::get_current()->abort_errnum(result, "Condition::wait(): pthread_cond_wait failed");
146 // This structure must have the same layout as the class above.
147 typedef struct Condition {
148 pthread_mutex_t _mutex;
149 pthread_cond_t _cond;
152 Condition* Condition_new();
153 void Condition_delete(Condition* cond);
154 void Condition_lock(Condition* cond);
155 void Condition_unlock(Condition* cond);
156 void Condition_broadcast(Condition* cond);
157 void Condition_signal(Condition* cond);
158 void Condition_timedwait(Condition* cond, Mutex *mutex, const struct timespec* abstime);
159 void Condition_wait(Condition* cond, Mutex* mutex);
163 #endif /* _CONDITION_POSIX_HPP */
167 * These are local overrides for various environment variables in Emacs.
168 * Please do not remove this and leave it at the end of the file, where
169 * Emacs will automagically detect them.
170 * ---------------------------------------------------------------------
173 * indent-tabs-mode: t
177 * vim:noexpandtab:sw=4:ts=4: