1 /* src/threads/posix/mutex-posix.h - POSIX mutual exclusion functions
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 _MUTEX_POSIX_H
27 #define _MUTEX_POSIX_H
36 /* POSIX mutex object *********************************************************/
38 typedef pthread_mutex_t mutex_t;
41 /* static mutex initializer ***************************************************/
43 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
46 /* inline functions ***********************************************************/
48 /* mutex_init ******************************************************************
50 Initializes the given mutex object and checks for errors.
53 mutex ... POSIX mutex object
55 *******************************************************************************/
57 inline static void mutex_init(mutex_t *mutex)
61 result = pthread_mutex_init(mutex, NULL);
64 vm_abort_errnum(result, "mutex_init: pthread_mutex_init failed");
68 /* mutex_lock ******************************************************************
70 Locks the given mutex object and checks for errors. If the mutex is
71 already locked by another thread, the calling thread is suspended until
72 the mutex is unlocked.
74 If the mutex is already locked by the calling thread, the same applies,
75 thus effectively causing the calling thread to deadlock. (This is because
76 we use "fast" pthread mutexes without error checking.)
79 mutex ... POSIX mutex object
81 *******************************************************************************/
83 inline static void mutex_lock(mutex_t *mutex)
87 result = pthread_mutex_lock(mutex);
90 vm_abort_errnum(result, "mutex_lock: pthread_mutex_lock failed");
94 /* mutex_unlock ****************************************************************
96 Unlocks the given mutex object and checks for errors. The mutex is
97 assumed to be locked and owned by the calling thread.
100 mutex ... POSIX mutex object
102 *******************************************************************************/
104 inline static void mutex_unlock(mutex_t *mutex)
108 result = pthread_mutex_unlock(mutex);
111 vm_abort_errnum(result, "mutex_unlock: pthread_mutex_unlock failed");
115 /* mutex_destroy ***************************************************************
117 Destroys the given mutex object and checks for errors.
120 mutex ... POSIX mutex object
122 *******************************************************************************/
124 inline static void mutex_destroy(mutex_t *mutex)
128 result = pthread_mutex_destroy(mutex);
131 vm_abort_errnum(result, "mutex_destroy: pthread_mutex_destroy failed");
135 #endif /* _MUTEX_POSIX_H */
139 * These are local overrides for various environment variables in Emacs.
140 * Please do not remove this and leave it at the end of the file, where
141 * Emacs will automagically detect them.
142 * ---------------------------------------------------------------------
145 * indent-tabs-mode: t
149 * vim:noexpandtab:sw=4:ts=4: