queue.hpp (91cdbe469c6c3f623beb22f39671a7b3384e8b42) queue.hpp (b2c2467d272359fb30f9ba6d6ee0107ad05cede0)
1// Copyright (c) Benjamin Kietzman (github.com/bkietz)
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef DBUS_QUEUE_HPP
7#define DBUS_QUEUE_HPP
8

--- 61 unchanged lines hidden (view full) ---

70
71 lock.unlock();
72
73 io.post(
74 closure(BOOST_ASIO_MOVE_CAST(handler_type)(h), m));
75 }
76 }
77
1// Copyright (c) Benjamin Kietzman (github.com/bkietz)
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef DBUS_QUEUE_HPP
7#define DBUS_QUEUE_HPP
8

--- 61 unchanged lines hidden (view full) ---

70
71 lock.unlock();
72
73 io.post(
74 closure(BOOST_ASIO_MOVE_CAST(handler_type)(h), m));
75 }
76 }
77
78 template<typename PopHandler>
79 inline BOOST_ASIO_INITFN_RESULT_TYPE(PopHandler,
78 template<typename MessageHandler>
79 inline BOOST_ASIO_INITFN_RESULT_TYPE(MessageHandler,
80 void(boost::system::error_code, message_type))
80 void(boost::system::error_code, message_type))
81 async_pop(BOOST_ASIO_MOVE_ARG(PopHandler) h)
81 async_pop(BOOST_ASIO_MOVE_ARG(MessageHandler) h)
82 {
83 typedef ::boost::asio::detail::async_result_init<
82 {
83 typedef ::boost::asio::detail::async_result_init<
84 PopHandler, void(boost::system::error_code, message_type)> init_type;
84 MessageHandler, void(boost::system::error_code, message_type)> init_type;
85
86 mutex_type::scoped_lock lock(mutex);
87 if(messages.empty())
88 {
85
86 mutex_type::scoped_lock lock(mutex);
87 if(messages.empty())
88 {
89 init_type init(BOOST_ASIO_MOVE_CAST(PopHandler)(h));
89 init_type init(BOOST_ASIO_MOVE_CAST(MessageHandler)(h));
90
91 handlers.push_back(init.handler);
92
93 lock.unlock();
94
95 return init.result.get();
96
97 } else {
98 message_type m = messages.front();
99 messages.pop_front();
100
101 lock.unlock();
102
90
91 handlers.push_back(init.handler);
92
93 lock.unlock();
94
95 return init.result.get();
96
97 } else {
98 message_type m = messages.front();
99 messages.pop_front();
100
101 lock.unlock();
102
103 init_type init(BOOST_ASIO_MOVE_CAST(PopHandler)(h));
103 init_type init(BOOST_ASIO_MOVE_CAST(MessageHandler)(h));
104
105 io.post(closure(
106 BOOST_ASIO_MOVE_CAST(handler_type)(init.handler), m));
107
108 return init.result.get();
109 }
110 }
111};
112
113
114} // namespace detail
115} // namespace dbus
116
117#endif // DBUS_QUEUE_HPP
104
105 io.post(closure(
106 BOOST_ASIO_MOVE_CAST(handler_type)(init.handler), m));
107
108 return init.result.get();
109 }
110 }
111};
112
113
114} // namespace detail
115} // namespace dbus
116
117#endif // DBUS_QUEUE_HPP