Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 // See http://www.boost.org/libs/interprocess for documentation.
|
Chris@16
|
8 //
|
Chris@16
|
9 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP
|
Chris@16
|
12 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP
|
Chris@16
|
13
|
Chris@101
|
14 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
15 # include <boost/config.hpp>
|
Chris@101
|
16 #endif
|
Chris@101
|
17 #
|
Chris@101
|
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
19 # pragma once
|
Chris@101
|
20 #endif
|
Chris@101
|
21
|
Chris@16
|
22 #include <boost/interprocess/detail/config_begin.hpp>
|
Chris@16
|
23 #include <boost/interprocess/detail/workaround.hpp>
|
Chris@16
|
24 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 #include <boost/interprocess/sync/interprocess_mutex.hpp>
|
Chris@16
|
27 #include <boost/interprocess/sync/scoped_lock.hpp>
|
Chris@16
|
28 #include <boost/interprocess/exceptions.hpp>
|
Chris@16
|
29 #include <boost/interprocess/sync/windows/semaphore.hpp>
|
Chris@16
|
30 #include <boost/interprocess/sync/windows/mutex.hpp>
|
Chris@16
|
31 #include <boost/interprocess/sync/detail/condition_algorithm_8a.hpp>
|
Chris@16
|
32
|
Chris@16
|
33
|
Chris@16
|
34 namespace boost {
|
Chris@16
|
35 namespace interprocess {
|
Chris@16
|
36 namespace ipcdetail {
|
Chris@16
|
37
|
Chris@16
|
38 class windows_condition
|
Chris@16
|
39 {
|
Chris@16
|
40 windows_condition(const windows_condition &);
|
Chris@16
|
41 windows_condition &operator=(const windows_condition &);
|
Chris@16
|
42
|
Chris@16
|
43 public:
|
Chris@16
|
44 windows_condition()
|
Chris@16
|
45 : m_condition_data()
|
Chris@16
|
46 {}
|
Chris@16
|
47
|
Chris@16
|
48 ~windows_condition()
|
Chris@101
|
49 {
|
Chris@101
|
50 //Notify all waiting threads
|
Chris@101
|
51 //to allow POSIX semantics on condition destruction
|
Chris@101
|
52 this->notify_all();
|
Chris@101
|
53 }
|
Chris@16
|
54
|
Chris@16
|
55 void notify_one()
|
Chris@16
|
56 { m_condition_data.notify_one(); }
|
Chris@16
|
57
|
Chris@16
|
58 void notify_all()
|
Chris@16
|
59 { m_condition_data.notify_all(); }
|
Chris@16
|
60
|
Chris@16
|
61 template <typename L>
|
Chris@16
|
62 bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time)
|
Chris@16
|
63 { return m_condition_data.timed_wait(lock, abs_time); }
|
Chris@16
|
64
|
Chris@16
|
65 template <typename L, typename Pr>
|
Chris@16
|
66 bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred)
|
Chris@16
|
67 { return m_condition_data.timed_wait(lock, abs_time, pred); }
|
Chris@16
|
68
|
Chris@16
|
69 template <typename L>
|
Chris@16
|
70 void wait(L& lock)
|
Chris@16
|
71 { m_condition_data.wait(lock); }
|
Chris@16
|
72
|
Chris@16
|
73 template <typename L, typename Pr>
|
Chris@16
|
74 void wait(L& lock, Pr pred)
|
Chris@16
|
75 { m_condition_data.wait(lock, pred); }
|
Chris@16
|
76
|
Chris@16
|
77 private:
|
Chris@16
|
78
|
Chris@16
|
79 struct condition_data
|
Chris@16
|
80 {
|
Chris@16
|
81 typedef boost::int32_t integer_type;
|
Chris@16
|
82 typedef windows_semaphore semaphore_type;
|
Chris@16
|
83 typedef windows_mutex mutex_type;
|
Chris@16
|
84
|
Chris@16
|
85 condition_data()
|
Chris@16
|
86 : m_nwaiters_blocked(0)
|
Chris@16
|
87 , m_nwaiters_gone(0)
|
Chris@16
|
88 , m_nwaiters_to_unblock(0)
|
Chris@16
|
89 , m_sem_block_queue(0)
|
Chris@16
|
90 , m_sem_block_lock(1)
|
Chris@16
|
91 , m_mtx_unblock_lock()
|
Chris@16
|
92 {}
|
Chris@16
|
93
|
Chris@16
|
94 integer_type &get_nwaiters_blocked()
|
Chris@16
|
95 { return m_nwaiters_blocked; }
|
Chris@16
|
96
|
Chris@16
|
97 integer_type &get_nwaiters_gone()
|
Chris@16
|
98 { return m_nwaiters_gone; }
|
Chris@16
|
99
|
Chris@16
|
100 integer_type &get_nwaiters_to_unblock()
|
Chris@16
|
101 { return m_nwaiters_to_unblock; }
|
Chris@16
|
102
|
Chris@16
|
103 semaphore_type &get_sem_block_queue()
|
Chris@16
|
104 { return m_sem_block_queue; }
|
Chris@16
|
105
|
Chris@16
|
106 semaphore_type &get_sem_block_lock()
|
Chris@16
|
107 { return m_sem_block_lock; }
|
Chris@16
|
108
|
Chris@16
|
109 mutex_type &get_mtx_unblock_lock()
|
Chris@16
|
110 { return m_mtx_unblock_lock; }
|
Chris@16
|
111
|
Chris@16
|
112 boost::int32_t m_nwaiters_blocked;
|
Chris@16
|
113 boost::int32_t m_nwaiters_gone;
|
Chris@16
|
114 boost::int32_t m_nwaiters_to_unblock;
|
Chris@16
|
115 windows_semaphore m_sem_block_queue;
|
Chris@16
|
116 windows_semaphore m_sem_block_lock;
|
Chris@16
|
117 windows_mutex m_mtx_unblock_lock;
|
Chris@16
|
118 };
|
Chris@16
|
119
|
Chris@16
|
120 ipcdetail::condition_8a_wrapper<condition_data> m_condition_data;
|
Chris@16
|
121 };
|
Chris@16
|
122
|
Chris@16
|
123 } //namespace ipcdetail
|
Chris@16
|
124 } //namespace interprocess
|
Chris@16
|
125 } //namespace boost
|
Chris@16
|
126
|
Chris@16
|
127 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
128
|
Chris@16
|
129 #endif //BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP
|