]> git.lyx.org Git - lyx.git/blob - boost/boost/regex/pending/static_mutex.hpp
Also display the info about BibTeX databases in the TeX info panel.
[lyx.git] / boost / boost / regex / pending / static_mutex.hpp
1 /*
2  *
3  * Copyright (c) 2004
4  * John Maddock
5  *
6  * Use, modification and distribution are subject to the 
7  * Boost Software License, Version 1.0. (See accompanying file 
8  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9  *
10  */
11  
12  /*
13   *   LOCATION:    see http://www.boost.org for most recent version.
14   *   FILE         static_mutex.hpp
15   *   VERSION      see <boost/version.hpp>
16   *   DESCRIPTION: Declares static_mutex lock type, there are three different
17   *                implementations: POSIX pthreads, WIN32 threads, and portable,
18   *                these are described in more detail below.
19   */
20
21 #ifndef BOOST_REGEX_STATIC_MUTEX_HPP
22 #define BOOST_REGEX_STATIC_MUTEX_HPP
23
24 #include <boost/config.hpp>
25 #include <boost/regex/config.hpp> // dll import/export options.
26
27 #ifdef BOOST_HAS_PTHREADS
28 #include <pthread.h>
29 #endif
30
31 #if defined(BOOST_HAS_PTHREADS) && defined(PTHREAD_MUTEX_INITIALIZER)
32 //
33 // pthreads version:
34 // simple wrap around a pthread_mutex_t initialized with
35 // PTHREAD_MUTEX_INITIALIZER.
36 //
37 namespace boost{
38
39 class BOOST_REGEX_DECL scoped_static_mutex_lock;
40
41 class static_mutex
42 {
43 public:
44    typedef scoped_static_mutex_lock scoped_lock;
45    pthread_mutex_t m_mutex;
46 };
47
48 #define BOOST_STATIC_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, }
49
50 class BOOST_REGEX_DECL scoped_static_mutex_lock
51 {
52 public:
53    scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
54    ~scoped_static_mutex_lock();
55    inline bool locked()const
56    {
57       return m_have_lock;
58    }
59    inline operator void const*()const
60    {
61       return locked() ? this : 0;
62    }
63    void lock();
64    void unlock();
65 private:
66    static_mutex& m_mutex;
67    bool m_have_lock;
68 };
69
70
71 } // namespace boost
72 #elif defined(BOOST_HAS_WINTHREADS)
73 //
74 // Win32 version:
75 // Use a 32-bit int as a lock, along with a test-and-set
76 // implementation using InterlockedCompareExchange.
77 //
78
79 #include <boost/cstdint.hpp>
80
81 namespace boost{
82
83 class BOOST_REGEX_DECL scoped_static_mutex_lock;
84
85 class static_mutex
86 {
87 public:
88    typedef scoped_static_mutex_lock scoped_lock;
89    boost::int32_t m_mutex;
90 };
91
92 #define BOOST_STATIC_MUTEX_INIT { 0, }
93
94 class BOOST_REGEX_DECL scoped_static_mutex_lock
95 {
96 public:
97    scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
98    ~scoped_static_mutex_lock();
99    operator void const*()const
100    {
101       return locked() ? this : 0;
102    }
103    bool locked()const
104    {
105       return m_have_lock;
106    }
107    void lock();
108    void unlock();
109 private:
110    static_mutex& m_mutex;
111    bool m_have_lock;
112    scoped_static_mutex_lock(const scoped_static_mutex_lock&);
113    scoped_static_mutex_lock& operator=(const scoped_static_mutex_lock&);
114 };
115
116 } // namespace
117
118 #else
119 //
120 // Portable version of a static mutex based on Boost.Thread library:
121 // This has to use a single mutex shared by all instances of static_mutex
122 // because boost::call_once doesn't alow us to pass instance information
123 // down to the initialisation proceedure.  In fact the initialisation routine
124 // may need to be called more than once - but only once per instance.
125 //
126 // Since this preprocessor path is almost never taken, we hide these header
127 // dependencies so that build tools don't find them.
128 //
129 #define B1 <boost/thread/once.hpp>
130 #define B2 <boost/thread/recursive_mutex.hpp>
131 #include B1
132 #include B2
133 #undef B1
134 #undef B2
135
136 namespace boost{
137
138 class BOOST_REGEX_DECL scoped_static_mutex_lock;
139 extern "C" BOOST_REGEX_DECL void boost_regex_free_static_mutex();
140
141 class BOOST_REGEX_DECL static_mutex
142 {
143 public:
144    typedef scoped_static_mutex_lock scoped_lock;
145    static void init();
146    static boost::recursive_mutex* m_pmutex;
147    static boost::once_flag m_once;
148 };
149
150 #define BOOST_STATIC_MUTEX_INIT {  }
151
152 class BOOST_REGEX_DECL scoped_static_mutex_lock
153 {
154 public:
155    scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
156    ~scoped_static_mutex_lock();
157    operator void const*()const;
158    bool locked()const;
159    void lock();
160    void unlock();
161 private:
162    boost::recursive_mutex::scoped_lock* m_plock;
163    bool m_have_lock;
164 };
165
166 inline scoped_static_mutex_lock::operator void const*()const
167 {
168    return locked() ? this : 0;
169 }
170
171 inline bool scoped_static_mutex_lock::locked()const
172 {
173    return m_have_lock;
174 }
175
176 } // namespace
177
178 #endif
179
180 #endif