Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Konstantin Osipov <kostja@tarantool.org>,
	tarantool-patches@freelists.org
Subject: Re: [PATCH v5 1/3] box: implement on_shutdown triggers
Date: Tue, 29 Jan 2019 17:47:03 +0300	[thread overview]
Message-ID: <25A845A3-48B3-4F81-811E-DB31D9071961@tarantool.org> (raw)
In-Reply-To: <20190128084325.2f2a6j6nyykjzkhl@esperanza>



> 28 янв. 2019 г., в 11:43, Vladimir Davydov <vdavydov.dev@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);

  reply	other threads:[~2019-01-29 14:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25 15:41 [PATCH v5 0/3] " Serge Petrenko
2019-01-25 15:41 ` [PATCH v5 1/3] " Serge Petrenko
2019-01-28  8:43   ` Vladimir Davydov
2019-01-29 14:47     ` Serge Petrenko [this message]
2019-01-25 15:41 ` [PATCH v5 2/3] lua: patch os.exit() to execute " Serge Petrenko
2019-01-28  8:45   ` Vladimir Davydov
2019-01-29 14:49     ` [tarantool-patches] " Serge Petrenko
2019-01-25 15:41 ` [PATCH v5 3/3] box: get rid of atexit() for calling cleanup routines Serge Petrenko
2019-01-30 10:52 ` [PATCH v5 0/3] box: implement on_shutdown triggers Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25A845A3-48B3-4F81-811E-DB31D9071961@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v5 1/3] box: implement on_shutdown triggers' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox