LCOV - code coverage report
Current view: top level - lunchbox - lfQueue.ipp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 19 21 90.5 %
Date: 2018-10-03 05:33:11 Functions: 3 3 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : namespace lunchbox
      19             : {
      20             : template <typename T>
      21             : void LFQueue<T>::clear()
      22             : {
      23             :     LB_TS_SCOPED(_reader);
      24             :     _readPos = 0;
      25             :     _writePos = 0;
      26             : }
      27             : 
      28             : template <typename T>
      29             : void LFQueue<T>::resize(const int32_t size)
      30             : {
      31             :     LBASSERT(isEmpty());
      32             :     _readPos = 0;
      33             :     _writePos = 0;
      34             :     _data.resize(size + 1);
      35             : }
      36             : 
      37             : template <typename T>
      38      273631 : bool LFQueue<T>::pop(T& result)
      39             : {
      40      547262 :     LB_TS_SCOPED(_reader);
      41      273631 :     if (_readPos == _writePos)
      42           0 :         return false;
      43             : 
      44      273631 :     result = _data[_readPos];
      45      273631 :     _readPos = (_readPos + 1) % _data.size();
      46      273631 :     return true;
      47             : }
      48             : 
      49             : template <typename T>
      50      273631 : bool LFQueue<T>::getFront(T& result)
      51             : {
      52      547262 :     LB_TS_SCOPED(_reader);
      53      273631 :     if (_readPos == _writePos)
      54           0 :         return false;
      55             : 
      56      273631 :     result = _data[_readPos];
      57      273631 :     return true;
      58             : }
      59             : 
      60             : template <typename T>
      61      531066 : bool LFQueue<T>::push(const T& element)
      62             : {
      63     1062132 :     LB_TS_SCOPED(_writer);
      64      531066 :     int32_t nextPos = (_writePos + 1) % _data.size();
      65      531066 :     if (nextPos == _readPos)
      66      256426 :         return false;
      67             : 
      68      274640 :     _data[_writePos] = element;
      69      274640 :     _writePos = nextPos;
      70      274640 :     return true;
      71             : }
      72             : }

Generated by: LCOV version 1.11