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
38 * POSIX condition variable.
42 // POSIX condition structure.
51 void timedwait(Mutex* mutex, const struct timespec* abstime);
52 void wait(Mutex* mutex);
53 void wait(Mutex& mutex);
66 * Initialize a POSIX condition variable.
68 inline Condition::Condition()
70 int result = pthread_cond_init(&_cond, NULL);
73 os::abort_errnum(result, "Condition::Condition(): pthread_cond_init failed");
79 * Destroys a POSIX condition variable.
81 inline Condition::~Condition()
83 // Restart all threads waiting on this condition.
86 int result = pthread_cond_destroy(&_cond);
89 os::abort_errnum(result, "Condition::~Condition(): pthread_cond_destroy failed");
95 * Restarts all the threads that are waiting on the condition
98 inline void Condition::broadcast()
100 int result = pthread_cond_broadcast(&_cond);
103 os::abort_errnum(result, "Condition::broadcast(): pthread_cond_broadcast failed");
109 * Restarts one of the threads that are waiting on this condition
112 inline void Condition::signal()
114 int result = pthread_cond_signal(&_cond);
117 os::abort_errnum(result, "Condition::signal(): pthread_cond_signal failed");
123 * Waits on the condition variable, as wait() does, but it also bounds
124 * the duration of the wait.
126 inline void Condition::timedwait(Mutex* mutex, const struct timespec* abstime)
128 // This function can return return values which are valid.
129 (void) pthread_cond_timedwait(&_cond, &(mutex->_mutex), abstime);
134 * Waits for the condition variable.
136 inline void Condition::wait(Mutex* mutex)
143 * Waits for the condition variable.
145 inline void Condition::wait(Mutex& mutex)
147 int result = pthread_cond_wait(&_cond, &(mutex._mutex));
150 os::abort_errnum(result, "Condition::wait(): pthread_cond_wait failed");
156 // This structure must have the same layout as the class above.
157 typedef struct Condition {
158 pthread_mutex_t _mutex;
159 pthread_cond_t _cond;
162 Condition* Condition_new();
163 void Condition_delete(Condition* cond);
164 void Condition_lock(Condition* cond);
165 void Condition_unlock(Condition* cond);
166 void Condition_broadcast(Condition* cond);
167 void Condition_signal(Condition* cond);
168 void Condition_timedwait(Condition* cond, Mutex *mutex, const struct timespec* abstime);
169 void Condition_wait(Condition* cond, Mutex* mutex);
173 #endif /* _CONDITION_POSIX_HPP */
177 * These are local overrides for various environment variables in Emacs.
178 * Please do not remove this and leave it at the end of the file, where
179 * Emacs will automagically detect them.
180 * ---------------------------------------------------------------------
183 * indent-tabs-mode: t
187 * vim:noexpandtab:sw=4:ts=4: