task_scheduler_observer.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_task_scheduler_observer_H
#define __TBB_task_scheduler_observer_H
#define __TBB_task_scheduler_observer_H_include_area
#include "internal/_warning_suppress_enable_notice.h"
#include "atomic.h"
#if __TBB_ARENA_OBSERVER
#include "task_arena.h"
#endif
#if __TBB_SCHEDULER_OBSERVER
namespace tbb {
namespace interface6 {
class task_scheduler_observer;
}
namespace internal {
class observer_proxy;
class observer_list;
class task_scheduler_observer_v3 {
friend class observer_proxy;
friend class observer_list;
friend class interface6::task_scheduler_observer;
observer_proxy* my_proxy;
atomic<intptr_t> my_busy_count;
public:
void __TBB_EXPORTED_METHOD observe( bool state=true );
bool is_observing() const {return my_proxy!=NULL;}
task_scheduler_observer_v3() : my_proxy(NULL) { my_busy_count.store<relaxed>(0); }
virtual void on_scheduler_entry( bool /*is_worker*/ ) {}
virtual void on_scheduler_exit( bool /*is_worker*/ ) {}
virtual ~task_scheduler_observer_v3() { if(my_proxy) observe(false);}
};
} // namespace internal
#if __TBB_ARENA_OBSERVER
namespace interface6 {
class task_scheduler_observer : public internal::task_scheduler_observer_v3 {
friend class internal::task_scheduler_observer_v3;
friend class internal::observer_proxy;
friend class internal::observer_list;
// TODO: take more high bits for version number
static const intptr_t v6_trait = (intptr_t)((~(uintptr_t)0 >> 1) + 1);
intptr_t my_context_tag;
enum { global_tag = 0, implicit_tag = 1 };
public:
explicit task_scheduler_observer( bool local = false ) {
#if __TBB_ARENA_OBSERVER
my_context_tag = local? implicit_tag : global_tag;
#else
__TBB_ASSERT_EX( !local, NULL );
my_context_tag = global_tag;
#endif
}
#if __TBB_ARENA_OBSERVER
explicit task_scheduler_observer( task_arena & a) {
my_context_tag = (intptr_t)&a;
}
#endif /* __TBB_ARENA_OBSERVER */
virtual ~task_scheduler_observer() { if(my_proxy) observe(false); }
void observe( bool state=true ) {
if( state && !my_proxy ) {
__TBB_ASSERT( !my_busy_count, "Inconsistent state of task_scheduler_observer instance");
my_busy_count.store<relaxed>(v6_trait);
}
internal::task_scheduler_observer_v3::observe(state);
}
};
} //namespace interface6
using interface6::task_scheduler_observer;
#else /*__TBB_ARENA_OBSERVER*/
typedef tbb::internal::task_scheduler_observer_v3 task_scheduler_observer;
#endif /*__TBB_ARENA_OBSERVER*/
} // namespace tbb
#endif /* __TBB_SCHEDULER_OBSERVER */
#include "internal/_warning_suppress_disable_notice.h"
#undef __TBB_task_scheduler_observer_H_include_area
#endif /* __TBB_task_scheduler_observer_H */
tbb::internal::task_scheduler_observer_v3::task_scheduler_observer_v3
task_scheduler_observer_v3()
Construct observer with observation disabled.
Definition: task_scheduler_observer.h:64
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::relaxed
No ordering.
Definition: atomic.h:61
task_arena.h
tbb::interface6::task_scheduler_observer::task_scheduler_observer
task_scheduler_observer(task_arena &a)
Construct local observer for a given arena in inactive state (observation disabled).
Definition: task_scheduler_observer.h:131
__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
tbb::internal::task_scheduler_observer_v3::is_observing
bool is_observing() const
Returns true if observation is enabled, false otherwise.
Definition: task_scheduler_observer.h:61
tbb::interface6::task_scheduler_observer::v6_trait
static const intptr_t v6_trait
Definition: task_scheduler_observer.h:100
tbb::internal::task_scheduler_observer_v3::observe
void __TBB_EXPORTED_METHOD observe(bool state=true)
Enable or disable observation.
tbb::interface6::task_scheduler_observer
Definition: task_scheduler_observer.h:92
tbb::internal::task_scheduler_observer_v3::on_scheduler_exit
virtual void on_scheduler_exit(bool)
Exit notification.
Definition: task_scheduler_observer.h:82
tbb::interface6::task_scheduler_observer::implicit_tag
Definition: task_scheduler_observer.h:104
tbb::internal::task_scheduler_observer_v3::my_busy_count
atomic< intptr_t > my_busy_count
Counter preventing the observer from being destroyed while in use by the scheduler.
Definition: task_scheduler_observer.h:50
tbb::internal::task_scheduler_observer_v3::observer_list
friend class observer_list
Definition: task_scheduler_observer.h:41
tbb::internal::task_scheduler_observer_v3
Definition: task_scheduler_observer.h:39
atomic.h
tbb::interface6::task_scheduler_observer::my_context_tag
intptr_t my_context_tag
contains task_arena pointer or tag indicating local or global semantics of the observer
Definition: task_scheduler_observer.h:103
tbb::internal::task_scheduler_observer_v3::observer_proxy
friend class observer_proxy
Definition: task_scheduler_observer.h:40
_warning_suppress_disable_notice.h
tbb::interface6::task_scheduler_observer::~task_scheduler_observer
virtual ~task_scheduler_observer()
Definition: task_scheduler_observer.h:139
tbb::interface6::task_scheduler_observer::observer_list
friend class internal::observer_list
Definition: task_scheduler_observer.h:95
tbb::internal::task_scheduler_observer_v3::on_scheduler_entry
virtual void on_scheduler_entry(bool)
Entry notification.
Definition: task_scheduler_observer.h:74
tbb::interface6::task_scheduler_observer::observe
void observe(bool state=true)
Enable or disable observation.
Definition: task_scheduler_observer.h:144
tbb::interface6::task_scheduler_observer::observer_proxy
friend class internal::observer_proxy
Definition: task_scheduler_observer.h:94
_warning_suppress_enable_notice.h
__TBB_EXPORTED_METHOD
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
tbb::internal::task_scheduler_observer_v3::my_proxy
observer_proxy * my_proxy
Pointer to the proxy holding this observer.
Definition: task_scheduler_observer.h:46
tbb::interface7::task_arena
Definition: task_arena.h:228
tbb::interface6::task_scheduler_observer::task_scheduler_observer
task_scheduler_observer(bool local=false)
Construct local or global observer in inactive state (observation disabled).
Definition: task_scheduler_observer.h:117
tbb::internal::task_scheduler_observer_v3::~task_scheduler_observer_v3
virtual ~task_scheduler_observer_v3()
Destructor automatically switches observation off if it is enabled.
Definition: task_scheduler_observer.h:85
__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
tbb::interface6::task_scheduler_observer::global_tag
Definition: task_scheduler_observer.h:104

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.