~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/pool/detail/mutex.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2000 Stephen Cleary (shammah@voyager.net)
 
2
//
 
3
// This file can be redistributed and/or modified under the terms found
 
4
//  in "copyright.html"
 
5
// This software and its documentation is provided "as is" without express or
 
6
//  implied warranty, and with no claim as to its suitability for any purpose.
 
7
//
 
8
// See http://www.boost.org for updates, documentation, and revision history.
 
9
 
 
10
#ifndef BOOST_POOL_MUTEX_HPP
 
11
#define BOOST_POOL_MUTEX_HPP
 
12
 
 
13
// Extremely Light-Weight wrapper classes for OS thread synchronization
 
14
 
 
15
// Configuration: for now, we just choose between pthread or Win32 mutexes or none
 
16
 
 
17
#define BOOST_MUTEX_HELPER_NONE         0
 
18
#define BOOST_MUTEX_HELPER_WIN32        1
 
19
#define BOOST_MUTEX_HELPER_PTHREAD      2
 
20
 
 
21
#ifdef BOOST_NO_MT
 
22
  // No multithreading -> make locks into no-ops
 
23
  #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_NONE
 
24
#else
 
25
  #ifdef __WIN32__
 
26
    #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_WIN32
 
27
  #else
 
28
    #include <unistd.h>
 
29
    #ifdef _POSIX_THREADS
 
30
      #define BOOST_MUTEX_HELPER BOOST_MUTEX_HELPER_PTHREAD
 
31
    #endif
 
32
  #endif
 
33
#endif
 
34
 
 
35
#ifndef BOOST_MUTEX_HELPER
 
36
  #error Unable to determine platform mutex type; define BOOST_NO_MT to assume single-threaded
 
37
#endif
 
38
 
 
39
 
 
40
#ifdef __WIN32__
 
41
  #include <windows.h>
 
42
#endif
 
43
#ifdef _POSIX_THREADS
 
44
  #include <pthread.h>
 
45
#endif
 
46
 
 
47
namespace boost {
 
48
 
 
49
namespace details {
 
50
namespace pool {
 
51
 
 
52
#ifdef __WIN32__
 
53
 
 
54
class win32_mutex
 
55
{
 
56
  private:
 
57
    CRITICAL_SECTION mtx;
 
58
 
 
59
    win32_mutex(const win32_mutex &);
 
60
    void operator=(const win32_mutex &);
 
61
 
 
62
  public:
 
63
    win32_mutex()
 
64
    { InitializeCriticalSection(&mtx); }
 
65
 
 
66
    ~win32_mutex()
 
67
    { DeleteCriticalSection(&mtx); }
 
68
 
 
69
    void lock()
 
70
    { EnterCriticalSection(&mtx); }
 
71
 
 
72
    void unlock()
 
73
    { LeaveCriticalSection(&mtx); }
 
74
};
 
75
 
 
76
#endif // defined(__WIN32__)
 
77
 
 
78
#ifdef _POSIX_THREADS
 
79
 
 
80
class pthread_mutex
 
81
{
 
82
  private:
 
83
    pthread_mutex_t mtx;
 
84
 
 
85
    pthread_mutex(const pthread_mutex &);
 
86
    void operator=(const pthread_mutex &);
 
87
 
 
88
  public:
 
89
    pthread_mutex()
 
90
    { pthread_mutex_init(&mtx, 0); }
 
91
 
 
92
    ~pthread_mutex()
 
93
    { pthread_mutex_destroy(&mtx); }
 
94
 
 
95
    void lock()
 
96
    { pthread_mutex_lock(&mtx); }
 
97
 
 
98
    void unlock()
 
99
    { pthread_mutex_unlock(&mtx); }
 
100
};
 
101
 
 
102
#endif // defined(_POSIX_THREADS)
 
103
 
 
104
class null_mutex
 
105
{
 
106
  private:
 
107
    null_mutex(const null_mutex &);
 
108
    void operator=(const null_mutex &);
 
109
 
 
110
  public:
 
111
    null_mutex() { }
 
112
 
 
113
    static void lock() { }
 
114
    static void unlock() { }
 
115
};
 
116
 
 
117
#if BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_NONE
 
118
  typedef null_mutex default_mutex;
 
119
#elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_WIN32
 
120
  typedef win32_mutex default_mutex;
 
121
#elif BOOST_MUTEX_HELPER == BOOST_MUTEX_HELPER_PTHREAD
 
122
  typedef pthread_mutex default_mutex;
 
123
#endif
 
124
 
 
125
} // namespace pool
 
126
} // namespace details
 
127
 
 
128
} // namespace boost
 
129
 
 
130
#undef BOOST_MUTEX_HELPER_WIN32
 
131
#undef BOOST_MUTEX_HELPER_PTHREAD
 
132
#undef BOOST_MUTEX_HELPER_NONE
 
133
#undef BOOST_MUTEX_HELPER
 
134
 
 
135
#endif