[go: up one dir, main page]

Menu

[408bb9]: / common / mutex.h  Maximize  Restore  History

Download this file

62 lines (46 with data), 1.1 kB

 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
57
58
59
60
61
#ifndef MUTEX_HEADER
#define MUTEX_HEADER
/***************************************************************************
* mutex.h
*
* Sat Aug 24 23:53:20 2002
* Copyright 2002 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include "utils.h"
#ifdef STXXL_BOOST_THREADS
// stxxl::mutex is not needed since boost:mutex exists
#include <boost/thread/mutex.hpp>
#else
#include <pthread.h>
namespace stxxl
{
class mutex
{
pthread_mutex_t _mutex;
public:
mutex ()
{
stxxl_nassert (pthread_mutex_init (&_mutex, NULL));
};
~mutex ()
{
int res = pthread_mutex_trylock (&_mutex);
if (res == 0 || res == EBUSY)
stxxl_nassert(pthread_mutex_unlock(&_mutex))
else
stxxl_function_error
stxxl_nassert(pthread_mutex_destroy(&_mutex));
};
void lock ()
{
stxxl_nassert(pthread_mutex_lock (&_mutex));
};
void unlock ()
{
stxxl_nassert(pthread_mutex_unlock (&_mutex));
};
};
};
#endif
#endif