Line data Source code
1 :
2 : /* Copyright (c) 2006-2014, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This file is part of Collage <https://github.com/Eyescale/Collage>
6 : *
7 : * This library is free software; you can redistribute it and/or modify it under
8 : * the terms of the GNU Lesser General Public License version 2.1 as published
9 : * by the Free Software Foundation.
10 : *
11 : * This library is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 : * details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with this library; if not, write to the Free Software Foundation, Inc.,
18 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #ifndef CO_BUFFERCACHE_H
22 : #define CO_BUFFERCACHE_H
23 :
24 : #include <co/api.h>
25 : #include <co/types.h>
26 :
27 : #include <lunchbox/thread.h> // thread-safety checks
28 : #include <boost/noncopyable.hpp>
29 :
30 : namespace co
31 : {
32 : namespace detail { class BufferCache; }
33 :
34 : /** @internal
35 : * The buffer cache handles the reuse of allocated buffers for a node.
36 : *
37 : * Buffers are retained and released whenever they are not directly processed,
38 : * e.g., when pushed to another thread using a CommandQueue.
39 : */
40 : class BufferCache : public boost::noncopyable
41 : {
42 : public:
43 : /**
44 : * Construct a new buffer cache.
45 : *
46 : * @param minFree number of buffers that are always kept free.
47 : */
48 : CO_API explicit BufferCache( const int32_t minFree );
49 : CO_API ~BufferCache();
50 :
51 : /** @return a new buffer. */
52 : CO_API BufferPtr alloc( const uint64_t reserve );
53 :
54 : /** Compact buffer if too many commands are free. */
55 : void compact();
56 :
57 : /** Flush all allocated buffers. */
58 : void flush();
59 :
60 : private:
61 : detail::BufferCache* const _impl;
62 : friend std::ostream& operator << ( std::ostream&, const BufferCache& );
63 222 : LB_TS_VAR( _thread );
64 : };
65 :
66 : std::ostream& operator << ( std::ostream&, const BufferCache& );
67 : }
68 :
69 : #endif //CO_BUFFERCACHE_H
|