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