1 #ifndef BOOST_DETAIL_LWM_GCC_HPP_INCLUDED
2 #define BOOST_DETAIL_LWM_GCC_HPP_INCLUDED
5 // boost/detail/lwm_gcc.hpp
7 // lightweight_mutex for GNU libstdc++ v3
9 // http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
11 // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
12 // Copyright (c) 2002 Lars Gullik Bjønnes <larsbj@lyx.org>
14 // Permission to copy, use, modify, sell and distribute this software
15 // is granted provided this copyright notice appears in all copies.
16 // This software is provided "as is" without express or implied
17 // warranty, and with no claim as to its suitability for any purpose.
20 #include <bits/atomicity.h>
29 class lightweight_mutex
35 lightweight_mutex(lightweight_mutex const &);
36 lightweight_mutex & operator=(lightweight_mutex const &);
40 lightweight_mutex(): a_(1)
45 friend class scoped_lock;
51 lightweight_mutex & m_;
53 scoped_lock(scoped_lock const &);
54 scoped_lock & operator=(scoped_lock const &);
58 explicit scoped_lock(lightweight_mutex & m): m_(m)
60 while( !__exchange_and_add(&m_.a_, -1) )
62 __atomic_add(&m_.a_, 1);
69 __atomic_add(&m_.a_, 1);
78 #endif // #ifndef BOOST_DETAIL_LWM_GCC_HPP_INCLUDED