1284990Scy/* pedigrees.c -*-C-*- 2284990Scy * 3284990Scy ************************************************************************* 4284990Scy * 5284990Scy * @copyright 6284990Scy * Copyright (C) 2007-2013, Intel Corporation 7284990Scy * All rights reserved. 8284990Scy * 9284990Scy * @copyright 10284990Scy * Redistribution and use in source and binary forms, with or without 11284990Scy * modification, are permitted provided that the following conditions 12284990Scy * are met: 13284990Scy * 14284990Scy * * Redistributions of source code must retain the above copyright 15289999Sglebius * notice, this list of conditions and the following disclaimer. 16289999Sglebius * * Redistributions in binary form must reproduce the above copyright 17289999Sglebius * notice, this list of conditions and the following disclaimer in 18289999Sglebius * the documentation and/or other materials provided with the 19289999Sglebius * distribution. 20289999Sglebius * * Neither the name of Intel Corporation nor the names of its 21289999Sglebius * contributors may be used to endorse or promote products derived 22289999Sglebius * from this software without specific prior written permission. 23289999Sglebius * 24289999Sglebius * @copyright 25289999Sglebius * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26289999Sglebius * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27284990Scy * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28284990Scy * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29289999Sglebius * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30294904Sdelphij * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31294904Sdelphij * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 32284990Scy * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 33284990Scy * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34284990Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 35284990Scy * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36289999Sglebius * POSSIBILITY OF SUCH DAMAGE. 37294904Sdelphij * 38294904Sdelphij **************************************************************************/ 39294904Sdelphij 40294904Sdelphij#include "pedigrees.h" 41294904Sdelphij#include "local_state.h" 42294904Sdelphij 43284990Scy/************************************************************* 44284990Scy Pedigree API code. 45289999Sglebius*************************************************************/ 46289999Sglebius 47294904Sdelphij/* 48294904Sdelphij * C99 requires that every inline function with external linkage have one 49294904Sdelphij * extern declaration in the program (with the inline definition in scope). 50294904Sdelphij */ 51294904SdelphijCOMMON_PORTABLE 52284990Scyextern void update_pedigree_on_leave_frame(__cilkrts_worker *w, 53284990Scy __cilkrts_stack_frame *sf); 54284990Scy 55284990Scyvoid __cilkrts_set_pedigree_leaf(__cilkrts_pedigree *leaf) 56284990Scy{ 57284990Scy __cilkrts_set_tls_pedigree_leaf(leaf); 58284990Scy} 59284990Scy 60284990Scyvoid load_pedigree_leaf_into_user_worker(__cilkrts_worker *w) 61284990Scy{ 62284990Scy __cilkrts_pedigree *pedigree_leaf; 63284990Scy CILK_ASSERT(w->l->type == WORKER_USER); 64284990Scy pedigree_leaf = __cilkrts_get_tls_pedigree_leaf(1); 65284990Scy w->pedigree = *pedigree_leaf; 66284990Scy 67284990Scy // Save a pointer to the old leaf. 68284990Scy // We'll need to restore it later. 69284990Scy CILK_ASSERT(w->l->original_pedigree_leaf == NULL); 70284990Scy w->l->original_pedigree_leaf = pedigree_leaf; 71289999Sglebius 72289999Sglebius __cilkrts_set_tls_pedigree_leaf(&w->pedigree); 73294904Sdelphij 74294904Sdelphij // Check that this new pedigree root has at least two values. 75294904Sdelphij CILK_ASSERT(w->pedigree.parent); 76294904Sdelphij CILK_ASSERT(w->pedigree.parent->parent == NULL); 77294904Sdelphij} 78294904Sdelphij 79294904Sdelphijvoid save_pedigree_leaf_from_user_worker(__cilkrts_worker *w) 80294904Sdelphij{ 81294904Sdelphij CILK_ASSERT(w->l->type == WORKER_USER); 82294904Sdelphij 83284990Scy // Existing leaf in tls should be for the current worker. 84284990Scy // This assert is expensive to check though. 85284990Scy // CILK_ASSERT(&w->pedigree == __cilkrts_get_tls_pedigree_leaf(0)); 86284990Scy CILK_ASSERT(w->l->original_pedigree_leaf); 87284990Scy 88284990Scy // w should finish with a pedigree node that points to 89284990Scy // the same root that we just looked up. 90284990Scy 91284990Scy // TODO: This assert should be valid. 92284990Scy // But we are removing it now to make exceptions (without pedigrees) work. 93284990Scy // Currently, reading the pedigree after an exception is caught 94284990Scy // fails because the pedigree chain not restored correctly. 95284990Scy // CILK_ASSERT(w->l->original_pedigree_leaf->next == w->pedigree.parent); 96284990Scy w->l->original_pedigree_leaf->rank = w->pedigree.rank; 97284990Scy 98284990Scy // Save that leaf pointer back into tls. 99284990Scy __cilkrts_set_tls_pedigree_leaf(w->l->original_pedigree_leaf); 100284990Scy // Null out worker's leaf for paranoia. 101284990Scy w->l->original_pedigree_leaf = NULL; 102284990Scy} 103284990Scy 104284990Scy 105284990Scy 106284990Scy/* 107284990Scy Local Variables: ** 108294904Sdelphij c-file-style:"bsd" ** 109294904Sdelphij c-basic-offset:4 ** 110289999Sglebius indent-tabs-mode:nil ** 111284990Scy End: ** 112284990Scy*/ 113289999Sglebius