]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/lwm_irix.hpp
update boost
[lyx.git] / boost / boost / detail / lwm_irix.hpp
1 #ifndef BOOST_DETAIL_LWM_IRIX_HPP_INCLUDED
2 #define BOOST_DETAIL_LWM_IRIX_HPP_INCLUDED
3
4 #if _MSC_VER >= 1020
5 #pragma once
6 #endif
7
8 //
9 //  boost/detail/lwm_irix.hpp
10 //
11 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
12 //  Copyright (c) 2002 Dan Gohman
13 //
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.
18 //
19
20 #include <sgidefs.h>
21 #include <mutex.h>
22 #include <sched.h>
23
24 namespace boost
25 {
26
27 namespace detail
28 {
29
30 class lightweight_mutex
31 {
32 private:
33
34     __uint32_t l_;
35
36     lightweight_mutex(lightweight_mutex const &);
37     lightweight_mutex & operator=(lightweight_mutex const &);
38
39 public:
40
41     lightweight_mutex(): l_(0)
42     {
43     }
44
45     class scoped_lock;
46     friend class scoped_lock;
47
48     class scoped_lock
49     {
50     private:
51
52         lightweight_mutex & m_;
53
54         scoped_lock(scoped_lock const &);
55         scoped_lock & operator=(scoped_lock const &);
56
57     public:
58
59         explicit scoped_lock(lightweight_mutex & m): m_(m)
60         {
61             while( test_and_set32(&m_.l_, 1) )
62             {
63                 sched_yield();
64             }
65         }
66
67         ~scoped_lock()
68         {
69             m_.l_ = 0;
70         }
71     };
72 };
73
74 } // namespace detail
75
76 } // namespace boost
77
78 #endif // #ifndef BOOST_DETAIL_LWM_IRIX_HPP_INCLUDED