1/* pedigrees.h -*-C++-*- 2 * 3 ************************************************************************* 4 * 5 * @copyright 6 * Copyright (C) 2009-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: 13 * 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. 23 * 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. 37 **************************************************************************/ 38 39#ifndef INCLUDED_PEDIGREES_DOT_H 40#define INCLUDED_PEDIGREES_DOT_H 41 42 43#include <cilk/common.h> 44#include <internal/abi.h> 45 46#include "rts-common.h" 47#include "global_state.h" 48#include "os.h" 49 50__CILKRTS_BEGIN_EXTERN_C 51 52/** 53 * @file pedigrees.h 54 * 55 * @brief pedigrees.h declares common routines related to pedigrees 56 * and the pedigree API. 57 */ 58 59 60/** 61 * @brief Sets the leaf pedigree node for the current user thread. 62 * 63 * A typical implementation stores this pedigree node in thread-local 64 * storage. 65 * 66 * Preconditions: 67 * - Current thread should be a user thread. 68 * 69 * @param leaf The pedigree node to store as a leaf. 70 */ 71COMMON_PORTABLE 72void __cilkrts_set_pedigree_leaf(__cilkrts_pedigree* leaf); 73 74 75/** 76 * Load the pedigree leaf node from thread-local storage into the 77 * current user worker. This method should execute as a part of 78 * binding the user thread to a worker. 79 * 80 * Preconditions: 81 * 82 * - w should be the worker for the current thread 83 * - w should be a user thread. 84 */ 85COMMON_PORTABLE 86void load_pedigree_leaf_into_user_worker(__cilkrts_worker *w); 87 88/** 89 * Save the pedigree leaf node from the worker into thread-local 90 * storage. This method should execute as part of unbinding a user 91 * thread from a worker. 92 * 93 * Preconditions: 94 * 95 * - w should be the worker for the current thread 96 * - w should be a user thread. 97 */ 98COMMON_PORTABLE 99void save_pedigree_leaf_from_user_worker(__cilkrts_worker *w); 100 101 102 103/** 104 * Update pedigree for a worker when leaving a frame. 105 * 106 * If this is the frame of a spawn helper (indicated by the 107 * CILK_FRAME_DETACHED flag) we must update the pedigree. The 108 * pedigree points to nodes allocated on the stack. Failing to 109 * update it will result in a accvio/segfault if the pedigree is 110 * walked. This must happen for all spawn helper frames, even if 111 * we're processing an exception. 112 */ 113COMMON_PORTABLE 114inline void update_pedigree_on_leave_frame(__cilkrts_worker *w, 115 __cilkrts_stack_frame *sf) 116{ 117 // Update the worker's pedigree information if this is an ABI 1 or later 118 // frame 119 if (CILK_FRAME_VERSION_VALUE(sf->flags) >= 1) 120 { 121 w->pedigree.rank = sf->spawn_helper_pedigree.rank + 1; 122 w->pedigree.parent = sf->spawn_helper_pedigree.parent; 123 } 124} 125 126 127 128__CILKRTS_END_EXTERN_C 129 130#endif // ! defined(INCLUDED_PEDIGREES_DOT_H) 131