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 
18 
19 */
20 
21 #ifndef __TBB_task_scheduler_observer_H
22 #define __TBB_task_scheduler_observer_H
23 
24 #include "atomic.h"
25 #if __TBB_ARENA_OBSERVER
26 #include "task_arena.h"
27 #endif
28 
29 #if __TBB_SCHEDULER_OBSERVER
30 
31 namespace tbb {
32 namespace interface6 {
33 class task_scheduler_observer;
34 }
35 namespace internal {
36 
37 class observer_proxy;
38 class observer_list;
39 
41  friend class observer_proxy;
42  friend class observer_list;
44 
46 
48 
50 
52 
53 public:
55 
59  void __TBB_EXPORTED_METHOD observe( bool state=true );
60 
62  bool is_observing() const {return my_proxy!=NULL;}
63 
66 
68 
75  virtual void on_scheduler_entry( bool /*is_worker*/ ) {}
76 
78 
83  virtual void on_scheduler_exit( bool /*is_worker*/ ) {}
84 
86  virtual ~task_scheduler_observer_v3() { if(my_proxy) observe(false);}
87 };
88 
89 } // namespace internal
90 
91 #if __TBB_ARENA_OBSERVER
92 namespace interface6 {
93 class task_scheduler_observer : public internal::task_scheduler_observer_v3 {
97 
100  // TODO: take more high bits for version number
101  static const intptr_t v6_trait = (intptr_t)((~(uintptr_t)0 >> 1) + 1);
102 
104  intptr_t my_context_tag;
105  enum { global_tag = 0, implicit_tag = 1 };
106 
107 public:
109 
118  explicit task_scheduler_observer( bool local = false ) {
119 #if __TBB_ARENA_OBSERVER
121 #else
122  __TBB_ASSERT_EX( !local, NULL );
124 #endif
125  }
126 
127 #if __TBB_ARENA_OBSERVER
128 
133  my_context_tag = (intptr_t)&a;
134  }
135 #endif /* __TBB_ARENA_OBSERVER */
136 
140  virtual ~task_scheduler_observer() { if(my_proxy) observe(false); }
141 
143 
145  void observe( bool state=true ) {
146  if( state && !my_proxy ) {
147  __TBB_ASSERT( !my_busy_count, "Inconsistent state of task_scheduler_observer instance");
149  }
151  }
152 };
153 
154 } //namespace interface6
155 using interface6::task_scheduler_observer;
156 #else /*__TBB_ARENA_OBSERVER*/
157 typedef tbb::internal::task_scheduler_observer_v3 task_scheduler_observer;
158 #endif /*__TBB_ARENA_OBSERVER*/
159 
160 } // namespace tbb
161 
162 #endif /* __TBB_SCHEDULER_OBSERVER */
163 
164 #endif /* __TBB_task_scheduler_observer_H */
virtual void on_scheduler_entry(bool)
Entry notification.
task_scheduler_observer(task_arena &a)
Construct local observer for a given arena in inactive state (observation disabled).
No ordering.
Definition: atomic.h:51
intptr_t my_context_tag
contains task_arena pointer or tag indicating local or global semantics of the observer
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
#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:171
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:102
The graph class.
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.
bool is_observing() const
Returns true if observation is enabled, false otherwise.
virtual ~task_scheduler_observer_v3()
Destructor automatically switches observation off if it is enabled.
task_scheduler_observer_v3()
Construct observer with observation disabled.
void __TBB_EXPORTED_METHOD observe(bool state=true)
Enable or disable observation.
virtual void on_scheduler_exit(bool)
Exit notification.
void observe(bool state=true)
Enable or disable observation.
void store(value_type value)
Definition: atomic.h:317
atomic< intptr_t > my_busy_count
Counter preventing the observer from being destroyed while in use by the scheduler.

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.