2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libcilkrts / runtime / signal_node.h
blob0a1fe2002013e7771e52fdf2e4d0b2dd3e718da7
1 /* signal_node.h -*-C++-*-
3 *************************************************************************
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:
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.
37 **************************************************************************/
39 /**
40 * @file signal_node.h
42 * @brief Signal nodes allow coordinated waking and sleeping of the runtime
43 * without hammering on a single location in memory.
45 * The workers are logically arranged in a binary tree and propagate messages
46 * leaf-ward. User workers notify the root about waking and sleeping, so only
47 * that one node need share a cache line with a user worker.
50 #ifndef INCLUDED_SIGNAL_NODE_DOT_H
51 #define INCLUDED_SIGNAL_NODE_DOT_H
53 #include "rts-common.h"
54 #include <cilk/common.h>
56 __CILKRTS_BEGIN_EXTERN_C
58 /** Opaque type. */
59 typedef struct signal_node_t signal_node_t;
61 /**
62 * Allocate and initialize a signal_node_t
64 * @return The initialized signal_node_t
66 COMMON_SYSDEP
67 signal_node_t *signal_node_create(void);
69 /**
70 * Free any resources and deallocate a signal_node_t
72 * @param node The node to be deallocated.
74 COMMON_SYSDEP void signal_node_destroy(signal_node_t *node);
76 /**
77 * Test whether the node thinks the worker should go to sleep
79 * @param node The node to be tested.
81 * @return 1 If the worker should go to sleep
82 * @return 0 If the worker should not go to sleep
84 COMMON_SYSDEP
85 unsigned int signal_node_should_wait(signal_node_t *node);
87 /**
88 * Specify whether the worker should go to sleep
90 * @param node The node to be set.
91 * @param msg The value to be set. Valid values are:
92 * - 0 - the worker should go to sleep
93 * - 1 - the worker should stay active
95 COMMON_SYSDEP
96 void signal_node_msg(signal_node_t *node, unsigned int msg);
99 /**
100 * Wait for the node to be set
102 * @param node The node to wait on
104 COMMON_SYSDEP
105 void signal_node_wait(signal_node_t *node);
107 __CILKRTS_END_EXTERN_C
109 #endif // ! defined(INCLUDED_SIGNAL_NODE_DOT_H)