]> git.sesse.net Git - casparcg/blob - tbb30_20100406oss/include/tbb/task_scheduler_observer.h
61003e524db4d637d872ce58626cdfa36370b8c8
[casparcg] / tbb30_20100406oss / include / tbb / task_scheduler_observer.h
1 /*
2     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
3
4     This file is part of Threading Building Blocks.
5
6     Threading Building Blocks is free software; you can redistribute it
7     and/or modify it under the terms of the GNU General Public License
8     version 2 as published by the Free Software Foundation.
9
10     Threading Building Blocks is distributed in the hope that it will be
11     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with Threading Building Blocks; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19     As a special exception, you may use this file as part of a free software
20     library without restriction.  Specifically, if other files instantiate
21     templates or use macros or inline functions from this file, or you compile
22     this file and link it with other files to produce an executable, this
23     file does not by itself cause the resulting executable to be covered by
24     the GNU General Public License.  This exception does not however
25     invalidate any other reasons why the executable file might be covered by
26     the GNU General Public License.
27 */
28
29 #ifndef __TBB_task_scheduler_observer_H
30 #define __TBB_task_scheduler_observer_H
31
32 #include "atomic.h"
33
34 #if __TBB_SCHEDULER_OBSERVER
35
36 namespace tbb {
37
38 namespace internal {
39
40 class observer_proxy;
41
42 class task_scheduler_observer_v3 {
43     friend class observer_proxy;
44     observer_proxy* my_proxy;
45     atomic<intptr_t> my_busy_count;
46 public:
47     //! Enable or disable observation
48     void __TBB_EXPORTED_METHOD observe( bool state=true );
49
50     //! True if observation is enables; false otherwise.
51     bool is_observing() const {return my_proxy!=NULL;}
52
53     //! Construct observer with observation disabled.
54     task_scheduler_observer_v3() : my_proxy(NULL) {my_busy_count=0;}
55
56     //! Called by thread before first steal since observation became enabled
57     virtual void on_scheduler_entry( bool /*is_worker*/ ) {} 
58
59     //! Called by thread when it no longer takes part in task stealing.
60     virtual void on_scheduler_exit( bool /*is_worker*/ ) {}
61
62     //! Destructor
63     virtual ~task_scheduler_observer_v3() {observe(false);}
64 };
65
66 } // namespace internal
67
68 typedef internal::task_scheduler_observer_v3 task_scheduler_observer;
69
70 } // namespace tbb
71
72 #endif /* __TBB_SCHEDULER_OBSERVER */
73
74 #endif /* __TBB_task_scheduler_observer_H */