observer_proxy.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _TBB_observer_proxy_H
#define _TBB_observer_proxy_H
#if __TBB_SCHEDULER_OBSERVER
#include "scheduler_common.h" // to include task.h
#include "tbb/task_scheduler_observer.h"
#include "tbb/spin_rw_mutex.h"
#include "tbb/aligned_space.h"
namespace tbb {
namespace internal {
class observer_list {
friend class arena;
// Mutex is wrapped with aligned_space to shut up warnings when its destructor
// is called while threads are still using it.
typedef aligned_space<spin_rw_mutex> my_mutex_type;
observer_proxy* my_head;
observer_proxy* my_tail;
my_mutex_type my_mutex;
arena* my_arena;
inline static void remove_ref_fast( observer_proxy*& p );
void do_notify_entry_observers( observer_proxy*& last, bool worker );
void do_notify_exit_observers( observer_proxy* last, bool worker );
public:
observer_list () : my_head(NULL), my_tail(NULL) {}
void clear ();
void insert ( observer_proxy* p );
void remove ( observer_proxy* p );
void remove_ref( observer_proxy* p );
typedef spin_rw_mutex::scoped_lock scoped_lock;
spin_rw_mutex& mutex () { return my_mutex.begin()[0]; }
bool empty () const { return my_head == NULL; }
inline void notify_entry_observers( observer_proxy*& last, bool worker );
inline void notify_exit_observers( observer_proxy*& last, bool worker );
}; // class observer_list
class observer_proxy {
friend class task_scheduler_observer_v3;
friend class observer_list;
atomic<int> my_ref_count;
observer_list* my_list;
observer_proxy* my_next;
observer_proxy* my_prev;
task_scheduler_observer_v3* my_observer;
char my_version;
#if __TBB_ARENA_OBSERVER
interface6::task_scheduler_observer* get_v6_observer();
#endif
#if __TBB_ARENA_OBSERVER
bool is_global(); //TODO: move them back inline when un-CPF'ing
#endif
observer_proxy( task_scheduler_observer_v3& );
#if TBB_USE_ASSERT
~observer_proxy();
#endif /* TBB_USE_ASSERT */
observer_proxy& operator = ( const observer_proxy& );
}; // class observer_proxy
inline void observer_list::remove_ref_fast( observer_proxy*& p ) {
if( p->my_observer ) {
// Can decrement refcount quickly, as it cannot drop to zero while under the lock.
int r = --p->my_ref_count;
__TBB_ASSERT_EX( r, NULL );
p = NULL;
} else {
// Use slow form of refcount decrementing, after the lock is released.
}
}
inline void observer_list::notify_entry_observers( observer_proxy*& last, bool worker ) {
if ( last == my_tail )
return;
do_notify_entry_observers( last, worker );
}
inline void observer_list::notify_exit_observers( observer_proxy*& last, bool worker ) {
if ( !last )
return;
__TBB_ASSERT(is_alive((uintptr_t)last), NULL);
do_notify_exit_observers( last, worker );
__TBB_ASSERT(last, NULL);
poison_value(last);
}
extern padded<observer_list> the_global_observer_list;
} // namespace internal
} // namespace tbb
#endif /* __TBB_SCHEDULER_OBSERVER */
#endif /* _TBB_observer_proxy_H */
scheduler_common.h
internal
Definition: _flow_graph_async_msg_impl.h:24
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
task_scheduler_observer.h
spin_rw_mutex.h
tbb::spin_rw_mutex
spin_rw_mutex_v3 spin_rw_mutex
Definition: spin_rw_mutex.h:33
aligned_space.h
poison_value
#define poison_value(g)
Definition: scheduler_common.h:235
tbb::internal::last
auto last(Container &c) -> decltype(begin(c))
Definition: _range_iterator.h:40
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
__TBB_ASSERT_EX
#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

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.