Collage  1.5.0
High-performance C++ library for developing object-oriented distributed applications.
worker.ipp
1 
2 /* Copyright (c) 2011-2013, Stefan Eilemann <eile@eyescale.ch>
3  * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include "worker.h"
20 
21 #include "iCommand.h"
22 
23 namespace co
24 {
25 template< class Q > void WorkerThread< Q >::run()
26 {
27  while( !stopRunning( ))
28  {
29  while( _commands.isEmpty( ))
30  if( !notifyIdle( )) // nothing to do
31  break;
32 
33  const ICommands& commands = _commands.popAll();
34  LBASSERT( !commands.empty( ));
35 
36  for( ICommandsCIter i = commands.begin(); i != commands.end(); ++i )
37  {
38  // We want to avoid a non-const copy of commands, hence the cast...
39  ICommand& command = const_cast< ICommand& >( *i );
40  if( !command( ))
41  {
42  LBABORT( "Error handling " << command );
43  }
44  if( stopRunning( ))
45  break;
46 
47  _commands.pump();
48  }
49  }
50 
51  _commands.flush();
52  LBDEBUG << "Leaving worker thread " << lunchbox::className( this )
53  << std::endl;
54 }
55 
56 }
CO_WORKER_API void run() override
Definition: worker.ipp:25
ICommands::const_iterator ICommandsCIter
A const iterator for a vector of input commands.
Definition: types.h:142
std::vector< ICommand > ICommands
A vector of input commands.
Definition: types.h:138
Object-oriented network library.
Definition: barrier.h:27
A class managing received commands.
Definition: iCommand.h:43