1 /* 2 * mutexes for libaudio 3 * 4 * Jon Trulson, 11/25/2001 5 * 6 * $Id: mutex.h 87 2002-02-24 04:39:08Z jon $ 7 * 8 */ 9 10 /* 11 Permission to use, copy, modify, distribute, and sell this software and its 12 documentation for any purpose is hereby granted without fee, provided that 13 the above copyright notice appear in all copies and that both that 14 copyright notice and this permission notice appear in supporting 15 documentation, and that the name of M.I.T. not be used in advertising or 16 publicity pertaining to distribution of the software without specific, 17 written prior permission. M.I.T. makes no representations about the 18 suitability of this software for any purpose. It is provided "as is" 19 without express or implied warranty. 20 */ 21 22 23 #include "NasConfig.h" /* see if we should try to use mutexes */ 24 25 #ifndef _MUTEX_H_INCLUDED 26 #define _MUTEX_H_INCLUDED 27 28 /*JET*/ 29 /*#define DEBUG_MUTEX*/ 30 31 #ifdef DEBUG_MUTEX 32 # define MDBG_START(x) fprintf(stderr, "%s: %s@%d ...", x, __FILE__, __LINE__); 33 # define MDBG_END() fprintf(stderr, "done\n"); 34 #else 35 # define MDBG_START(x) 36 # define MDBG_END() 37 #endif 38 39 #include <audio/audiolib.h> 40 41 #include <stdio.h> 42 #include <errno.h> 43 44 #include <audio/Aproto.h> 45 #include <audio/Afuncs.h> 46 #include <audio/Aosdefs.h> 47 48 /* NAS_USEMTSAFEAPI is defined in config/NasConfig.h. If undefined 49 thread safety will be disabled */ 50 51 #if defined(XTHREADS) && defined(NAS_USEMTSAFEAPI) 52 53 # include <X11/Xthreads.h> 54 typedef xmutex_rec _AuMutex; 55 # ifndef XMUTEX_INITIALIZER 56 57 /* These systems don't seem to define 58 XMUTEX_INITIALIZER, even though they 59 should */ 60 # if defined(SVR4) && (defined(USL) || defined(sun)) 61 # define XMUTEX_INITIALIZER {0} 62 # else 63 # define XMUTEX_INITIALIZER 0 64 # endif 65 # endif 66 # define _AU_MUTEX_INITIALIZER XMUTEX_INITIALIZER 67 #else 68 typedef unsigned int _AuMutex; 69 # define _AU_MUTEX_INITIALIZER 0 70 #endif 71 72 #ifdef _INSTANTIATE_GLOBALS 73 _AuMutex _serv_mutex = _AU_MUTEX_INITIALIZER; 74 _AuMutex _init_mutex = _AU_MUTEX_INITIALIZER; 75 #else 76 extern _AuMutex _serv_mutex; 77 extern _AuMutex _init_mutex; 78 #endif 79 80 81 /* NAS_USEMTSAFEAPI is defined in config/NasConfig.h. If undefined 82 thread safety will be disabled */ 83 84 #if defined(XTHREADS) && defined(NAS_USEMTSAFEAPI) 85 #define _AuLockServer() { \ 86 MDBG_START("LOCK _serv_mutex"); \ 87 xmutex_lock(&_serv_mutex); \ 88 MDBG_END(); \ 89 } 90 #define _AuUnlockServer() { \ 91 MDBG_START("UNLOCK _serv_mutex"); \ 92 xmutex_unlock(&_serv_mutex); \ 93 MDBG_END(); \ 94 } 95 96 #define _AuLockMutex(x) { \ 97 MDBG_START("LOCK mutex"); \ 98 xmutex_lock(&(x)); \ 99 MDBG_END(); \ 100 } 101 #define _AuUnlockMutex(x) { \ 102 MDBG_START("UNLOCK mutex"); \ 103 xmutex_unlock(&(x)); \ 104 MDBG_END(); \ 105 } 106 107 #else 108 #define _AuLockServer() 109 #define _AuUnlockServer() 110 111 #define _AuLockMutex(x) 112 #define _AuUnlockMutex(x) 113 #endif 114 115 116 117 #endif /* _MUTEX_H_INCLUDED */ 118