annotate libcilkrts/runtime/cilk-tbb-interop.h @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* cilk-tbb-interop.h -*-C++-*-
kono
parents:
diff changeset
2 *
kono
parents:
diff changeset
3 *************************************************************************
kono
parents:
diff changeset
4 *
kono
parents:
diff changeset
5 * Copyright (C) 2009-2016, Intel Corporation
kono
parents:
diff changeset
6 * All rights reserved.
kono
parents:
diff changeset
7 *
kono
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
9 * modification, are permitted provided that the following conditions
kono
parents:
diff changeset
10 * are met:
kono
parents:
diff changeset
11 *
kono
parents:
diff changeset
12 * * Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
14 * * Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in
kono
parents:
diff changeset
16 * the documentation and/or other materials provided with the
kono
parents:
diff changeset
17 * distribution.
kono
parents:
diff changeset
18 * * Neither the name of Intel Corporation nor the names of its
kono
parents:
diff changeset
19 * contributors may be used to endorse or promote products derived
kono
parents:
diff changeset
20 * from this software without specific prior written permission.
kono
parents:
diff changeset
21 *
kono
parents:
diff changeset
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
kono
parents:
diff changeset
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
kono
parents:
diff changeset
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
kono
parents:
diff changeset
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
kono
parents:
diff changeset
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
kono
parents:
diff changeset
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
kono
parents:
diff changeset
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
kono
parents:
diff changeset
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
kono
parents:
diff changeset
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
kono
parents:
diff changeset
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
kono
parents:
diff changeset
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
kono
parents:
diff changeset
33 * POSSIBILITY OF SUCH DAMAGE.
kono
parents:
diff changeset
34 *
kono
parents:
diff changeset
35 * *********************************************************************
kono
parents:
diff changeset
36 *
kono
parents:
diff changeset
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
kono
parents:
diff changeset
38 * a repository at cilkplus.org. Changes made to this file that are not
kono
parents:
diff changeset
39 * submitted through the contribution process detailed at
kono
parents:
diff changeset
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
kono
parents:
diff changeset
41 * time that a new version is released. Changes only submitted to the
kono
parents:
diff changeset
42 * GNU compiler collection or posted to the git repository at
kono
parents:
diff changeset
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
kono
parents:
diff changeset
44 * not tracked.
kono
parents:
diff changeset
45 *
kono
parents:
diff changeset
46 * We welcome your contributions to this open source project. Thank you
kono
parents:
diff changeset
47 * for your assistance in helping us improve Cilk Plus.
kono
parents:
diff changeset
48 **************************************************************************/
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /**
kono
parents:
diff changeset
51 * @file cilk-tbb-interop.h
kono
parents:
diff changeset
52 *
kono
parents:
diff changeset
53 * @brief Interface between TBB and Cilk to allow TBB to associate it's
kono
parents:
diff changeset
54 * per-thread data with Cilk workers, and maintain the association as work
kono
parents:
diff changeset
55 * moves between worker threads. This handles the case where TBB calls
kono
parents:
diff changeset
56 * into a Cilk function which may later call back to a function making
kono
parents:
diff changeset
57 * TBB calls.
kono
parents:
diff changeset
58 *
kono
parents:
diff changeset
59 * Each thunk structure has two pointers: \"routine\" and \"data\".
kono
parents:
diff changeset
60 * The caller of the thunk invokes *routine, passing \"data\" as the void*
kono
parents:
diff changeset
61 * parameter.
kono
parents:
diff changeset
62 */
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 #ifndef INCLUDED_CILK_TBB_INTEROP_DOT_H
kono
parents:
diff changeset
65 #define INCLUDED_CILK_TBB_INTEROP_DOT_H
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 #include <cilk/common.h> // for CILK_EXPORT
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 __CILKRTS_BEGIN_EXTERN_C
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 /** A return code. 0 indicates success. */
kono
parents:
diff changeset
72 typedef int __cilk_tbb_retcode;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 /**
kono
parents:
diff changeset
75 * Enumeration of reasons that Cilk will call the TBB stack operation
kono
parents:
diff changeset
76 * function.
kono
parents:
diff changeset
77 *
kono
parents:
diff changeset
78 * When a non-empty stack is transfered between threads, the first thread must
kono
parents:
diff changeset
79 * orphan it and the second thread must adopt it.
kono
parents:
diff changeset
80 *
kono
parents:
diff changeset
81 * An empty stack can be transfered similarly, or simply released by the first
kono
parents:
diff changeset
82 * thread.
kono
parents:
diff changeset
83 *
kono
parents:
diff changeset
84 * Here is a summary of the actions as transitions on a state machine.
kono
parents:
diff changeset
85 @verbatim
kono
parents:
diff changeset
86 watch ORPHAN
kono
parents:
diff changeset
87 -->--> -->--
kono
parents:
diff changeset
88 / \ / \
kono
parents:
diff changeset
89 (freed empty stack) (TBB sees stack running on thread) (stack in limbo)
kono
parents:
diff changeset
90 \ / \ /
kono
parents:
diff changeset
91 --<-- --<--
kono
parents:
diff changeset
92 RELEASE or ADOPT
kono
parents:
diff changeset
93 unwatch
kono
parents:
diff changeset
94 @endverbatim
kono
parents:
diff changeset
95 */
kono
parents:
diff changeset
96 typedef enum __cilk_tbb_stack_op {
kono
parents:
diff changeset
97 /**
kono
parents:
diff changeset
98 * Disconnecting stack from a thread.
kono
parents:
diff changeset
99 *
kono
parents:
diff changeset
100 * The thunk must be invoked on the thread disconnecting itself from the
kono
parents:
diff changeset
101 * stack. Must \"happen before\" the stack is adopted elsewhere.
kono
parents:
diff changeset
102 */
kono
parents:
diff changeset
103 CILK_TBB_STACK_ORPHAN,
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 /**
kono
parents:
diff changeset
106 * Reconnecting orphaned stack to a thread.
kono
parents:
diff changeset
107 *
kono
parents:
diff changeset
108 * The thunk must be invoked on the thread adopting the stack.
kono
parents:
diff changeset
109 */
kono
parents:
diff changeset
110 CILK_TBB_STACK_ADOPT,
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 /**
kono
parents:
diff changeset
113 * Releasing stack.
kono
parents:
diff changeset
114 *
kono
parents:
diff changeset
115 * The thunk must be invoked on the thread doing the releasing, Must
kono
parents:
diff changeset
116 * \"happen before\" the stack is used elsewhere.
kono
parents:
diff changeset
117 */
kono
parents:
diff changeset
118 CILK_TBB_STACK_RELEASE
kono
parents:
diff changeset
119 } __cilk_tbb_stack_op;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 /**
kono
parents:
diff changeset
122 * Function that will be called by the Cilk runtime to inform TBB of a change
kono
parents:
diff changeset
123 * in the stack associated with the current thread.
kono
parents:
diff changeset
124 *
kono
parents:
diff changeset
125 * It does not matter what stack the thunk runs on.
kono
parents:
diff changeset
126 * The thread (not fiber) on which the thunk runs is important.
kono
parents:
diff changeset
127 *
kono
parents:
diff changeset
128 * @param op Enumerated value indicating what type of change is ocurring.
kono
parents:
diff changeset
129 * @param data Context value provided by TBB in the __cilkrts_watch_stack
kono
parents:
diff changeset
130 * call. This data is opaque to Cilk.
kono
parents:
diff changeset
131 *
kono
parents:
diff changeset
132 * @return 0 indicates success.
kono
parents:
diff changeset
133 */
kono
parents:
diff changeset
134 typedef __cilk_tbb_retcode (*__cilk_tbb_pfn_stack_op)(enum __cilk_tbb_stack_op op,
kono
parents:
diff changeset
135 void* data);
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 /**
kono
parents:
diff changeset
138 * Function that will be called by TBB to inform the Cilk runtime that TBB
kono
parents:
diff changeset
139 * is no longer interested in watching the stack bound to the current thread.
kono
parents:
diff changeset
140 *
kono
parents:
diff changeset
141 * @param data Context value provided to TBB by the __cilkrts_watch_stack
kono
parents:
diff changeset
142 * call. This data is opaque to TBB.
kono
parents:
diff changeset
143 *
kono
parents:
diff changeset
144 * @return 0 indicates success.
kono
parents:
diff changeset
145 */
kono
parents:
diff changeset
146 typedef __cilk_tbb_retcode (*__cilk_tbb_pfn_unwatch_stacks)(void *data);
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 /**
kono
parents:
diff changeset
149 * Thunk invoked by Cilk to call back to TBB to tell it about a change in
kono
parents:
diff changeset
150 * the stack bound to the current thread.
kono
parents:
diff changeset
151 */
kono
parents:
diff changeset
152 typedef struct __cilk_tbb_stack_op_thunk {
kono
parents:
diff changeset
153 /// Function in TBB the Cilk runtime should call when something
kono
parents:
diff changeset
154 // "interesting" happens involving a stack
kono
parents:
diff changeset
155 __cilk_tbb_pfn_stack_op routine;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 /// TBB context data to pass with the call to the stack_op routine
kono
parents:
diff changeset
158 void* data;
kono
parents:
diff changeset
159 } __cilk_tbb_stack_op_thunk;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /**
kono
parents:
diff changeset
162 * Thunk invoked by TBB when it is no longer interested in watching the stack
kono
parents:
diff changeset
163 * bound to the current thread.
kono
parents:
diff changeset
164 */
kono
parents:
diff changeset
165 typedef struct __cilk_tbb_unwatch_thunk {
kono
parents:
diff changeset
166 /// Function in Cilk runtime to call when TBB no longer wants to watch
kono
parents:
diff changeset
167 // stacks
kono
parents:
diff changeset
168 __cilk_tbb_pfn_unwatch_stacks routine;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 /// Cilk runtime context data to pass with the call to the unwatch_stacks
kono
parents:
diff changeset
171 /// routine
kono
parents:
diff changeset
172 void* data;
kono
parents:
diff changeset
173 } __cilk_tbb_unwatch_thunk;
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 /**
kono
parents:
diff changeset
176 * Requests that Cilk invoke __cilk_tbb_orphan_thunk when it orphans a stack.
kono
parents:
diff changeset
177 * Cilk sets *u to a thunk that TBB should call when it is no longer
kono
parents:
diff changeset
178 * interested in watching the stack.
kono
parents:
diff changeset
179 *
kono
parents:
diff changeset
180 * If the thread is not yet bound to the Cilk runtime, the Cilk runtime should
kono
parents:
diff changeset
181 * save this data in thread-local storage until __cilkrts_bind_thread is called.
kono
parents:
diff changeset
182 *
kono
parents:
diff changeset
183 * Called by TBB, defined by Cilk. This function is exported from the Cilk
kono
parents:
diff changeset
184 * runtime DLL/shared object. This declaration also appears in
kono
parents:
diff changeset
185 * cilk/cilk_undocumented.h -- don't change one declaration without also
kono
parents:
diff changeset
186 * changing the other.
kono
parents:
diff changeset
187 *
kono
parents:
diff changeset
188 * @param u __cilk_tbb_unwatch_thunk. This structure will be filled in by
kono
parents:
diff changeset
189 * the Cilk runtime to allow TBB to register that it is no longer interested
kono
parents:
diff changeset
190 * in watching the stack bound to the current thread.
kono
parents:
diff changeset
191 * @param o __cilk_tbb_stack_op_thunk. This structure specifies the routine
kono
parents:
diff changeset
192 * that the Cilk runtime should call when an "interesting" change in the stack
kono
parents:
diff changeset
193 * associate with the current worker occurs.
kono
parents:
diff changeset
194 *
kono
parents:
diff changeset
195 * @return 0 indicates success.
kono
parents:
diff changeset
196 */
kono
parents:
diff changeset
197 CILK_EXPORT
kono
parents:
diff changeset
198 __cilk_tbb_retcode __cilkrts_watch_stack(__cilk_tbb_unwatch_thunk* u,
kono
parents:
diff changeset
199 __cilk_tbb_stack_op_thunk o);
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 __CILKRTS_END_EXTERN_C
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 #endif // ! defined(INCLUDED_CILK_TBB_INTEROP_DOT_H)