author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
#ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED |
sl@0 | 2 |
#define BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED |
sl@0 | 3 |
|
sl@0 | 4 |
// MS compatible compilers support #pragma once |
sl@0 | 5 |
|
sl@0 | 6 |
#if defined(_MSC_VER) && (_MSC_VER >= 1020) |
sl@0 | 7 |
# pragma once |
sl@0 | 8 |
#endif |
sl@0 | 9 |
|
sl@0 | 10 |
// |
sl@0 | 11 |
// boost/detail/lwm_pthreads.hpp |
sl@0 | 12 |
// |
sl@0 | 13 |
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. |
sl@0 | 14 |
// |
sl@0 | 15 |
// Distributed under the Boost Software License, Version 1.0. (See |
sl@0 | 16 |
// accompanying file LICENSE_1_0.txt or copy at |
sl@0 | 17 |
// http://www.boost.org/LICENSE_1_0.txt) |
sl@0 | 18 |
// |
sl@0 | 19 |
|
sl@0 | 20 |
#include <pthread.h> |
sl@0 | 21 |
|
sl@0 | 22 |
namespace boost |
sl@0 | 23 |
{ |
sl@0 | 24 |
|
sl@0 | 25 |
namespace detail |
sl@0 | 26 |
{ |
sl@0 | 27 |
|
sl@0 | 28 |
class lightweight_mutex |
sl@0 | 29 |
{ |
sl@0 | 30 |
private: |
sl@0 | 31 |
|
sl@0 | 32 |
pthread_mutex_t m_; |
sl@0 | 33 |
|
sl@0 | 34 |
lightweight_mutex(lightweight_mutex const &); |
sl@0 | 35 |
lightweight_mutex & operator=(lightweight_mutex const &); |
sl@0 | 36 |
|
sl@0 | 37 |
public: |
sl@0 | 38 |
|
sl@0 | 39 |
lightweight_mutex() |
sl@0 | 40 |
{ |
sl@0 | 41 |
|
sl@0 | 42 |
// HPUX 10.20 / DCE has a nonstandard pthread_mutex_init |
sl@0 | 43 |
|
sl@0 | 44 |
#if defined(__hpux) && defined(_DECTHREADS_) |
sl@0 | 45 |
pthread_mutex_init(&m_, pthread_mutexattr_default); |
sl@0 | 46 |
#else |
sl@0 | 47 |
pthread_mutex_init(&m_, 0); |
sl@0 | 48 |
#endif |
sl@0 | 49 |
} |
sl@0 | 50 |
|
sl@0 | 51 |
~lightweight_mutex() |
sl@0 | 52 |
{ |
sl@0 | 53 |
pthread_mutex_destroy(&m_); |
sl@0 | 54 |
} |
sl@0 | 55 |
|
sl@0 | 56 |
class scoped_lock; |
sl@0 | 57 |
friend class scoped_lock; |
sl@0 | 58 |
|
sl@0 | 59 |
class scoped_lock |
sl@0 | 60 |
{ |
sl@0 | 61 |
private: |
sl@0 | 62 |
|
sl@0 | 63 |
pthread_mutex_t & m_; |
sl@0 | 64 |
|
sl@0 | 65 |
scoped_lock(scoped_lock const &); |
sl@0 | 66 |
scoped_lock & operator=(scoped_lock const &); |
sl@0 | 67 |
|
sl@0 | 68 |
public: |
sl@0 | 69 |
|
sl@0 | 70 |
scoped_lock(lightweight_mutex & m): m_(m.m_) |
sl@0 | 71 |
{ |
sl@0 | 72 |
pthread_mutex_lock(&m_); |
sl@0 | 73 |
} |
sl@0 | 74 |
|
sl@0 | 75 |
~scoped_lock() |
sl@0 | 76 |
{ |
sl@0 | 77 |
pthread_mutex_unlock(&m_); |
sl@0 | 78 |
} |
sl@0 | 79 |
}; |
sl@0 | 80 |
}; |
sl@0 | 81 |
|
sl@0 | 82 |
} // namespace detail |
sl@0 | 83 |
|
sl@0 | 84 |
} // namespace boost |
sl@0 | 85 |
|
sl@0 | 86 |
#endif // #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED |