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