PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/signals2/detail/lwm_pthreads.hpp

http://hadesmem.googlecode.com/
C++ Header | 78 lines | 45 code | 21 blank | 12 comment | 3 complexity | fce4e86380d795a40c741cecf6db0152 MD5 | raw file
 1//
 2//  boost/signals2/detail/lwm_pthreads.hpp
 3//
 4//  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
 5//  Copyright (c) 2008 Frank Mori Hess
 6//
 7// Distributed under the Boost Software License, Version 1.0. (See
 8// accompanying file LICENSE_1_0.txt or copy at
 9// http://www.boost.org/LICENSE_1_0.txt)
10//
11
12#ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP
13#define BOOST_SIGNALS2_LWM_PTHREADS_HPP
14
15// MS compatible compilers support #pragma once
16
17#if defined(_MSC_VER) && (_MSC_VER >= 1020)
18# pragma once
19#endif
20
21
22#include <pthread.h>
23
24namespace boost
25{
26
27namespace signals2
28{
29
30class mutex
31{
32private:
33
34    pthread_mutex_t m_;
35
36    mutex(mutex const &);
37    mutex & operator=(mutex const &);
38
39public:
40
41    mutex()
42    {
43
44// HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
45
46#if defined(__hpux) && defined(_DECTHREADS_)
47        pthread_mutex_init(&m_, pthread_mutexattr_default);
48#else
49        pthread_mutex_init(&m_, 0);
50#endif
51    }
52
53    ~mutex()
54    {
55        pthread_mutex_destroy(&m_);
56    }
57
58    void lock()
59    {
60        pthread_mutex_lock(&m_);
61    }
62
63    bool try_lock()
64    {
65        return pthread_mutex_trylock(&m_) == 0;
66    }
67
68    void unlock()
69    {
70        pthread_mutex_unlock(&m_);
71    }
72};
73
74} // namespace signals2
75
76} // namespace boost
77
78#endif // #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP