Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
observer_proxy.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_observer_proxy_H
18#define _TBB_observer_proxy_H
19
20#if __TBB_SCHEDULER_OBSERVER
21
22#include "scheduler_common.h" // to include task.h
24#include "tbb/spin_rw_mutex.h"
25#include "tbb/aligned_space.h"
26
27namespace tbb {
28namespace internal {
29
30class observer_list {
31 friend class arena;
32
33 // Mutex is wrapped with aligned_space to shut up warnings when its destructor
34 // is called while threads are still using it.
35 typedef aligned_space<spin_rw_mutex> my_mutex_type;
36
38 observer_proxy* my_head;
39
41 observer_proxy* my_tail;
42
44 my_mutex_type my_mutex;
45
47 arena* my_arena;
48
50
51 inline static void remove_ref_fast( observer_proxy*& p );
52
54 void do_notify_entry_observers( observer_proxy*& last, bool worker );
55
57 void do_notify_exit_observers( observer_proxy* last, bool worker );
58
59public:
60 observer_list () : my_head(NULL), my_tail(NULL) {}
61
63
64 void clear ();
65
67 void insert ( observer_proxy* p );
68
70 void remove ( observer_proxy* p );
71
73
74 void remove_ref( observer_proxy* p );
75
77 typedef spin_rw_mutex::scoped_lock scoped_lock;
78
80 spin_rw_mutex& mutex () { return my_mutex.begin()[0]; }
81
82 bool empty () const { return my_head == NULL; }
83
85
87 inline void notify_entry_observers( observer_proxy*& last, bool worker );
88
90 inline void notify_exit_observers( observer_proxy*& last, bool worker );
91}; // class observer_list
92
94
97class observer_proxy {
98 friend class task_scheduler_observer_v3;
99 friend class observer_list;
101
104 atomic<int> my_ref_count;
106 observer_list* my_list;
108
109 observer_proxy* my_next;
111
112 observer_proxy* my_prev;
114 task_scheduler_observer_v3* my_observer;
116 char my_version;
117
118#if __TBB_ARENA_OBSERVER
119 interface6::task_scheduler_observer* get_v6_observer();
120#endif
121#if __TBB_ARENA_OBSERVER
122 bool is_global(); //TODO: move them back inline when un-CPF'ing
123#endif
124
126 observer_proxy( task_scheduler_observer_v3& );
127
128#if TBB_USE_ASSERT
129 ~observer_proxy();
130#endif /* TBB_USE_ASSERT */
131
133 observer_proxy& operator = ( const observer_proxy& );
134}; // class observer_proxy
135
136inline void observer_list::remove_ref_fast( observer_proxy*& p ) {
137 if( p->my_observer ) {
138 // Can decrement refcount quickly, as it cannot drop to zero while under the lock.
139 int r = --p->my_ref_count;
140 __TBB_ASSERT_EX( r, NULL );
141 p = NULL;
142 } else {
143 // Use slow form of refcount decrementing, after the lock is released.
144 }
145}
146
147inline void observer_list::notify_entry_observers( observer_proxy*& last, bool worker ) {
148 if ( last == my_tail )
149 return;
150 do_notify_entry_observers( last, worker );
151}
152
153inline void observer_list::notify_exit_observers( observer_proxy*& last, bool worker ) {
154 if ( !last )
155 return;
156 __TBB_ASSERT(is_alive((uintptr_t)last), NULL);
157 do_notify_exit_observers( last, worker );
158 __TBB_ASSERT(last, NULL);
160}
161
162extern padded<observer_list> the_global_observer_list;
163
164} // namespace internal
165} // namespace tbb
166
167#endif /* __TBB_SCHEDULER_OBSERVER */
168
169#endif /* _TBB_observer_proxy_H */
#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
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define poison_value(g)
void const char const char int ITT_FORMAT __itt_group_sync p
The graph class.
spin_rw_mutex_v3 spin_rw_mutex
Definition: spin_rw_mutex.h:33
auto last(Container &c) -> decltype(begin(c))

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.