- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# task_scheduler_observer.h

    00001 /*
    00002     Copyright 2005-2012 Intel Corporation.  All Rights Reserved.
    00003
    00004     This file is part of Threading Building Blocks.
    00005
    00006     Threading Building Blocks is free software; you can redistribute it
    00007     and/or modify it under the terms of the GNU General Public License
    00008     version 2 as published by the Free Software Foundation.
    00009
    00010     Threading Building Blocks is distributed in the hope that it will be
    00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
    00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013     GNU General Public License for more details.
    00014
    00015     You should have received a copy of the GNU General Public License
    00016     along with Threading Building Blocks; if not, write to the Free Software
    00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    00018
    00019     As a special exception, you may use this file as part of a free software
    00020     library without restriction.  Specifically, if other files instantiate
    00021     templates or use macros or inline functions from this file, or you compile
    00022     this file and link it with other files to produce an executable, this
    00023     file does not by itself cause the resulting executable to be covered by
    00024     the GNU General Public License.  This exception does not however
    00025     invalidate any other reasons why the executable file might be covered by
    00026     the GNU General Public License.
    00027 */
    00028
    00029 #ifndef __TBB_task_scheduler_observer_H
    00030 #define __TBB_task_scheduler_observer_H
    00031
    00032 #include "atomic.h"
    00033 #if __TBB_TASK_ARENA
    00034 #include "task_arena.h"
    00035 #endif //__TBB_TASK_ARENA
    00036
    00037 #if __TBB_SCHEDULER_OBSERVER
    00038
    00039 namespace tbb {
    00040 namespace interface6 {
    00041 class task_scheduler_observer;
    00042 }
    00043 namespace internal {
    00044
    00045 class observer_proxy;
    00046 class observer_list;
    00047
    00048 class task_scheduler_observer_v3 {
    00049     friend class observer_proxy;
    00050     friend class observer_list;
    00051     friend class interface6::task_scheduler_observer;
    00052
    00054
    00055     observer_proxy* my_proxy;
    00056
    00058
    00059     atomic<intptr_t> my_busy_count;
    00060
    00061 public:
    00063
    00067     void __TBB_EXPORTED_METHOD observe( bool state=true );
    00068
    00070     bool is_observing() const {return my_proxy!=NULL;}
    00071
    00073     task_scheduler_observer_v3() : my_proxy(NULL) { my_busy_count.store<relaxed>(0); }
    00074
    00076
    00083     virtual void on_scheduler_entry( bool /*is_worker*/ ) {}
    00084
    00086
    00091     virtual void on_scheduler_exit( bool /*is_worker*/ ) {}
    00092
    00094     virtual ~task_scheduler_observer_v3() { if(my_proxy) observe(false);}
    00095 };
    00096
    00097 } // namespace internal
    00098
    00099 #if TBB_PREVIEW_LOCAL_OBSERVER
    00100 namespace interface6 {
    00101 class task_scheduler_observer : public internal::task_scheduler_observer_v3 {
    00102     friend class internal::task_scheduler_observer_v3;
    00103     friend class internal::observer_proxy;
    00104     friend class internal::observer_list;
    00105
    00108     // TODO: take more high bits for version number
    00109     static const intptr_t v6_trait = (intptr_t)((~(uintptr_t)0 >> 1) + 1);
    00110
    00112     intptr_t my_context_tag;
    00113     enum { global_tag = 0, implicit_tag = 1 };
    00114
    00115 public:
    00117
    00126     task_scheduler_observer( bool local = false ) {
    00127         my_busy_count.store<relaxed>(v6_trait);
    00128         my_context_tag = local? implicit_tag : global_tag;
    00129     }
    00130
    00131 #if __TBB_TASK_ARENA
    00133
    00136     task_scheduler_observer( task_arena & a) {
    00137         my_busy_count.store<relaxed>(v6_trait);
    00138         my_context_tag = (intptr_t)&a;
    00139     }
    00140 #endif //__TBB_TASK_ARENA
    00141
    00143
    00146     virtual bool on_scheduler_leaving() { return true; }
    00147
    00149     // It is recommended to disable observation before destructor of a derived class starts,
    00150     // otherwise it can lead to concurrent notification callback on partly destroyed object
    00151     virtual ~task_scheduler_observer() { if(my_proxy) observe(false);}
    00152 };
    00153
    00154 } //namespace interface6
    00155 using interface6::task_scheduler_observer;
    00156 #else /*TBB_PREVIEW_LOCAL_OBSERVER*/
    00157 typedef tbb::internal::task_scheduler_observer_v3 task_scheduler_observer;
    00158 #endif /*TBB_PREVIEW_LOCAL_OBSERVER*/
    00159
    00160 } // namespace tbb
    00161
    00162 #endif /* __TBB_SCHEDULER_OBSERVER */
    00163
    00164 #endif /* __TBB_task_scheduler_observer_H */

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