blob: 06d6e42f00c9f83f99c3eac7c2a89c920c06dd06 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* @author Peter Boros
* @date 2004/09/07
* @version $Id$
* @file mutex.cpp
* @brief Mutex.
*
*/
#include <pthread.h>
#include <sched.h>
#include <cassert>
#include "mutex.h"
namespace fsa {
// {{{ class Mutex::Impl
struct Mutex::Impl
{
pthread_mutex_t _mutex; /**< lock */
};
// }}}
Mutex::Mutex(void) : _impl(new Impl)
{
int rc;
rc = pthread_mutex_init(&(_impl->_mutex),NULL);
assert(rc == 0);
}
Mutex::~Mutex(void)
{
pthread_mutex_destroy(&(_impl->_mutex));
delete _impl;
}
bool Mutex::tryLock (void)
{
return pthread_mutex_trylock(&(_impl->_mutex)) == 0;
}
bool Mutex::lock (void)
{
return pthread_mutex_lock(&(_impl->_mutex)) == 0;
}
bool Mutex::unlock (void)
{
return pthread_mutex_unlock(&(_impl->_mutex)) == 0;
}
} // namespace fsa
|