Line data Source code
1 :
2 : /* Copyright (c) 2005-2014, Stefan Eilemann <eile@equalizergraphics.com>
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_COMMANDQUEUE_H
21 : #define CO_COMMANDQUEUE_H
22 :
23 : #include <co/api.h>
24 : #include <co/types.h>
25 : #include <lunchbox/thread.h>
26 : #include <limits.h>
27 :
28 : namespace co
29 : {
30 : namespace detail { class CommandQueue; }
31 :
32 : /** A thread-safe, blocking queue for ICommand buffers. */
33 : class CommandQueue : public boost::noncopyable
34 : {
35 : public:
36 : /**
37 : * Construct a new command queue.
38 : *
39 : * @param maxSize the maximum number of enqueued commands.
40 : * @version 1.0
41 : */
42 : CO_API explicit CommandQueue( const size_t maxSize = ULONG_MAX );
43 :
44 : /** Destruct a new command queue. @version 1.0 */
45 : CO_API virtual ~CommandQueue();
46 :
47 : /**
48 : * Push a command to the queue.
49 : *
50 : * @param command the command.
51 : * @version 1.0
52 : */
53 : CO_API virtual void push( const ICommand& command );
54 :
55 : /** Push a command to the front of the queue. @version 1.0 */
56 : CO_API virtual void pushFront( const ICommand& command );
57 :
58 : /**
59 : * Pop a command from the queue.
60 : *
61 : * @param timeout the time in ms to wait for the operation.
62 : * @return the next command in the queue, or an invalid ICommand on timeout.
63 : * @version 1.0
64 : */
65 : CO_API virtual ICommand pop( const uint32_t timeout =
66 : LB_TIMEOUT_INDEFINITE );
67 :
68 : /**
69 : * Pop all, but at least one command from the queue.
70 : *
71 : * @param timeout the time in ms to wait for the operation.
72 : * @return All commands in the queue.
73 : * @version 1.0
74 : */
75 : CO_API virtual ICommands popAll( const uint32_t timeout =
76 : LB_TIMEOUT_INDEFINITE );
77 :
78 : /**
79 : * Try to pop a command from the queue.
80 : *
81 : * @return the next command in the queue, or 0 if no command is queued.
82 : * @version 1.0
83 : */
84 : CO_API virtual ICommand tryPop();
85 :
86 : /**
87 : * @return <code>true</code> if the command queue is empty,
88 : * <code>false</code> if not.
89 : * @version 1.0
90 : */
91 : CO_API bool isEmpty() const;
92 :
93 : /** Flush all pending commands. @version 1.0 */
94 : CO_API void flush();
95 :
96 : /** @return the size of the queue. @version 1.0 */
97 : CO_API size_t getSize() const;
98 :
99 : /** @internal trigger internal processing (message pump) */
100 51598 : virtual void pump() {};
101 :
102 138 : LB_TS_VAR( _thread );
103 :
104 : private:
105 : detail::CommandQueue* const _impl;
106 : };
107 : }
108 :
109 : #endif //CO_COMMANDQUEUE_H
|