Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / cpp_interfaces / ie_task_executor.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <string>
8 #include <vector>
9 #include <memory>
10 #include <mutex>
11 #include <condition_variable>
12 #include <thread>
13 #include <queue>
14 #include "ie_api.h"
15 #include "details/ie_exception.hpp"
16 #include "cpp_interfaces/ie_task_synchronizer.hpp"
17 #include "cpp_interfaces/ie_task.hpp"
18 #include "cpp_interfaces/exception2status.hpp"
19 #include "cpp_interfaces/ie_itask_executor.hpp"
20
21 namespace InferenceEngine {
22
23 class INFERENCE_ENGINE_API_CLASS(TaskExecutor) : public ITaskExecutor {
24 public:
25     typedef std::shared_ptr<TaskExecutor> Ptr;
26
27     TaskExecutor(std::string name = "Default");
28
29     ~TaskExecutor();
30
31     /**
32      * @brief Add task for execution and notify working thread about new task to start.
33      * @note can be called from multiple threads - tasks will be added to the queue and executed one-by-one in FIFO mode.
34      * @param task - shared pointer to the task to start
35      *  @return true if succeed to add task, otherwise - false
36      */
37     bool startTask(Task::Ptr task) override;
38
39 private:
40     std::shared_ptr<std::thread> _thread;
41     std::mutex _queueMutex;
42     std::condition_variable _queueCondVar;
43     std::queue<Task::Ptr> _taskQueue;
44     bool _isStopped;
45     std::string _name;
46 };
47
48 }  // namespace InferenceEngine