Collage  1.7.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>
27 {
28  while (!stopRunning())
29  {
30  while (_commands.isEmpty())
31  if (!notifyIdle()) // nothing to do
32  break;
33 
34  const ICommands& commands = _commands.popAll();
35  LBASSERT(!commands.empty());
36 
37  for (ICommandsCIter i = commands.begin(); i != commands.end(); ++i)
38  {
39  // We want to avoid a non-const copy of commands, hence the cast...
40  ICommand& command = const_cast<ICommand&>(*i);
41  if (!command())
42  {
43  LBABORT("Error handling " << command);
44  }
45  if (stopRunning())
46  break;
47 
48  _commands.pump();
49  }
50  }
51 
52  _commands.flush();
53  LBDEBUG << "Leaving worker thread " << lunchbox::className(this)
54  << std::endl;
55 }
56 }
CO_WORKER_API void run() override
Definition: worker.ipp:26
ICommands::const_iterator ICommandsCIter
A const iterator for a vector of input commands.
Definition: types.h:142
Object-oriented network library.
Definition: barrier.h:27
A class managing received commands.
Definition: iCommand.h:45
std::vector< ICommand > ICommands
A vector of input commands.
Definition: types.h:138