std::vector<std::vector<T> > inputs;
};
-template<typename R> class AsyncManager
+template<typename T, typename R> class AsyncManager
{
private:
using CallbackType = std::function<void()>;
const std::chrono::seconds _INPUT_QUEUE_WAIT_TIME_SEC { 1 };
const std::chrono::seconds _OUTPUT_QUEUE_WAIT_TIME_SEC { 3 };
- std::queue<AsyncInputQueue<unsigned char> > _incoming_queue;
+ std::queue<AsyncInputQueue<T> > _incoming_queue;
std::queue<R> _outgoing_queue;
std::mutex _incoming_queue_mutex;
std::mutex _outgoing_queue_mutex;
unsigned long _input_frame_number {};
CallbackType _callback;
- template<typename T> void pushToInput(AsyncInputQueue<T> &inputQueue)
+ void pushToInput(AsyncInputQueue<T> &inputQueue)
{
std::lock_guard<std::mutex> lock(_incoming_queue_mutex);
- AsyncInputQueue<unsigned char> dstQueue;
- dstQueue.frame_number = inputQueue.frame_number;
-
- for (auto &elms : inputQueue.inputs) {
- std::vector<unsigned char> dst_vector;
-
- for (auto &elm : elms) {
- unsigned char *bytes = reinterpret_cast<unsigned char *>(&elm);
-
- std::copy_n(bytes, sizeof(T), back_inserter(dst_vector));
- }
-
- dstQueue.inputs.push_back(dst_vector);
- }
-
- _incoming_queue.push(dstQueue);
+ _incoming_queue.push(inputQueue);
_incoming_queue_event.notify_one();
}
- template<typename T> bool isInputQueueEmpty()
+ bool isInputQueueEmpty()
{
std::lock_guard<std::mutex> lock(_incoming_queue_mutex);
return output;
}
- template<typename T> void inferenceThreadLoop()
+ void inferenceThreadLoop()
{
// If user called destroy API then this thread loop will be terminated.
while (!_exit_thread) {
// So make sure to call notify_one() here.
_outgoing_queue_event.notify_one();
}
- template<typename T> void invoke()
+ void invoke()
{
if (!_thread_handle)
- _thread_handle = std::make_unique<std::thread>(&AsyncManager::inferenceThreadLoop<T>, this);
+ _thread_handle = std::make_unique<std::thread>(&AsyncManager::inferenceThreadLoop, this);
}
bool waitforInputQueue()
{
swap(_outgoing_queue, empty);
}
- template<typename T> AsyncInputQueue<T> popFromInput()
+ AsyncInputQueue<T> popFromInput()
{
std::lock_guard<std::mutex> lock(_incoming_queue_mutex);
- AsyncInputQueue<unsigned char> inputQueue = _incoming_queue.front();
+ AsyncInputQueue<T> inputQueue = _incoming_queue.front();
_incoming_queue.pop();
- AsyncInputQueue<T> dstQueue;
-
- dstQueue.frame_number = inputQueue.frame_number;
-
- for (auto &elms : inputQueue.inputs) {
- std::vector<T> dst_vector;
-
- for (size_t idx = 0; idx < elms.size(); idx += sizeof(T)) {
- T dst_data;
-
- std::copy_n(elms.begin() + idx, sizeof(T), reinterpret_cast<unsigned char *>(&dst_data));
- dst_vector.push_back(dst_data);
- }
-
- dstQueue.inputs.push_back(dst_vector);
- }
-
- return dstQueue;
+ return inputQueue;
}
void pushToOutput(R &output)
{
_outgoing_queue.push(output);
_outgoing_queue_event.notify_one();
}
- template<typename T> void push(std::vector<std::vector<T> > &inputs)
+ void push(std::vector<std::vector<T> > &inputs)
{
_input_frame_number++;
- if (!isInputQueueEmpty<T>()) {
+ if (!isInputQueueEmpty()) {
LOGD("input frame number(%ld) has been skipped.", _input_frame_number);
return;
}
AsyncInputQueue<T> in_queue = { _input_frame_number, inputs };
- pushToInput<T>(in_queue);
+ pushToInput(in_queue);
LOGD("Pushed : input frame number = %lu", in_queue.frame_number);
- invoke<T>();
+ invoke();
}
R pop()
{