Line data Source code
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 46 : template< class Q > void WorkerThread< Q >::run()
26 : {
27 51653 : while( !stopRunning( ))
28 : {
29 103215 : while( _commands.isEmpty( ))
30 50596 : if( !notifyIdle( )) // nothing to do
31 50597 : break;
32 :
33 51608 : const ICommands& commands = _commands.popAll();
34 51605 : LBASSERT( !commands.empty( ));
35 :
36 103193 : 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 51632 : ICommand& command = const_cast< ICommand& >( *i );
40 51632 : if( !command( ))
41 : {
42 0 : LBABORT( "Error handling " << command );
43 : }
44 51634 : if( stopRunning( ))
45 45 : break;
46 :
47 51590 : _commands.pump();
48 : }
49 : }
50 :
51 45 : _commands.flush();
52 90 : LBINFO << "Leaving worker thread " << lunchbox::className( this )
53 45 : << std::endl;
54 45 : }
55 :
56 : }
|