[PATCH v5 1/3] box: implement on_shutdown triggers
Serge Petrenko
sergepetrenko at tarantool.org
Tue Jan 29 17:47:03 MSK 2019
> 28 янв. 2019 г., в 11:43, Vladimir Davydov <vdavydov.dev at gmail.com> написал(а):
>
> The patch is generally OK. See a few really minor comments below.
>
Hi! Thankyou for review. I fixed your comments. The fixes are on the branch
https://github.com/tarantool/tarantool/tree/sp/gh-1607-on-exit-triggers
Incremental diff for this patch is below
diff --git a/src/main.cc b/src/main.cc
index 96df9e851..a3d96843d 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -91,9 +91,10 @@ static double start_time;
/** A preallocated fiber to run on_shutdown triggers. */
static struct fiber *on_shutdown_fiber = NULL;
+/** A flag restricting repeated execution of tarantool_exit(). */
static bool is_shutting_down = false;
/** A trigger which will break the event loop on shutdown. */
-static struct trigger shutdown_trig;
+static struct trigger break_loop_trigger;
double
tarantool_uptime(void)
@@ -133,7 +134,7 @@ on_shutdown_f(va_list ap)
return 0;
}
-void
+static void
tarantool_exit(void)
{
if (is_shutting_down) {
@@ -145,7 +146,7 @@ tarantool_exit(void)
return;
}
is_shutting_down = true;
- fiber_wakeup(on_shutdown_fiber);
+ fiber_call(on_shutdown_fiber);
}
static void
@@ -786,8 +787,17 @@ main(int argc, char **argv)
try {
box_init();
box_lua_init(tarantool_L);
- /* Reserve a fiber to run on_shutdown triggers. */
- on_shutdown_fiber = fiber_new("on_exit", on_shutdown_f);
+ /*
+ * Reserve a fiber to run on_shutdown triggers.
+ * Make sure the fiber is non-cancellable so that
+ * it doesn't get woken up from Lua unintentionally.
+ */
+ struct fiber_attr attr;
+ fiber_attr_create(&attr);
+ attr.flags &= ~FIBER_IS_CANCELLABLE;
+ on_shutdown_fiber = fiber_new_ex("on_shutdown",
+ &attr,
+ on_shutdown_f);
if (on_shutdown_fiber == NULL)
diag_raise();
/*
@@ -795,8 +805,8 @@ main(int argc, char **argv)
* main event loop. The trigger will be the last to run
* since it's the first one we register.
*/
- trigger_create(&shutdown_trig, break_loop, NULL, NULL);
- trigger_add(&box_on_shutdown, &shutdown_trig);
+ trigger_create(&break_loop_trigger, break_loop, NULL, NULL);
+ trigger_add(&box_on_shutdown, &break_loop_trigger);
/* main core cleanup routine */
atexit(tarantool_free);
More information about the Tarantool-patches
mailing list