coroutine.hh (12800:7736882bdea5) coroutine.hh (14067:2c3667b32607)
1/*
2 * Copyright (c) 2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 147 unchanged lines hidden (view full) ---

156 Coroutine& operator=(const Coroutine& rhs) = delete;
157
158 /**
159 * Coroutine constructor.
160 * The only way to construct a coroutine is to pass it the routine
161 * it needs to run. The first argument of the function should be a
162 * reference to the Coroutine<Arg,Ret>::caller_type which the
163 * routine will use as a way for yielding to the caller.
1/*
2 * Copyright (c) 2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 147 unchanged lines hidden (view full) ---

156 Coroutine& operator=(const Coroutine& rhs) = delete;
157
158 /**
159 * Coroutine constructor.
160 * The only way to construct a coroutine is to pass it the routine
161 * it needs to run. The first argument of the function should be a
162 * reference to the Coroutine<Arg,Ret>::caller_type which the
163 * routine will use as a way for yielding to the caller.
164 * The optional second boolean argument controls if the Coroutine
165 * should be run on creation, which mimics Boost's Coroutine
166 * semantics by default. This can be disabled as an optimization to
167 * avoid unnecessary context switches on Coroutine creation.
164 *
165 * @param f task run by the coroutine
168 *
169 * @param f task run by the coroutine
170 * @param run_coroutine set to false to disable running the coroutine
171 * immediately after it is created
166 */
172 */
167 Coroutine(std::function f)
173 Coroutine(std::function<void(CallerType&)> f, bool run_coroutine = true)
168 : Fiber(), task(f), caller(*this)
169 {
174 : Fiber(), task(f), caller(*this)
175 {
170 // Create and Run the Coroutine
171 this->call();
176 // When desired, run the Coroutine after it is created
177 if (run_coroutine)
178 this->call();
172 }
173
174 virtual ~Coroutine() {}
175
176 public:
177 /** Coroutine interface */
178
179 /**

--- 87 unchanged lines hidden ---
179 }
180
181 virtual ~Coroutine() {}
182
183 public:
184 /** Coroutine interface */
185
186 /**

--- 87 unchanged lines hidden ---