csGblMtx.h

Go to the documentation of this file.
00001 /*
00002     csGblMtx.h:
00003 
00004     Copyright (C) 2005 Istvan Varga
00005 
00006     This file is part of Csound.
00007 
00008     The Csound Library is free software; you can redistribute it
00009     and/or modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2.1 of the License, or (at your option) any later version.
00012 
00013     Csound is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with Csound; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00021     02111-1307 USA
00022 */
00023 
00024 #ifndef CSOUND_CSGBLMTX_H
00025 #define CSOUND_CSGBLMTX_H
00026 
00027 #if defined(__linux) || defined(__linux__) || defined(__unix) ||    \
00028     defined(__unix__) || defined(__MACOSX__) || defined(__APPLE__)
00029 
00030 #include <pthread.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 static  pthread_mutex_t     csound_global_lock_ = PTHREAD_MUTEX_INITIALIZER;
00037 
00038 static
00039 #ifdef __GNUC__
00040 #  ifndef __STRICT_ANSI__
00041   inline
00042 #  else
00043   __inline__
00044 #  endif
00045 #endif
00046     void csound_global_mutex_lock(void)
00047 {
00048     pthread_mutex_lock(&csound_global_lock_);
00049 }
00050 
00051 static
00052 #ifdef __GNUC__
00053 #  ifndef __STRICT_ANSI__
00054   inline
00055 #  else
00056   __inline__
00057 #  endif
00058 #endif
00059     void csound_global_mutex_unlock(void)
00060 {
00061     pthread_mutex_unlock(&csound_global_lock_);
00062 }
00063 
00064 #ifdef __cplusplus
00065 }       /* extern "C" */
00066 #endif
00067 
00068 #elif defined(_WIN32) || defined(__WIN32__)
00069 
00070 #include <windows.h>
00071 
00072 #ifdef __cplusplus
00073 extern "C" {
00074 #endif
00075 
00076 static  CRITICAL_SECTION    csound_global_lock_;
00077 
00078 #ifdef __GNUC__
00079 
00080 static __attribute__ ((__constructor__)) void csound_global_mutex_init_(void)
00081 {
00082     InitializeCriticalSection(&csound_global_lock_);
00083 }
00084 
00085 static __attribute__ ((__destructor__)) void csound_global_mutex_destroy_(void)
00086 {
00087     DeleteCriticalSection(&csound_global_lock_);
00088 }
00089 
00090 #else
00091 
00092 static  int     csound_global_lock_init_done_ = 0;
00093 
00094 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
00095 
00096 #endif
00097 
00098 static
00099 #ifdef __GNUC__
00100 #  ifndef __STRICT_ANSI__
00101   inline
00102 #  else
00103   __inline__
00104 #  endif
00105 #elif defined(_MSC_VER)
00106   __inline
00107 #endif
00108     void csound_global_mutex_lock(void)
00109 {
00110 #ifndef __GNUC__
00111     if (csound_global_lock_init_done_)
00112 #endif
00113       EnterCriticalSection(&csound_global_lock_);
00114 }
00115 
00116 static
00117 #ifdef __GNUC__
00118 #  ifndef __STRICT_ANSI__
00119   inline
00120 #  else
00121   __inline__
00122 #  endif
00123 #elif defined(_MSC_VER)
00124   __inline
00125 #endif
00126     void csound_global_mutex_unlock(void)
00127 {
00128 #ifndef __GNUC__
00129     if (csound_global_lock_init_done_)
00130 #endif
00131       LeaveCriticalSection(&csound_global_lock_);
00132 }
00133 
00134 #ifdef __cplusplus
00135 }       /* extern "C" */
00136 #endif
00137 
00138 #else
00139 
00140 #ifdef __GNUC__
00141 #  warning "global thread locks not supported on this platform"
00142 #endif
00143 
00144 #ifdef __cplusplus
00145 extern "C" {
00146 #endif
00147 
00148 static
00149 #ifdef __GNUC__
00150 #  ifndef __STRICT_ANSI__
00151   inline
00152 #  else
00153   __inline__
00154 #  endif
00155 #elif defined(_MSC_VER)
00156   __inline
00157 #endif
00158     void csound_global_mutex_lock(void)
00159 {
00160 }
00161 
00162 static
00163 #ifdef __GNUC__
00164 #  ifndef __STRICT_ANSI__
00165   inline
00166 #  else
00167   __inline__
00168 #  endif
00169 #elif defined(_MSC_VER)
00170   __inline
00171 #endif
00172     void csound_global_mutex_unlock(void)
00173 {
00174 }
00175 
00176 #ifdef __cplusplus
00177 }       /* extern "C" */
00178 #endif
00179 
00180 #endif
00181 
00182 #endif      /* CSOUND_CSGBLMTX_H */
00183 

Generated on Sun Nov 9 00:04:52 2008 for Csound and CsoundAC by  doxygen 1.5.6