Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
task_scheduler_observer.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2020 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 #ifndef __TBB_task_scheduler_observer_H
18 #define __TBB_task_scheduler_observer_H
19 
20 #define __TBB_task_scheduler_observer_H_include_area
22 
23 #include "atomic.h"
24 #if __TBB_ARENA_OBSERVER
25 #include "task_arena.h"
26 #endif
27 
28 #if __TBB_SCHEDULER_OBSERVER
29 
30 namespace tbb {
31 namespace interface6 {
32 class task_scheduler_observer;
33 }
34 namespace internal {
35 
36 class observer_proxy;
37 class observer_list;
38 
40  friend class observer_proxy;
41  friend class observer_list;
43 
45 
47 
49 
50  atomic<intptr_t> my_busy_count;
51 
52 public:
54 
58  void __TBB_EXPORTED_METHOD observe( bool state=true );
59 
61  bool is_observing() const {return my_proxy!=NULL;}
62 
65 
67 
74  virtual void on_scheduler_entry( bool /*is_worker*/ ) {}
75 
77 
82  virtual void on_scheduler_exit( bool /*is_worker*/ ) {}
83 
85  virtual ~task_scheduler_observer_v3() { if(my_proxy) observe(false);}
86 };
87 
88 } // namespace internal
89 
90 #if __TBB_ARENA_OBSERVER
91 namespace interface6 {
96 
99  // TODO: take more high bits for version number
100  static const intptr_t v6_trait = (intptr_t)((~(uintptr_t)0 >> 1) + 1);
101 
103  intptr_t my_context_tag;
104  enum { global_tag = 0, implicit_tag = 1 };
105 
106 public:
108 
117  explicit task_scheduler_observer( bool local = false ) {
118 #if __TBB_ARENA_OBSERVER
120 #else
121  __TBB_ASSERT_EX( !local, NULL );
123 #endif
124  }
125 
126 #if __TBB_ARENA_OBSERVER
127 
132  my_context_tag = (intptr_t)&a;
133  }
134 #endif /* __TBB_ARENA_OBSERVER */
135 
139  virtual ~task_scheduler_observer() { if(my_proxy) observe(false); }
140 
142 
144  void observe( bool state=true ) {
145  if( state && !my_proxy ) {
146  __TBB_ASSERT( !my_busy_count, "Inconsistent state of task_scheduler_observer instance");
148  }
150  }
151 };
152 
153 } //namespace interface6
154 using interface6::task_scheduler_observer;
155 #else /*__TBB_ARENA_OBSERVER*/
156 typedef tbb::internal::task_scheduler_observer_v3 task_scheduler_observer;
157 #endif /*__TBB_ARENA_OBSERVER*/
158 
159 } // namespace tbb
160 
161 #endif /* __TBB_SCHEDULER_OBSERVER */
162 
164 #undef __TBB_task_scheduler_observer_H_include_area
165 
166 #endif /* __TBB_task_scheduler_observer_H */
task_scheduler_observer(task_arena &a)
Construct local observer for a given arena in inactive state (observation disabled).
virtual void on_scheduler_entry(bool)
Entry notification.
intptr_t my_context_tag
contains task_arena pointer or tag indicating local or global semantics of the observer
void observe(bool state=true)
Enable or disable observation.
bool is_observing() const
Returns true if observation is enabled, false otherwise.
void __TBB_EXPORTED_METHOD observe(bool state=true)
Enable or disable observation.
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
Definition: tbb_stddef.h:167
virtual void on_scheduler_exit(bool)
Exit notification.
atomic< intptr_t > my_busy_count
Counter preventing the observer from being destroyed while in use by the scheduler.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
No ordering.
Definition: atomic.h:61
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
virtual ~task_scheduler_observer_v3()
Destructor automatically switches observation off if it is enabled.
task_scheduler_observer(bool local=false)
Construct local or global observer in inactive state (observation disabled).
observer_proxy * my_proxy
Pointer to the proxy holding this observer.
The graph class.
task_scheduler_observer_v3()
Construct observer with observation disabled.

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.