1 #ifndef BOOST_STATECHART_FIFO_WORKER_HPP_INCLUDED
2 #define BOOST_STATECHART_FIFO_WORKER_HPP_INCLUDED
11 #include <boost/assert.hpp>
12 #include <boost/noncopyable.hpp>
13 #include <boost/function/function0.hpp>
14 #include <boost/bind.hpp>
16 #include <boost/config.hpp>
18 #include <boost/detail/allocator_utilities.hpp>
20 #ifdef BOOST_HAS_THREADS
22 # pragma warning( push )
24 # pragma warning( disable: 4127 )
26 # pragma warning( disable: 4244 )
28 # pragma warning( disable: 4251 )
30 # pragma warning( disable: 4512 )
33 # pragma warning( disable: 4996 )
36 # include <boost/thread/mutex.hpp>
37 # include <boost/thread/condition.hpp>
40 # pragma warning( pop )
55 template<
class Allocator = std::allocator< none > >
60 #ifdef BOOST_HAS_THREADS
62 waitOnEmptyQueue_( waitOnEmptyQueue ),
82 #ifdef BOOST_HAS_THREADS
83 mutex::scoped_lock lock( mutex_ );
87 workQueue_.back().swap( item );
89 #ifdef BOOST_HAS_THREADS
90 queueNotEmpty_.notify_one();
106 work_item item = boost::bind( &fifo_worker::terminate_impl,
this );
119 unsigned long itemCount = 0;
122 ( ( maxItemCount == 0 ) || ( itemCount < maxItemCount ) ) )
145 #ifdef BOOST_HAS_THREADS
146 mutex::scoped_lock lock( mutex_ );
148 if ( !waitOnEmptyQueue_ && workQueue_.empty() )
153 while ( workQueue_.empty() )
155 queueNotEmpty_.wait( lock );
164 if ( workQueue_.empty() )
173 result.swap( workQueue_.front() );
174 workQueue_.pop_front();
178 void terminate_impl()
186 typename boost::detail::allocator::rebind_to<
190 work_queue_type workQueue_;
192 #ifdef BOOST_HAS_THREADS
194 condition queueNotEmpty_;
195 const bool waitOnEmptyQueue_;