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_abort_errnum(result, "Condition::Condition(): pthread_cond_init failed");
72 * Destroys a POSIX condition variable.
74 inline Condition::~Condition()
78 result = pthread_cond_destroy(&_cond);
81 vm_abort_errnum(result, "Condition::~Condition(): pthread_cond_destroy failed");
86 * Restarts all the threads that are waiting on the condition
89 inline void Condition::broadcast()
93 result = pthread_cond_broadcast(&_cond);
96 vm_abort_errnum(result, "Condition::broadcast(): pthread_cond_broadcast failed");
101 * Restarts one of the threads that are waiting on this condition
104 inline void Condition::signal()
108 result = pthread_cond_signal(&_cond);
111 vm_abort_errnum(result, "Condition::signal(): pthread_cond_signal failed");
116 * Waits on the condition variable, as wait() does, but it also bounds
117 * the duration of the wait.
119 inline void Condition::timedwait(Mutex* mutex, const struct timespec* abstime)
121 // This function can return return values which are valid.
122 (void) pthread_cond_timedwait(&_cond, &(mutex->_mutex), abstime);
127 * Waits for the condition variable.
129 inline void Condition::wait(Mutex* mutex)
133 result = pthread_cond_wait(&_cond, &(mutex->_mutex));
136 vm_abort_errnum(result, "Condition::wait(): pthread_cond_wait failed");
141 // This structure must have the same layout as the class above.
142 typedef struct Condition {
143 pthread_mutex_t _mutex;
144 pthread_cond_t _cond;
147 Condition* Condition_new();
148 void Condition_delete(Condition* cond);
149 void Condition_lock(Condition* cond);
150 void Condition_unlock(Condition* cond);
151 void Condition_broadcast(Condition* cond);
152 void Condition_signal(Condition* cond);
153 void Condition_timedwait(Condition* cond, Mutex *mutex, const struct timespec* abstime);
154 void Condition_wait(Condition* cond, Mutex* mutex);
158 #endif /* _CONDITION_POSIX_HPP */
162 * These are local overrides for various environment variables in Emacs.
163 * Please do not remove this and leave it at the end of the file, where
164 * Emacs will automagically detect them.
165 * ---------------------------------------------------------------------
168 * indent-tabs-mode: t
172 * vim:noexpandtab:sw=4:ts=4: