1 /*****************************************************************************
2 * $Id: thread.h,v 1.1.10.2 2008/12/18 18:02:31 johann Exp $
3 *****************************************************************************
4 * Copyright (C) 2003 The Regents of the University of California.
5 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6 * Written by Chris Dunlap <cdunlap@llnl.gov>.
8 * This file is from LSD-Tools, the LLNL Software Development Toolbox.
10 * LSD-Tools is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
15 * LSD-Tools is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * You should have received a copy of the GNU General Public License along
21 * with LSD-Tools; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *****************************************************************************/
33 #endif /* WITH_PTHREADS */
36 /*****************************************************************************
38 *****************************************************************************/
42 # ifdef WITH_LSD_FATAL_ERROR_FUNC
43 # undef lsd_fatal_error
44 extern void lsd_fatal_error (char *file, int line, char *mesg);
45 # else /* !WITH_LSD_FATAL_ERROR_FUNC */
46 # ifndef lsd_fatal_error
47 # define lsd_fatal_error(file, line, mesg) (abort ())
48 # endif /* !lsd_fatal_error */
49 # endif /* !WITH_LSD_FATAL_ERROR_FUNC */
51 # define lsd_mutex_init(pmutex) \
53 int e = pthread_mutex_init (pmutex, NULL); \
56 lsd_fatal_error (__FILE__, __LINE__, "mutex_init"); \
61 # define lsd_mutex_lock(pmutex) \
63 int e = pthread_mutex_lock (pmutex); \
66 lsd_fatal_error (__FILE__, __LINE__, "mutex_lock"); \
71 # define lsd_mutex_unlock(pmutex) \
73 int e = pthread_mutex_unlock (pmutex); \
76 lsd_fatal_error (__FILE__, __LINE__, "mutex_unlock"); \
81 # define lsd_mutex_destroy(pmutex) \
83 int e = pthread_mutex_destroy (pmutex); \
86 lsd_fatal_error (__FILE__, __LINE__, "mutex_destroy"); \
92 int lsd_mutex_is_locked (pthread_mutex_t *pmutex);
95 #else /* !WITH_PTHREADS */
97 # define lsd_mutex_init(mutex)
98 # define lsd_mutex_lock(mutex)
99 # define lsd_mutex_unlock(mutex)
100 # define lsd_mutex_destroy(mutex)
101 # define lsd_mutex_is_locked(mutex) (1)
103 #endif /* !WITH_PTHREADS */
106 #endif /* !LSD_THREAD_H */