--- linuxsampler/trunk/src/common/Mutex.cpp 2004/04/27 09:21:58 56 +++ linuxsampler/trunk/src/common/Mutex.cpp 2004/10/20 03:02:35 290 @@ -20,11 +20,28 @@ * MA 02111-1307 USA * ***************************************************************************/ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 /* so _XOPEN_SOURCE will be defined by features.h */ +#endif + +#include + +#if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500 +# undef _XOPEN_SOURCE +# define _XOPEN_SOURCE 500 /* to define PTHREAD_MUTEX_ERRORCHECK */ +# warning "Seems you don't have a UNIX98 compatible system." +# warning "Please run LinuxSampler's selftest to make sure this won't be a problem!" +# warning "(compile tests with 'make tests', run them with 'src/testcases/linuxsamplertest')" +#endif + #include +#include +#include /* for exit(int) */ #include "Mutex.h" Mutex::Mutex() { + // the following function call only works on UNIX98 compatible systems if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_ERRORCHECK)) { std::cout << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK)\n" << std::flush; exit(-1); @@ -40,6 +57,12 @@ pthread_mutex_lock(&__posix_mutex); } +bool Mutex::Trylock() { + if (pthread_mutex_trylock(&__posix_mutex) == EBUSY) + return false; + return true; +} + void Mutex::Unlock() { pthread_mutex_unlock(&__posix_mutex); }