[Tarantool-patches] [PATCH v2 1/4] fiber: introduce fiber.f_arg

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Nov 10 02:58:51 MSK 2020

Struct fiber has a member va_list f_data. It is used to forward
arguments to the fiber function when fiber_start() is called,
right from the caller's stack.

But it is useless when fiber is started asynchronously, with
fiber_new + fiber_wakeup. And there is no way to pass anything
into such a fiber.

This patch adds a new member 'void *f_arg', which shares memory
with va_list f_data, and can be used to pass something into the

The feature is going to be used by raft. Currently raft worker
fiber works only with global variables, but soon it will need to
have its own pointer at struct raft object. And it can't be
started with fiber_start(), because raft code does not yield
anywhere in its state machine.

Needed for #5303
 src/lib/core/fiber.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h
index 539e5c8e7..0ca9a4191 100644
--- a/src/lib/core/fiber.h
+++ b/src/lib/core/fiber.h
@@ -565,7 +565,19 @@ struct fiber {
 	 * See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31488
 	fiber_func f;
-	va_list f_data;
+	union {
+		/**
+		 * Argument list passed when the fiber is invoked in a blocking
+		 * way, so the caller may pass arguments from its own stack.
+		 */
+		va_list f_data;
+		/**
+		 * Fiber function argument which passed asynchronously. Can be
+		 * used not to call fiber_start to avoid yields, but still pass
+		 * something into the fiber.
+		 */
+		void *f_arg;
+	};
 	int f_ret;
 	/** Fiber local storage. */
 	struct {
2.21.1 (Apple Git-122.3)

More information about the Tarantool-patches mailing list