1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#include "PosixMutex.h" |
---|
25 |
|
---|
26 |
namespace Util |
---|
27 |
{ |
---|
28 |
|
---|
29 |
IMPL_DEBUG_MODULE( PosixMutex, PosixMutex, DEBUG_LEVEL_NORMAL ); |
---|
30 |
|
---|
31 |
PosixMutex::PosixMutex() |
---|
32 |
{ |
---|
33 |
pthread_mutexattr_t attr; |
---|
34 |
#ifdef DEBUG |
---|
35 |
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
---|
36 |
#else |
---|
37 |
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); |
---|
38 |
#endif |
---|
39 |
pthread_mutex_init(&m_mutex, &attr); |
---|
40 |
} |
---|
41 |
|
---|
42 |
PosixMutex::~PosixMutex() |
---|
43 |
{ |
---|
44 |
pthread_mutex_destroy(&m_mutex); |
---|
45 |
} |
---|
46 |
|
---|
47 |
void |
---|
48 |
PosixMutex::Lock() |
---|
49 |
{ |
---|
50 |
debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p) lock\n", this); |
---|
51 |
pthread_mutex_lock(&m_mutex); |
---|
52 |
} |
---|
53 |
|
---|
54 |
bool |
---|
55 |
PosixMutex::TryLock() |
---|
56 |
{ |
---|
57 |
debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p) trying to lock\n", this); |
---|
58 |
return pthread_mutex_trylock(&m_mutex) == 0; |
---|
59 |
} |
---|
60 |
|
---|
61 |
void |
---|
62 |
PosixMutex::Unlock() |
---|
63 |
{ |
---|
64 |
debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p) unlock\n", this); |
---|
65 |
pthread_mutex_unlock(&m_mutex); |
---|
66 |
} |
---|
67 |
|
---|
68 |
void |
---|
69 |
PosixMutex::show() |
---|
70 |
{ |
---|
71 |
debugOutput(DEBUG_LEVEL_NORMAL, "(%p) mutex\n", this); |
---|
72 |
} |
---|
73 |
|
---|
74 |
|
---|
75 |
} // end of namespace |
---|