Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / include / event_impl.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #pragma once
19 #include "api_impl.h"
20 #include "refcounted_obj.h"
21
22 #include <list>
23 #include <mutex>
24
25 namespace cldnn
26 {
27 struct user_event;
28
29 struct event_impl : public refcounted_obj<event_impl>
30 {
31 public:
32     event_impl() = default;
33
34     void wait();
35     bool is_set();
36     virtual bool is_valid() const { return _attached; }
37     virtual void reset() { _attached = false; }
38     //returns true if handler has been successfully added
39     bool add_event_handler(cldnn_event_handler handler, void* data);
40     
41     const std::list<cldnn_profiling_interval>& get_profiling_info();
42
43 private:
44     std::mutex _handlers_mutex;
45     std::list<std::pair<cldnn_event_handler, void*>> _handlers;
46
47     bool _profiling_captured = false;
48     std::list<cldnn_profiling_interval> _profiling_info;
49
50 protected:
51     bool _set = false;
52     bool _attached = false; //because ocl event can be attached later, we need mechanism to check if such event was attached
53     void call_handlers();
54
55     virtual void wait_impl() = 0;
56     virtual bool is_set_impl() = 0;
57     virtual bool add_event_handler_impl(cldnn_event_handler, void*) { return true; }
58
59     //returns whether profiling info has been captures successfully and there's no need to call this impl a second time when user requests to get profling info
60     virtual bool get_profiling_info_impl(std::list<cldnn_profiling_interval>&) { return true; };
61 };
62
63 struct user_event : virtual public event_impl
64 {
65 public:
66     user_event(bool set = false)
67     {
68         _set = set;
69     }
70
71     void set()
72     { 
73         if (_set)
74             return;
75         _set = true;
76         set_impl();
77         call_handlers();
78     }
79
80 private:
81     virtual void set_impl() = 0;
82 };
83
84 }
85
86 API_CAST(::cldnn_event, cldnn::event_impl)