| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | #ifndef BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 17:09:24 +00:00
										 |  |  | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
 | 
					
						
							|  |  |  | # pragma once
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  boost/detail/lightweight_mutex.hpp - lightweight mutex
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2003-07-02 11:54:40 +00:00
										 |  |  | //  Copyright (c) 2002, 2003 Peter Dimov and Multi Media Ltd.
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  Permission to copy, use, modify, sell and distribute this software
 | 
					
						
							|  |  |  | //  is granted provided this copyright notice appears in all copies.
 | 
					
						
							|  |  |  | //  This software is provided "as is" without express or implied
 | 
					
						
							|  |  |  | //  warranty, and with no claim as to its suitability for any purpose.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | //  typedef <unspecified> boost::detail::lightweight_mutex;
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | //  boost::detail::lightweight_mutex meets a subset of the Mutex concept
 | 
					
						
							|  |  |  | //  requirements: http://www.boost.org/libs/thread/doc/mutex_concept.html#Mutex
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  * Used by the smart pointer library
 | 
					
						
							|  |  |  | //  * Performance oriented
 | 
					
						
							|  |  |  | //  * Header-only implementation
 | 
					
						
							|  |  |  | //  * Small memory footprint
 | 
					
						
							|  |  |  | //  * Not a general purpose mutex, use boost::mutex, CRITICAL_SECTION or
 | 
					
						
							|  |  |  | //    pthread_mutex instead.
 | 
					
						
							|  |  |  | //  * Never spin in a tight lock/do-something/unlock loop, since
 | 
					
						
							|  |  |  | //    lightweight_mutex does not guarantee fairness.
 | 
					
						
							|  |  |  | //  * Never keep a lightweight_mutex locked for long periods.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | //  The current implementation can use a pthread_mutex, a CRITICAL_SECTION,
 | 
					
						
							|  |  |  | //  or a platform-specific spinlock.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  You can force a particular implementation by defining BOOST_LWM_USE_PTHREADS,
 | 
					
						
							|  |  |  | //  BOOST_LWM_USE_CRITICAL_SECTION, or BOOST_LWM_USE_SPINLOCK.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  If neither macro has been defined, the default is to use a spinlock on Win32,
 | 
					
						
							|  |  |  | //  and a pthread_mutex otherwise.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Note that a spinlock is not a general synchronization primitive. In particular,
 | 
					
						
							|  |  |  | //  it is not guaranteed to be a memory barrier, and it is possible to "livelock"
 | 
					
						
							|  |  |  | //  if a lower-priority thread has acquired the spinlock but a higher-priority
 | 
					
						
							|  |  |  | //  thread is spinning trying to acquire the same lock.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  For these reasons, spinlocks have been disabled by default except on Windows,
 | 
					
						
							|  |  |  | //  where a spinlock can be several orders of magnitude faster than a CRITICAL_SECTION.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-01 16:17:08 +00:00
										 |  |  | //  Note: lwm_linux.hpp has been disabled by default; see the comments
 | 
					
						
							|  |  |  | //        inside for more info.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | //  Note to implementors: if you write a platform-specific spinlock
 | 
					
						
							| 
									
										
										
										
											2002-03-15 22:00:10 +00:00
										 |  |  | //  for a platform that supports pthreads, be sure to test its performance
 | 
					
						
							| 
									
										
										
										
											2002-05-21 16:48:20 +00:00
										 |  |  | //  against the pthreads-based version using shared_ptr_timing_test.cpp and
 | 
					
						
							|  |  |  | //  shared_ptr_mt_test.cpp. Custom versions are usually not worth the trouble
 | 
					
						
							| 
									
										
										
										
											2002-03-15 22:00:10 +00:00
										 |  |  | //  _unless_ the performance gains are substantial.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2002-05-21 16:48:20 +00:00
										 |  |  | //  Be sure to compare against a "real" pthreads library;
 | 
					
						
							|  |  |  | //  shared_ptr_timing_test.cpp will compile succesfully with a stub do-nothing
 | 
					
						
							|  |  |  | //  pthreads library, since it doesn't create any threads.
 | 
					
						
							| 
									
										
										
										
											2002-03-15 22:00:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-02 11:54:40 +00:00
										 |  |  | #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) && !defined(BOOST_LWM_USE_CRITICAL_SECTION) && !defined(BOOST_LWM_USE_PTHREADS)
 | 
					
						
							|  |  |  | # define BOOST_LWM_WIN32
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_HAS_THREADS)
 | 
					
						
							|  |  |  | #  if defined(BOOST_LWM_WIN32)
 | 
					
						
							|  |  |  | #    include <boost/detail/lwm_win32_nt.hpp>
 | 
					
						
							|  |  |  | #  else
 | 
					
						
							|  |  |  | #    include <boost/detail/lwm_nop.hpp>
 | 
					
						
							|  |  |  | #  endif
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | #elif defined(BOOST_LWM_USE_SPINLOCK) && defined(BOOST_USE_ASM_ATOMIC_H)
 | 
					
						
							| 
									
										
										
										
											2002-02-16 15:00:55 +00:00
										 |  |  | #  include <boost/detail/lwm_linux.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-03-15 22:00:10 +00:00
										 |  |  | #elif defined(BOOST_LWM_USE_CRITICAL_SECTION)
 | 
					
						
							|  |  |  | #  include <boost/detail/lwm_win32_cs.hpp>
 | 
					
						
							|  |  |  | #elif defined(BOOST_LWM_USE_PTHREADS)
 | 
					
						
							|  |  |  | #  include <boost/detail/lwm_pthreads.hpp>
 | 
					
						
							| 
									
										
										
										
											2003-07-02 11:54:40 +00:00
										 |  |  | #elif defined(BOOST_LWM_WIN32)
 | 
					
						
							| 
									
										
										
										
											2002-03-15 22:00:10 +00:00
										 |  |  | #  include <boost/detail/lwm_win32.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | #elif defined(BOOST_LWM_USE_SPINLOCK) && defined(__sgi)
 | 
					
						
							| 
									
										
										
										
											2002-02-27 16:35:15 +00:00
										 |  |  | #  include <boost/detail/lwm_irix.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-06-20 15:16:03 +00:00
										 |  |  | #elif defined(BOOST_LWM_USE_SPINLOCK) && defined(__GLIBCPP__)
 | 
					
						
							| 
									
										
										
										
											2002-05-21 16:48:20 +00:00
										 |  |  | #  include <boost/detail/lwm_gcc.hpp>
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | #elif defined(BOOST_HAS_PTHREADS)
 | 
					
						
							| 
									
										
										
										
											2002-03-15 22:00:10 +00:00
										 |  |  | #  define BOOST_LWM_USE_PTHREADS
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | #  include <boost/detail/lwm_pthreads.hpp>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2003-02-10 12:58:50 +00:00
										 |  |  | // Use #define BOOST_DISABLE_THREADS to avoid the error
 | 
					
						
							|  |  |  | #  error Unrecognized threading platform
 | 
					
						
							| 
									
										
										
										
											2002-02-12 16:55:25 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_MUTEX_HPP_INCLUDED
 |