annotate libcilkrts/runtime/cilk_fiber-unix.h @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* cilk_fiber-unix.h -*-C++-*-
kono
parents:
diff changeset
2 *
kono
parents:
diff changeset
3 *************************************************************************
kono
parents:
diff changeset
4 *
kono
parents:
diff changeset
5 * Copyright (C) 2012-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 #ifndef INCLUDED_CILK_FIBER_UNIX_DOT_H
kono
parents:
diff changeset
51 #define INCLUDED_CILK_FIBER_UNIX_DOT_H
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 #ifndef __cplusplus
kono
parents:
diff changeset
54 # error cilk_fiber-unix.h is a C++-only header
kono
parents:
diff changeset
55 #endif
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 #include "cilk_fiber.h"
kono
parents:
diff changeset
58 #include "jmpbuf.h"
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 /**
kono
parents:
diff changeset
61 * @file cilk_fiber-unix.h
kono
parents:
diff changeset
62 *
kono
parents:
diff changeset
63 * @brief Unix-specific implementation for cilk_fiber.
kono
parents:
diff changeset
64 */
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 /**
kono
parents:
diff changeset
67 * @brief Unix-specific fiber class derived from portable fiber class
kono
parents:
diff changeset
68 */
kono
parents:
diff changeset
69 struct cilk_fiber_sysdep : public cilk_fiber
kono
parents:
diff changeset
70 {
kono
parents:
diff changeset
71 public:
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 #if SUPPORT_GET_CURRENT_FIBER
kono
parents:
diff changeset
74 /**
kono
parents:
diff changeset
75 * @brief Gets the current fiber from TLS.
kono
parents:
diff changeset
76 */
kono
parents:
diff changeset
77 static cilk_fiber_sysdep* get_current_fiber_sysdep();
kono
parents:
diff changeset
78 #endif
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /**
kono
parents:
diff changeset
81 * @brief Construct the system-dependent portion of a fiber.
kono
parents:
diff changeset
82 *
kono
parents:
diff changeset
83 * @param stack_size The size of the stack for this fiber.
kono
parents:
diff changeset
84 */
kono
parents:
diff changeset
85 cilk_fiber_sysdep(std::size_t stack_size);
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /**
kono
parents:
diff changeset
88 * @brief Construct the system-dependent of a fiber created from a
kono
parents:
diff changeset
89 * thread.
kono
parents:
diff changeset
90 */
kono
parents:
diff changeset
91 cilk_fiber_sysdep(from_thread_t);
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 /**
kono
parents:
diff changeset
94 * @brief Destructor
kono
parents:
diff changeset
95 */
kono
parents:
diff changeset
96 ~cilk_fiber_sysdep();
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 /**
kono
parents:
diff changeset
99 * @brief OS-specific calls to convert this fiber back to thread.
kono
parents:
diff changeset
100 *
kono
parents:
diff changeset
101 * Nothing to do for Linux.
kono
parents:
diff changeset
102 */
kono
parents:
diff changeset
103 void convert_fiber_back_to_thread();
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 /**
kono
parents:
diff changeset
106 * @brief System-dependent function to suspend self and resume execution of "other".
kono
parents:
diff changeset
107 *
kono
parents:
diff changeset
108 * This fiber is suspended.
kono
parents:
diff changeset
109 *
kono
parents:
diff changeset
110 * @pre @c is_resumable() should be true.
kono
parents:
diff changeset
111 *
kono
parents:
diff changeset
112 * @param other Fiber to resume.
kono
parents:
diff changeset
113 */
kono
parents:
diff changeset
114 void suspend_self_and_resume_other_sysdep(cilk_fiber_sysdep* other);
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 /**
kono
parents:
diff changeset
117 * @brief System-dependent function called to jump to @p other
kono
parents:
diff changeset
118 * fiber.
kono
parents:
diff changeset
119 *
kono
parents:
diff changeset
120 * @pre @c is_resumable() should be false.
kono
parents:
diff changeset
121 *
kono
parents:
diff changeset
122 * @param other Fiber to resume.
kono
parents:
diff changeset
123 */
kono
parents:
diff changeset
124 NORETURN jump_to_resume_other_sysdep(cilk_fiber_sysdep* other);
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 /**
kono
parents:
diff changeset
127 * @brief Runs the start_proc.
kono
parents:
diff changeset
128 * @pre is_resumable() should be false.
kono
parents:
diff changeset
129 * @pre is_allocated_from_thread() should be false.
kono
parents:
diff changeset
130 * @pre m_start_proc must be valid.
kono
parents:
diff changeset
131 */
kono
parents:
diff changeset
132 NORETURN run();
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 /**
kono
parents:
diff changeset
135 * @brief Returns the base of this fiber's stack.
kono
parents:
diff changeset
136 */
kono
parents:
diff changeset
137 inline char* get_stack_base_sysdep() { return m_stack_base; }
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 private:
kono
parents:
diff changeset
140 char* m_stack_base; ///< The base of this fiber's stack.
kono
parents:
diff changeset
141 char* m_stack; ///< Stack memory (low address)
kono
parents:
diff changeset
142 __CILK_JUMP_BUFFER m_resume_jmpbuf; ///< Place to resume fiber
kono
parents:
diff changeset
143 unsigned m_magic; ///< Magic number for checking
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 static long s_page_size; ///< Page size for stacks.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 // Allocate memory for a stack. This method
kono
parents:
diff changeset
148 // initializes m_stack and m_stack_base.
kono
parents:
diff changeset
149 void make_stack(size_t stack_size);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 // Deallocates memory for the stack.
kono
parents:
diff changeset
152 void free_stack();
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 // Common helper method for implementation of resume_other_sysdep
kono
parents:
diff changeset
155 // variants.
kono
parents:
diff changeset
156 inline void resume_other_sysdep(cilk_fiber_sysdep* other);
kono
parents:
diff changeset
157 };
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 #endif // ! defined(INCLUDED_CILK_FIBER_UNIX_DOT_H)