LCOV - code coverage report
Current view: top level - co - commandQueue.cpp (source / functions) Hit Total Coverage
Test: Collage Lines: 33 38 86.8 %
Date: 2015-11-03 13:48:53 Functions: 13 15 86.7 %

          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          64 : class CommandQueue
      34             : {
      35             : public:
      36          66 :     explicit CommandQueue( const size_t maxSize ) : commands( maxSize ) {}
      37             : 
      38             :     /** Thread-safe buffer queue. */
      39             :     lunchbox::MTQueue< co::ICommand > commands;
      40             : };
      41             : }
      42             : 
      43          66 : CommandQueue::CommandQueue( const size_t maxSize )
      44          66 :     : _impl( new detail::CommandQueue( maxSize ))
      45             : {
      46          66 : }
      47             : 
      48         128 : CommandQueue::~CommandQueue()
      49             : {
      50          64 :     flush();
      51          64 :     delete _impl;
      52          64 : }
      53             : 
      54         109 : void CommandQueue::flush()
      55             : {
      56         109 :     if( !isEmpty( ))
      57           0 :         LBLOG( LOG_BUG ) << "Flushing non-empty command queue" << std::endl;
      58             : 
      59         109 :     _impl->commands.clear();
      60         109 : }
      61             : 
      62       51361 : bool CommandQueue::isEmpty() const
      63             : {
      64       51361 :     return _impl->commands.isEmpty();
      65             : }
      66             : 
      67           5 : size_t CommandQueue::getSize() const
      68             : {
      69           5 :     return _impl->commands.getSize();
      70             : }
      71             : 
      72      626437 : void CommandQueue::push( const ICommand& command )
      73             : {
      74      626437 :     _impl->commands.push( command );
      75      626437 : }
      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      574762 : ICommand CommandQueue::pop( const uint32_t timeout )
      84             : {
      85      574762 :     LB_TS_THREAD( _thread );
      86             : 
      87      574622 :     ICommand command;
      88      574603 :     _impl->commands.timedPop( timeout, command );
      89      574691 :     return command;
      90             : }
      91             : 
      92       51239 : ICommands CommandQueue::popAll( const uint32_t timeout )
      93             : {
      94       51239 :     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          63 : }

Generated by: LCOV version 1.11