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-2019 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 #include "atomic.h"
21 #if __TBB_ARENA_OBSERVER
22 #include "task_arena.h"
23 #endif
24 
25 #if __TBB_SCHEDULER_OBSERVER
26 
27 namespace tbb {
28 namespace interface6 {
29 class task_scheduler_observer;
30 }
31 namespace internal {
32 
33 class observer_proxy;
34 class observer_list;
35 
37  friend class observer_proxy;
38  friend class observer_list;
40 
42 
44 
46 
48 
49 public:
51 
55  void __TBB_EXPORTED_METHOD observe( bool state=true );
56 
58  bool is_observing() const {return my_proxy!=NULL;}
59 
62 
64 
71  virtual void on_scheduler_entry( bool /*is_worker*/ ) {}
72 
74 
79  virtual void on_scheduler_exit( bool /*is_worker*/ ) {}
80 
82  virtual ~task_scheduler_observer_v3() { if(my_proxy) observe(false);}
83 };
84 
85 } // namespace internal
86 
87 #if __TBB_ARENA_OBSERVER
88 namespace interface6 {
89 class task_scheduler_observer : public internal::task_scheduler_observer_v3 {
93 
96  // TODO: take more high bits for version number
97  static const intptr_t v6_trait = (intptr_t)((~(uintptr_t)0 >> 1) + 1);
98 
100  intptr_t my_context_tag;
101  enum { global_tag = 0, implicit_tag = 1 };
102 
103 public:
105 
114  explicit task_scheduler_observer( bool local = false ) {
115 #if __TBB_ARENA_OBSERVER
117 #else
118  __TBB_ASSERT_EX( !local, NULL );
120 #endif
121  }
122 
123 #if __TBB_ARENA_OBSERVER
124 
129  my_context_tag = (intptr_t)&a;
130  }
131 #endif /* __TBB_ARENA_OBSERVER */
132 
136  virtual ~task_scheduler_observer() { if(my_proxy) observe(false); }
137 
139 
141  void observe( bool state=true ) {
142  if( state && !my_proxy ) {
143  __TBB_ASSERT( !my_busy_count, "Inconsistent state of task_scheduler_observer instance");
145  }
147  }
148 };
149 
150 } //namespace interface6
151 using interface6::task_scheduler_observer;
152 #else /*__TBB_ARENA_OBSERVER*/
153 typedef tbb::internal::task_scheduler_observer_v3 task_scheduler_observer;
154 #endif /*__TBB_ARENA_OBSERVER*/
155 
156 } // namespace tbb
157 
158 #endif /* __TBB_SCHEDULER_OBSERVER */
159 
160 #endif /* __TBB_task_scheduler_observer_H */
virtual void on_scheduler_exit(bool)
Exit notification.
#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
void store(value_type value)
Definition: atomic.h:313
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
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
bool is_observing() const
Returns true if observation is enabled, false otherwise.
The graph class.
void observe(bool state=true)
Enable or disable observation.
intptr_t my_context_tag
contains task_arena pointer or tag indicating local or global semantics of the observer
observer_proxy * my_proxy
Pointer to the proxy holding this observer.
task_scheduler_observer(task_arena &a)
Construct local observer for a given arena in inactive state (observation disabled).
virtual ~task_scheduler_observer_v3()
Destructor automatically switches observation off if it is enabled.
No ordering.
Definition: atomic.h:47
task_scheduler_observer(bool local=false)
Construct local or global observer in inactive state (observation disabled).
task_scheduler_observer_v3()
Construct observer with observation disabled.
virtual void on_scheduler_entry(bool)
Entry notification.
void __TBB_EXPORTED_METHOD observe(bool state=true)
Enable or disable observation.

Copyright © 2005-2019 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.