]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/lightweight_mutex.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / detail / lightweight_mutex.hpp
1 #ifndef BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
2 #define BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 //  boost/detail/lightweight_mutex.hpp - lightweight mutex
12 //
13 //  Copyright (c) 2002, 2003 Peter Dimov and Multi Media Ltd.
14 //
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 //
19 //  typedef <unspecified> boost::detail::lightweight_mutex;
20 //
21 //  boost::detail::lightweight_mutex meets a subset of the Mutex concept
22 //  requirements: http://www.boost.org/libs/thread/doc/mutex_concept.html#Mutex
23 //
24 //  * Used by the smart pointer library
25 //  * Performance oriented
26 //  * Header-only implementation
27 //  * Small memory footprint
28 //  * Not a general purpose mutex, use boost::mutex, CRITICAL_SECTION or
29 //    pthread_mutex instead.
30 //  * Never spin in a tight lock/do-something/unlock loop, since
31 //    lightweight_mutex does not guarantee fairness.
32 //  * Never keep a lightweight_mutex locked for long periods.
33 //
34 //  The current implementation can use a pthread_mutex, a CRITICAL_SECTION,
35 //  or a platform-specific spinlock.
36 //
37 //  You can force a particular implementation by defining BOOST_LWM_USE_PTHREADS,
38 //  BOOST_LWM_USE_CRITICAL_SECTION, or BOOST_LWM_USE_SPINLOCK.
39 //
40 //  If neither macro has been defined, the default is to use a spinlock on Win32,
41 //  and a pthread_mutex otherwise.
42 //
43 //  Note that a spinlock is not a general synchronization primitive. In particular,
44 //  it is not guaranteed to be a memory barrier, and it is possible to "livelock"
45 //  if a lower-priority thread has acquired the spinlock but a higher-priority
46 //  thread is spinning trying to acquire the same lock.
47 //
48 //  For these reasons, spinlocks have been disabled by default except on Windows,
49 //  where a spinlock can be several orders of magnitude faster than a CRITICAL_SECTION.
50
51
52 //  Note: lwm_linux.hpp has been disabled by default; see the comments
53 //        inside for more info.
54
55
56 #include <boost/config.hpp>
57
58 //  Note to implementors: if you write a platform-specific spinlock
59 //  for a platform that supports pthreads, be sure to test its performance
60 //  against the pthreads-based version using shared_ptr_timing_test.cpp and
61 //  shared_ptr_mt_test.cpp. Custom versions are usually not worth the trouble
62 //  _unless_ the performance gains are substantial.
63 //
64 //  Be sure to compare against a "real" pthreads library;
65 //  shared_ptr_timing_test.cpp will compile succesfully with a stub do-nothing
66 //  pthreads library, since it doesn't create any threads.
67
68 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) && !defined(BOOST_LWM_USE_CRITICAL_SECTION) && !defined(BOOST_LWM_USE_PTHREADS)
69 # define BOOST_LWM_WIN32
70 #endif
71
72 #if !defined(BOOST_HAS_THREADS)
73 #  if defined(BOOST_LWM_WIN32)
74 #    include <boost/detail/lwm_win32_nt.hpp>
75 #  else
76 #    include <boost/detail/lwm_nop.hpp>
77 #  endif
78 #elif defined(BOOST_LWM_USE_SPINLOCK) && defined(BOOST_USE_ASM_ATOMIC_H)
79 #  include <boost/detail/lwm_linux.hpp>
80 #elif defined(BOOST_LWM_USE_CRITICAL_SECTION)
81 #  include <boost/detail/lwm_win32_cs.hpp>
82 #elif defined(BOOST_LWM_USE_PTHREADS)
83 #  include <boost/detail/lwm_pthreads.hpp>
84 #elif defined(BOOST_LWM_WIN32)
85 #  include <boost/detail/lwm_win32.hpp>
86 #elif defined(BOOST_LWM_USE_SPINLOCK) && defined(__sgi)
87 #  include <boost/detail/lwm_irix.hpp>
88 #elif defined(BOOST_LWM_USE_SPINLOCK) && defined(__GLIBCPP__)
89 #  include <boost/detail/lwm_gcc.hpp>
90 #elif defined(BOOST_HAS_PTHREADS)
91 #  define BOOST_LWM_USE_PTHREADS
92 #  include <boost/detail/lwm_pthreads.hpp>
93 #else
94 // Use #define BOOST_DISABLE_THREADS to avoid the error
95 #  error Unrecognized threading platform
96 #endif
97
98 #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED