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 51696 : template< class Q > void WorkerThread< Q >::run()
26 : {
27 103342 : while( !stopRunning( ))
28 : {
29 51647 : while( _commands.isEmpty( ))
30 51574 : if( !notifyIdle( )) // nothing to do
31 51574 : break;
32 :
33 103293 : const ICommands& commands = _commands.popAll();
34 51646 : LBASSERT( !commands.empty( ));
35 :
36 103243 : 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 51646 : ICommand& command = const_cast< ICommand& >( *i );
40 51646 : if( !command( ))
41 : {
42 0 : LBABORT( "Error handling " << command );
43 : }
44 51647 : if( stopRunning( ))
45 49 : break;
46 :
47 51598 : _commands.pump();
48 : }
49 : }
50 :
51 49 : _commands.flush();
52 98 : LBDEBUG << "Leaving worker thread " << lunchbox::className( this )
53 49 : << std::endl;
54 49 : }
55 :
56 : }
|