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 int getDataSize (void) const { return (int)m_data.size(); }
59 void setDataSize (int 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, int numBytes);
76 const deUint8* getDataBlock (int numBytes); //!< \note Valid only during call.
86 CallWriter (CallQueue* queue, Call::Function function);
89 void write (const deUint8* bytes, int numBytes);
93 CallWriter (const CallWriter& other);
94 CallWriter& operator= (const CallWriter& other);
107 void callNext (void); //!< Executes and removes first call in queue. Will block if queue is empty.
109 Call* getEmptyCall (void);
110 void enqueue (Call* call);
111 void freeCall (Call* call);
114 CallQueue (const CallQueue& other);
115 CallQueue& operator= (const CallQueue& other);
117 de::Semaphore m_callSem;
120 std::vector<Call*> m_calls;
121 std::vector<Call*> m_freeCalls;
122 de::RingBuffer<Call*> m_callQueue;
125 // Stream operators for call reader / writer.
127 CallReader& operator>> (CallReader& reader, std::string& value);
128 CallWriter& operator<< (CallWriter& writer, const char* str);
130 template <typename T>
131 CallReader& operator>> (CallReader& reader, T& value)
133 reader.read((deUint8*)&value, sizeof(T));
137 template <typename T>
138 CallWriter& operator<< (CallWriter& writer, T& value)
140 writer.write((const deUint8*)&value, sizeof(T));
146 #endif // _XECALLQUEUE_HPP