LCOV - code coverage report
Current view: top level - co - commandQueue.cpp (source / functions) Hit Total Coverage
Test: Collage Lines: 35 40 87.5 %
Date: 2018-01-09 16:37:03 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 "exception.h"
      23             : #include "iCommand.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          66 : class CommandQueue
      34             : {
      35             : public:
      36          68 :     explicit CommandQueue(const size_t maxSize)
      37          68 :         : commands(maxSize)
      38             :     {
      39          68 :     }
      40             : 
      41             :     /** Thread-safe buffer queue. */
      42             :     lunchbox::MTQueue<co::ICommand> commands;
      43             : };
      44             : }
      45             : 
      46          68 : CommandQueue::CommandQueue(const size_t maxSize)
      47          68 :     : _impl(new detail::CommandQueue(maxSize))
      48             : {
      49          68 : }
      50             : 
      51         132 : CommandQueue::~CommandQueue()
      52             : {
      53          66 :     flush();
      54          66 :     delete _impl;
      55          66 : }
      56             : 
      57         113 : void CommandQueue::flush()
      58             : {
      59         113 :     if (!isEmpty())
      60           0 :         LBLOG(LOG_BUG) << "Flushing non-empty command queue" << std::endl;
      61             : 
      62         113 :     _impl->commands.clear();
      63         113 : }
      64             : 
      65       51734 : bool CommandQueue::isEmpty() const
      66             : {
      67       51734 :     return _impl->commands.isEmpty();
      68             : }
      69             : 
      70           5 : size_t CommandQueue::getSize() const
      71             : {
      72           5 :     return _impl->commands.getSize();
      73             : }
      74             : 
      75      621520 : void CommandQueue::push(const ICommand& command)
      76             : {
      77      621520 :     _impl->commands.push(command);
      78      621520 : }
      79             : 
      80           0 : void CommandQueue::pushFront(const ICommand& command)
      81             : {
      82           0 :     LBASSERT(command.isValid());
      83           0 :     _impl->commands.pushFront(command);
      84           0 : }
      85             : 
      86      569875 : ICommand CommandQueue::pop(const uint32_t timeout)
      87             : {
      88      569875 :     LB_TS_THREAD(_thread);
      89             : 
      90      569872 :     ICommand command;
      91      569877 :     _impl->commands.timedPop(timeout, command);
      92      569838 :     return command;
      93             : }
      94             : 
      95       51608 : ICommands CommandQueue::popAll(const uint32_t timeout)
      96             : {
      97       51608 :     return _impl->commands.timedPopRange(timeout);
      98             : }
      99             : 
     100           2 : ICommand CommandQueue::tryPop()
     101             : {
     102           2 :     LB_TS_THREAD(_thread);
     103           2 :     ICommand command;
     104           2 :     _impl->commands.tryPop(command);
     105           2 :     return command;
     106             : }
     107          63 : }

Generated by: LCOV version 1.11