2014-05-21 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libcilkrts / runtime / pedigrees.c
blobdee4d9cb4112777b9d25171b84c3bbc93266f27a
1 /* pedigrees.c -*-C-*-
3 *************************************************************************
5 * @copyright
6 * Copyright (C) 2007-2013, Intel Corporation
7 * All rights reserved.
8 *
9 * @copyright
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * * Neither the name of Intel Corporation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * @copyright
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
38 **************************************************************************/
40 #include "pedigrees.h"
41 #include "local_state.h"
43 /*************************************************************
44 Pedigree API code.
45 *************************************************************/
48 * C99 requires that every inline function with external linkage have one
49 * extern declaration in the program (with the inline definition in scope).
51 COMMON_PORTABLE
52 extern void update_pedigree_on_leave_frame(__cilkrts_worker *w,
53 __cilkrts_stack_frame *sf);
55 void __cilkrts_set_pedigree_leaf(__cilkrts_pedigree *leaf)
57 __cilkrts_set_tls_pedigree_leaf(leaf);
60 void load_pedigree_leaf_into_user_worker(__cilkrts_worker *w)
62 __cilkrts_pedigree *pedigree_leaf;
63 CILK_ASSERT(w->l->type == WORKER_USER);
64 pedigree_leaf = __cilkrts_get_tls_pedigree_leaf(1);
65 w->pedigree = *pedigree_leaf;
67 // Save a pointer to the old leaf.
68 // We'll need to restore it later.
69 CILK_ASSERT(w->l->original_pedigree_leaf == NULL);
70 w->l->original_pedigree_leaf = pedigree_leaf;
72 __cilkrts_set_tls_pedigree_leaf(&w->pedigree);
74 // Check that this new pedigree root has at least two values.
75 CILK_ASSERT(w->pedigree.parent);
76 CILK_ASSERT(w->pedigree.parent->parent == NULL);
79 void save_pedigree_leaf_from_user_worker(__cilkrts_worker *w)
81 CILK_ASSERT(w->l->type == WORKER_USER);
83 // Existing leaf in tls should be for the current worker.
84 // This assert is expensive to check though.
85 // CILK_ASSERT(&w->pedigree == __cilkrts_get_tls_pedigree_leaf(0));
86 CILK_ASSERT(w->l->original_pedigree_leaf);
88 // w should finish with a pedigree node that points to
89 // the same root that we just looked up.
91 // TODO: This assert should be valid.
92 // But we are removing it now to make exceptions (without pedigrees) work.
93 // Currently, reading the pedigree after an exception is caught
94 // fails because the pedigree chain not restored correctly.
95 // CILK_ASSERT(w->l->original_pedigree_leaf->next == w->pedigree.parent);
96 w->l->original_pedigree_leaf->rank = w->pedigree.rank;
98 // Save that leaf pointer back into tls.
99 __cilkrts_set_tls_pedigree_leaf(w->l->original_pedigree_leaf);
100 // Null out worker's leaf for paranoia.
101 w->l->original_pedigree_leaf = NULL;
107 Local Variables: **
108 c-file-style:"bsd" **
109 c-basic-offset:4 **
110 indent-tabs-mode:nil **
111 End: **