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