Line data Source code
1 :
2 : /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This file is part of Collage <https://github.com/Eyescale/Collage>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #include "commandQueue.h"
21 :
22 : #include "iCommand.h"
23 : #include "exception.h"
24 : #include "log.h"
25 : #include "node.h"
26 :
27 : #include <lunchbox/mtQueue.h>
28 :
29 : namespace co
30 : {
31 : namespace detail
32 : {
33 68 : class CommandQueue
34 : {
35 : public:
36 70 : explicit CommandQueue( const size_t maxSize ) : commands( maxSize ) {}
37 :
38 : /** Thread-safe buffer queue. */
39 : lunchbox::MTQueue< co::ICommand > commands;
40 : };
41 : }
42 :
43 70 : CommandQueue::CommandQueue( const size_t maxSize )
44 70 : : _impl( new detail::CommandQueue( maxSize ))
45 : {
46 70 : }
47 :
48 136 : CommandQueue::~CommandQueue()
49 : {
50 68 : flush();
51 68 : delete _impl;
52 68 : }
53 :
54 117 : void CommandQueue::flush()
55 : {
56 117 : if( !isEmpty( ))
57 0 : LBLOG( LOG_BUG ) << "Flushing non-empty command queue" << std::endl;
58 :
59 117 : _impl->commands.clear();
60 117 : }
61 :
62 51777 : bool CommandQueue::isEmpty() const
63 : {
64 51777 : return _impl->commands.isEmpty();
65 : }
66 :
67 5 : size_t CommandQueue::getSize() const
68 : {
69 5 : return _impl->commands.getSize();
70 : }
71 :
72 645285 : void CommandQueue::push( const ICommand& command )
73 : {
74 645285 : _impl->commands.push( command );
75 645286 : }
76 :
77 0 : void CommandQueue::pushFront( const ICommand& command )
78 : {
79 0 : LBASSERT( command.isValid( ));
80 0 : _impl->commands.pushFront( command );
81 0 : }
82 :
83 593606 : ICommand CommandQueue::pop( const uint32_t timeout )
84 : {
85 593606 : LB_TS_THREAD( _thread );
86 :
87 593630 : ICommand command;
88 593552 : _impl->commands.timedPop( timeout, command );
89 593604 : return command;
90 : }
91 :
92 51647 : ICommands CommandQueue::popAll( const uint32_t timeout )
93 : {
94 51647 : return _impl->commands.timedPopRange( timeout );
95 : }
96 :
97 2 : ICommand CommandQueue::tryPop()
98 : {
99 2 : LB_TS_THREAD( _thread );
100 2 : ICommand command;
101 2 : _impl->commands.tryPop( command );
102 2 : return command;
103 : }
104 :
105 66 : }
|