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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 880 - (hide annotations) (download)
Tue Jun 27 22:57:37 2006 UTC (17 years, 10 months ago) by schoenebeck
File size: 3200 byte(s)
just some refactoring work:
- renamed class LinuxSamplerException -> Exception
- encapsulated LS API relevant files into LS namespace
- removed unnecessary header inclusions

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 880 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * 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 *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24 persson 830 #ifdef HAVE_CONFIG_H
25     # include <config.h>
26     #endif
27    
28 schoenebeck 289 #ifndef _GNU_SOURCE
29     # define _GNU_SOURCE 1 /* so _XOPEN_SOURCE will be defined by features.h */
30     #endif
31    
32 persson 830 #ifdef HAVE_FEATURES_H
33 wylder 819 # include <features.h>
34     #endif
35 schoenebeck 289
36     #if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500
37     # undef _XOPEN_SOURCE
38     # define _XOPEN_SOURCE 500 /* to define PTHREAD_MUTEX_ERRORCHECK */
39 senkov 290 # 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 schoenebeck 289 #endif
43    
44 schoenebeck 53 #include <iostream>
45 capela 268 #include <errno.h>
46 schoenebeck 281 #include <stdlib.h> /* for exit(int) */
47 capela 268
48 schoenebeck 53 #include "Mutex.h"
49    
50 schoenebeck 880 namespace LinuxSampler {
51    
52 schoenebeck 53 Mutex::Mutex() {
53 schoenebeck 275 // the following function call only works on UNIX98 compatible systems
54 schoenebeck 361 #if (_XOPEN_SOURCE > 500)
55 schoenebeck 53 if (pthread_mutexattr_settype(&__posix_mutexattr, PTHREAD_MUTEX_ERRORCHECK)) {
56     std::cout << "Mutex Constructor: Fatal error - unable to pthread_mutexattr_settype(PTHREAD_MUTEX_ERRORCHECK)\n" << std::flush;
57     exit(-1);
58     }
59 schoenebeck 361 #endif
60 schoenebeck 53 pthread_mutex_init(&__posix_mutex, &__posix_mutexattr);
61     }
62    
63     Mutex::~Mutex() {
64     pthread_mutex_destroy(&__posix_mutex);
65     }
66    
67     void Mutex::Lock() {
68     pthread_mutex_lock(&__posix_mutex);
69     }
70    
71 senkov 165 bool Mutex::Trylock() {
72     if (pthread_mutex_trylock(&__posix_mutex) == EBUSY)
73     return false;
74     return true;
75     }
76    
77 schoenebeck 53 void Mutex::Unlock() {
78     pthread_mutex_unlock(&__posix_mutex);
79     }
80 schoenebeck 880
81     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC