3 * Copyright (c) 1998-2000
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Dr John Maddock makes no representations
11 * about the suitability of this software for any purpose.
12 * It is provided "as is" without express or implied warranty.
17 * LOCATION: see http://www.boost.org for most recent version.
18 * FILE regex_synch.hpp
20 * DESCRIPTION: Thread synchronisation for regex code.
21 * Note this is an internal header file included
22 * by regex.hpp, do not include on its own.
25 #ifndef BOOST_REGEX_SYNCH_HPP
26 #define BOOST_REGEX_SYNCH_HPP
28 #ifndef BOOST_REGEX_CONFIG_HPP
29 #include <boost/re_detail/regex_config.hpp>
32 #if defined(BOOST_RE_PLATFORM_W32) && defined(BOOST_RE_THREADS)
36 #if !defined(BOOST_RE_PLATFORM_W32) && defined(BOOST_RE_THREADS)
45 #if __BORLANDC__ == 0x530
46 #pragma option push -a4 -b -Ve
47 #elif __BORLANDC__ > 0x530
48 #pragma option push -a8 -b -Ve
52 void BOOST_RE_CALL re_init_threads();
53 void BOOST_RE_CALL re_free_threads();
55 #ifdef BOOST_RE_THREADS
57 #ifndef BOOST_RE_PLATFORM_W32
59 typedef pthread_mutex_t CRITICAL_SECTION;
61 inline void BOOST_RE_CALL InitializeCriticalSection(CRITICAL_SECTION* ps)
63 pthread_mutex_init(ps, NULL);
66 inline void BOOST_RE_CALL DeleteCriticalSection(CRITICAL_SECTION* ps)
68 pthread_mutex_destroy(ps);
71 inline void BOOST_RE_CALL EnterCriticalSection(CRITICAL_SECTION* ps)
73 pthread_mutex_lock(ps);
76 inline void BOOST_RE_CALL LeaveCriticalSection(CRITICAL_SECTION* ps)
78 pthread_mutex_unlock(ps);
86 typedef Lock lock_type;
88 lock_guard(lock_type& m, bool aq = true)
89 : mut(m), owned(false){ acquire(aq); }
94 void BOOST_RE_CALL acquire(bool aq = true)
101 else if(!aq && owned)
110 // VC6 warning suppression:
111 lock_guard& operator=(const lock_guard&);
115 class critical_section
119 { InitializeCriticalSection(&hmutex);}
121 critical_section(const critical_section&)
122 { InitializeCriticalSection(&hmutex);}
124 const critical_section& BOOST_RE_CALL operator=(const critical_section&)
128 {DeleteCriticalSection(&hmutex);}
132 void BOOST_RE_CALL acquire(bool aq)
133 { if(aq) EnterCriticalSection(&hmutex);
134 else LeaveCriticalSection(&hmutex);
137 CRITICAL_SECTION hmutex;
140 typedef lock_guard<critical_section> ro_guard;
141 typedef lock_guard<critical_section> rw_guard;
143 friend lock_guard<critical_section>;
146 inline bool BOOST_RE_CALL operator==(const critical_section&, const critical_section&)
151 inline bool BOOST_RE_CALL operator<(const critical_section&, const critical_section&)
156 typedef lock_guard<critical_section> cs_guard;
158 BOOST_RE_IX_DECL extern critical_section* p_re_lock;
159 BOOST_RE_IX_DECL extern unsigned int re_lock_count;
161 #define BOOST_RE_GUARD(inst) boost::re_detail::critical_section::rw_guard g(inst);
163 #else // BOOST_RE_THREADS
165 #define BOOST_RE_GUARD(inst)
167 #endif // BOOST_RE_THREADS
170 #if __BORLANDC__ > 0x520
175 } // namespace re_detail