LCOV - code coverage report
Current view: top level - co - dataIStreamQueue.h (source / functions) Hit Total Coverage
Test: Collage Lines: 1 2 50.0 %
Date: 2018-01-09 16:37:03 Functions: 2 3 66.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2011-2017, Stefan Eilemann <eile@eyescale.ch>
       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             : #ifndef CO_DATAISTREAMQUEUE_H
      21             : #define CO_DATAISTREAMQUEUE_H
      22             : 
      23             : #include <co/types.h>
      24             : 
      25             : #include <lunchbox/mtQueue.h> // member
      26             : #include <lunchbox/pool.h>    // member
      27             : #include <lunchbox/thread.h>  // thread-safety check
      28             : 
      29             : #include "objectDataIStream.h" // pooled object
      30             : 
      31             : namespace co
      32             : {
      33             : /**
      34             :  * @internal
      35             :  * Manages lifecycle of DataIStreams (assembles, queues and reuses them).
      36             :  */
      37             : class DataIStreamQueue
      38             : {
      39             : public:
      40             :     DataIStreamQueue();
      41             :     ~DataIStreamQueue();
      42             : 
      43             :     bool addDataCommand(const uint128_t& key, ICommand& command);
      44             : 
      45           0 :     ObjectDataIStream* pop() { return _queued.pop().second; }
      46             :     ObjectDataIStream* tryPop();
      47             :     ObjectDataIStream* pull(const uint128_t& key);
      48             :     void recycle(ObjectDataIStream* stream);
      49             : 
      50             : protected:
      51             :     typedef std::unordered_map<uint128_t, ObjectDataIStream*> PendingStreams;
      52             :     typedef PendingStreams::const_iterator PendingStreamsCIter;
      53             : 
      54             :     /** Not yet ready streams. */
      55             :     PendingStreams _pending;
      56             : 
      57             :     typedef std::pair<uint128_t, ObjectDataIStream*> QueuedStream;
      58             :     typedef std::vector<QueuedStream> QueuedStreams;
      59             : 
      60             :     /** The change queue. */
      61             :     lunchbox::MTQueue<QueuedStream> _queued;
      62             : 
      63             :     /** Cached input streams (+decompressor) */
      64             :     lunchbox::Pool<ObjectDataIStream> _iStreamCache;
      65             : 
      66         130 :     LB_TS_VAR(_thread);
      67             : };
      68             : }
      69             : 
      70             : #endif // CO_DATAISTREAMQUEUE_H

Generated by: LCOV version 1.11