1 #ifndef _XECALLQUEUE_HPP
2 #define _XECALLQUEUE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Test Executor
5 * ------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Cross-thread function call dispatcher.
24 *//*--------------------------------------------------------------------*/
27 #include "deMutex.hpp"
28 #include "deSemaphore.hpp"
29 #include "deRingBuffer.hpp"
41 // \todo [2012-07-10 pyry] Optimize memory management in Call
42 // \todo [2012-07-10 pyry] CallQueue API could be improved to match TestLog API more closely.
43 // In order to do that, reference counting system for call object management is needed.
48 typedef void (*Function) (CallReader& data);
55 Function getFunction (void) const { return m_func; }
56 void setFunction (Function func) { m_func = func; }
58 size_t getDataSize (void) const { return m_data.size(); }
59 void setDataSize (size_t size) { m_data.resize(size); }
61 const deUint8* getData (void) const { return m_data.empty() ? DE_NULL : &m_data[0]; }
62 deUint8* getData (void) { return m_data.empty() ? DE_NULL : &m_data[0]; }
66 std::vector<deUint8> m_data;
72 CallReader (Call* call);
73 CallReader (void) : m_call(DE_NULL), m_curPos(0) {}
75 void read (deUint8* bytes, size_t numBytes);
76 const deUint8* getDataBlock (size_t numBytes); //!< \note Valid only during call.
77 bool isDataConsumed (void) const; //!< all data has been consumed
80 CallReader (const CallReader& other); //!< disallowed
81 CallReader& operator= (const CallReader& other); //!< disallowed
90 CallWriter (CallQueue* queue, Call::Function function);
93 void write (const deUint8* bytes, size_t numBytes);
97 CallWriter (const CallWriter& other);
98 CallWriter& operator= (const CallWriter& other);
111 void callNext (void); //!< Executes and removes first call in queue. Will block if queue is empty.
113 Call* getEmptyCall (void);
114 void enqueue (Call* call);
115 void freeCall (Call* call);
119 CallQueue (const CallQueue& other);
120 CallQueue& operator= (const CallQueue& other);
123 de::Semaphore m_callSem;
126 std::vector<Call*> m_calls;
127 std::vector<Call*> m_freeCalls;
128 de::RingBuffer<Call*> m_callQueue;
131 // Stream operators for call reader / writer.
133 CallReader& operator>> (CallReader& reader, std::string& value);
134 CallWriter& operator<< (CallWriter& writer, const char* str);
136 template <typename T>
137 CallReader& operator>> (CallReader& reader, T& value)
139 reader.read((deUint8*)&value, sizeof(T));
143 template <typename T>
144 CallWriter& operator<< (CallWriter& writer, T& value)
146 writer.write((const deUint8*)&value, sizeof(T));
152 #endif // _XECALLQUEUE_HPP