3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2016 Christian Schoenebeck * |
* Copyright (C) 2005 - 2017 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
40 |
#if !defined(WIN32) |
#if !defined(WIN32) |
41 |
# if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500 |
# if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500 |
42 |
# undef _XOPEN_SOURCE |
# undef _XOPEN_SOURCE |
43 |
# define _XOPEN_SOURCE 500 /* to define PTHREAD_MUTEX_ERRORCHECK */ |
# define _XOPEN_SOURCE 500 /* to define PTHREAD_MUTEX_RECURSIVE */ |
44 |
# if (!defined(POSIX_C_SOURCE) || POSIX_C_SOURCE < 199801L) && !defined(__DARWIN_UNIX03) |
# if (!defined(POSIX_C_SOURCE) || POSIX_C_SOURCE < 199801L) && !__DARWIN_UNIX03 |
45 |
# warning "Seems you don't have a UNIX98 compatible system." |
# warning "Seems you don't have a UNIX98 compatible system." |
46 |
# warning "Please run LinuxSampler's selftest to make sure this won't be a problem!" |
# warning "Please run LinuxSampler's selftest to make sure this won't be a problem!" |
47 |
# warning "(compile tests with 'make tests', run them with 'src/testcases/linuxsamplertest')" |
# warning "(compile tests with 'make tests', run them with 'src/testcases/linuxsamplertest')" |
57 |
|
|
58 |
namespace LinuxSampler { |
namespace LinuxSampler { |
59 |
|
|
60 |
Mutex::Mutex() { |
Mutex::Mutex(type_t type) { |
61 |
#if defined(WIN32) |
#if defined(WIN32) |
62 |
hMutex = CreateMutex( NULL, FALSE, NULL); |
hMutex = CreateMutex( NULL, FALSE, NULL); |
63 |
if (hMutex == NULL) { |
if (hMutex == NULL) { |
66 |
} |
} |
67 |
#else |
#else |
68 |
pthread_mutexattr_init(&__posix_mutexattr); |
pthread_mutexattr_init(&__posix_mutexattr); |
69 |
|
// pthread_mutexattr_settype() only works on UNIX98 compatible systems |
70 |
// the following function call only works on UNIX98 compatible systems |
switch (type) { |
71 |
#if (_XOPEN_SOURCE > 500) || defined(__APPLE__) |
case RECURSIVE: |
72 |
// Mac OS X Note: 10.4 (and later) does support PTHREAD_MUTEX_ERRORCHECK, and |
if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_RECURSIVE)) { |
73 |
// actually LinuxSampler does not work if this call is omitted. However, |
std::cerr << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_RECURSIVE)\n" << std::flush; |
74 |
// defining _XOPEN_SOURCE macro seems to cause other problems. As a workaround, |
exit(-1); |
75 |
// the symbol __APPLE__ is checked here. There should be a better solution |
} |
76 |
// to this problem. (Toshi Nagata, 27 Mar 2007) |
break; |
77 |
if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_ERRORCHECK)) { |
case NON_RECURSIVE: |
78 |
std::cerr << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK)\n" << std::flush; |
if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_ERRORCHECK)) { |
79 |
|
std::cerr << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK)\n" << std::flush; |
80 |
|
exit(-1); |
81 |
|
} |
82 |
|
break; |
83 |
|
default: |
84 |
|
std::cerr << "Mutex Constructor: Fatal error - Unknown mutex type requested\n" << std::flush; |
85 |
exit(-1); |
exit(-1); |
86 |
|
break; |
87 |
} |
} |
|
#endif |
|
88 |
pthread_mutex_init(&__posix_mutex, &__posix_mutexattr); |
pthread_mutex_init(&__posix_mutex, &__posix_mutexattr); |
89 |
#endif |
#endif |
90 |
} |
} |