/[svn]/linuxsampler/trunk/src/common/Mutex.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/Mutex.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 281 by schoenebeck, Tue Oct 12 20:46:13 2004 UTC revision 1149 by schoenebeck, Sat Apr 7 22:32:47 2007 UTC
# Line 3  Line 3 
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 - 2007 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  *
# Line 20  Line 21 
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
23    
24    #ifdef HAVE_CONFIG_H
25    # include <config.h>
26    #endif
27    
28    #ifndef _GNU_SOURCE
29    # define _GNU_SOURCE 1 /* so _XOPEN_SOURCE will be defined by features.h */
30    #endif
31    
32    #ifdef HAVE_FEATURES_H
33    # include <features.h>
34    #endif
35    
36    #if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500
37    # undef _XOPEN_SOURCE
38    # define _XOPEN_SOURCE 500 /* to define PTHREAD_MUTEX_ERRORCHECK */
39    # warning "Seems you don't have a UNIX98 compatible system."
40    # warning "Please run LinuxSampler's selftest to make sure this won't be a problem!"
41    # warning "(compile tests with 'make tests', run them with 'src/testcases/linuxsamplertest')"
42    #endif
43    
44  #include <iostream>  #include <iostream>
45  #include <errno.h>  #include <errno.h>
46  #include <stdlib.h> /* for exit(int) */  #include <stdlib.h> /* for exit(int) */
47    
48  #include "Mutex.h"  #include "Mutex.h"
49    
50    namespace LinuxSampler {
51    
52  Mutex::Mutex() {  Mutex::Mutex() {
53        pthread_mutexattr_init(&__posix_mutexattr);
54    
55      // the following function call only works on UNIX98 compatible systems      // the following function call only works on UNIX98 compatible systems
56        #if (_XOPEN_SOURCE > 500) || defined(__APPLE__)
57            // Mac OS X Note: 10.4 (and later) does support PTHREAD_MUTEX_ERRORCHECK, and
58            // actually LinuxSampler does not work if this call is omitted. However,
59            // defining _XOPEN_SOURCE macro seems to cause other problems. As a workaround,
60            // the symbol __APPLE__ is checked here. There should be a better solution
61            // to this problem. (Toshi Nagata, 27 Mar 2007)
62      if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_ERRORCHECK)) {      if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_ERRORCHECK)) {
63          std::cout << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK)\n" << std::flush;          std::cout << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK)\n" << std::flush;
64          exit(-1);          exit(-1);
65      }      }
66        #endif
67      pthread_mutex_init(&__posix_mutex, &__posix_mutexattr);      pthread_mutex_init(&__posix_mutex, &__posix_mutexattr);
68  }  }
69    
70  Mutex::~Mutex() {  Mutex::~Mutex() {
71      pthread_mutex_destroy(&__posix_mutex);      pthread_mutex_destroy(&__posix_mutex);
72        pthread_mutexattr_destroy(&__posix_mutexattr);
73  }  }
74    
75  void Mutex::Lock() {  void Mutex::Lock() {
# Line 52  bool Mutex::Trylock() { Line 85  bool Mutex::Trylock() {
85  void Mutex::Unlock() {  void Mutex::Unlock() {
86      pthread_mutex_unlock(&__posix_mutex);      pthread_mutex_unlock(&__posix_mutex);
87  }  }
88    
89    } // namespace LinuxSampler

Legend:
Removed from v.281  
changed lines
  Added in v.1149

  ViewVC Help
Powered by ViewVC