1 #ifndef BOOST_DETAIL_LWM_LINUX_HPP_INCLUDED
2 #define BOOST_DETAIL_LWM_LINUX_HPP_INCLUDED
9 // boost/detail/lwm_linux.hpp
11 // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
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.
20 // This implementation uses <asm/atomic.h>. This is a kernel header;
21 // using kernel headers in a user program may cause a number of problems,
22 // and not all flavors of Linux provide the atomic instructions.
24 // This file is only provided because the performance of this implementation
25 // is about 3.5 times higher than the pthreads version. Use at your own risk
26 // (by defining BOOST_USE_ASM_ATOMIC_H.)
29 #include <asm/atomic.h>
38 class lightweight_mutex
44 lightweight_mutex(lightweight_mutex const &);
45 lightweight_mutex & operator=(lightweight_mutex const &);
51 atomic_t a = ATOMIC_INIT(1);
56 friend class scoped_lock;
62 lightweight_mutex & m_;
64 scoped_lock(scoped_lock const &);
65 scoped_lock & operator=(scoped_lock const &);
69 explicit scoped_lock(lightweight_mutex & m): m_(m)
71 while( !atomic_dec_and_test(&m_.a_) )
89 #endif // #ifndef BOOST_DETAIL_LWM_LINUX_HPP_INCLUDED