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 <boost/noncopyable.hpp>
28 : #include <lunchbox/thread.h> // thread-safety checks
29 :
30 : namespace co
31 : {
32 : namespace detail
33 : {
34 : class BufferCache;
35 : }
36 :
37 : /** @internal
38 : * The buffer cache handles the reuse of allocated buffers for a node.
39 : *
40 : * Buffers are retained and released whenever they are not directly processed,
41 : * e.g., when pushed to another thread using a CommandQueue.
42 : */
43 : class BufferCache : public boost::noncopyable
44 : {
45 : public:
46 : /**
47 : * Construct a new buffer cache.
48 : *
49 : * @param minFree number of buffers that are always kept free.
50 : */
51 : CO_API explicit BufferCache(const int32_t minFree);
52 : CO_API ~BufferCache();
53 :
54 : /** @return a new buffer. */
55 : CO_API BufferPtr alloc(const uint64_t reserve);
56 :
57 : /** Compact buffer if too many commands are free. */
58 : void compact();
59 :
60 : /** Flush all allocated buffers. */
61 : void flush();
62 :
63 : private:
64 : detail::BufferCache* const _impl;
65 : friend std::ostream& operator<<(std::ostream&, const BufferCache&);
66 214 : LB_TS_VAR(_thread);
67 : };
68 :
69 : std::ostream& operator<<(std::ostream&, const BufferCache&);
70 : }
71 :
72 : #endif // CO_BUFFERCACHE_H
|