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