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.
63 : * @throw Exception on timeout.
64 : * @version 1.0
65 : */
66 : CO_API virtual ICommand pop( const uint32_t timeout =
67 : LB_TIMEOUT_INDEFINITE );
68 :
69 : /**
70 : * Pop all, but at least one command from the queue.
71 : *
72 : * @param timeout the time in ms to wait for the operation.
73 : * @return one or more commands in the queue.
74 : * @throw Exception on timeout.
75 : * @version 1.0
76 : */
77 : CO_API virtual ICommands popAll( const uint32_t timeout =
78 : LB_TIMEOUT_INDEFINITE );
79 :
80 : /**
81 : * Try to pop a command from the queue.
82 : *
83 : * @return the next command in the queue, or 0 if no command is queued.
84 : * @version 1.0
85 : */
86 : CO_API virtual ICommand tryPop();
87 :
88 : /**
89 : * @return <code>true</code> if the command queue is empty,
90 : * <code>false</code> if not.
91 : * @version 1.0
92 : */
93 : CO_API bool isEmpty() const;
94 :
95 : /** Flush all pending commands. @version 1.0 */
96 : CO_API void flush();
97 :
98 : /** @return the size of the queue. @version 1.0 */
99 : CO_API size_t getSize() const;
100 :
101 : /** @internal trigger internal processing (message pump) */
102 51588 : virtual void pump() {};
103 :
104 130 : LB_TS_VAR( _thread );
105 :
106 : private:
107 : detail::CommandQueue* const _impl;
108 : };
109 : }
110 :
111 : #endif //CO_COMMANDQUEUE_H
|