From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: [PATCH v5 1/3] box: implement on_shutdown triggers From: Serge Petrenko In-Reply-To: <20190128084325.2f2a6j6nyykjzkhl@esperanza> Date: Tue, 29 Jan 2019 17:47:03 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <25A845A3-48B3-4F81-811E-DB31D9071961@tarantool.org> References: <9c7b6a71c1092f04c4538fddc1b08199e01dd995.1548430046.git.sergepetrenko@tarantool.org> <20190128084325.2f2a6j6nyykjzkhl@esperanza> To: Vladimir Davydov Cc: Konstantin Osipov , tarantool-patches@freelists.org List-ID: > 28 =D1=8F=D0=BD=D0=B2. 2019 =D0=B3., =D0=B2 11:43, Vladimir Davydov = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0= ): >=20 > The patch is generally OK. See a few really minor comments below. >=20 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; =20 /** A preallocated fiber to run on_shutdown triggers. */ static struct fiber *on_shutdown_fiber =3D NULL; +/** A flag restricting repeated execution of tarantool_exit(). */ static bool is_shutting_down =3D false; /** A trigger which will break the event loop on shutdown. */ -static struct trigger shutdown_trig; +static struct trigger break_loop_trigger; =20 double tarantool_uptime(void) @@ -133,7 +134,7 @@ on_shutdown_f(va_list ap) return 0; } =20 -void +static void tarantool_exit(void) { if (is_shutting_down) { @@ -145,7 +146,7 @@ tarantool_exit(void) return; } is_shutting_down =3D true; - fiber_wakeup(on_shutdown_fiber); + fiber_call(on_shutdown_fiber); } =20 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 =3D 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 &=3D ~FIBER_IS_CANCELLABLE; + on_shutdown_fiber =3D fiber_new_ex("on_shutdown", + &attr, + on_shutdown_f); if (on_shutdown_fiber =3D=3D 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); =20 /* main core cleanup routine */ atexit(tarantool_free);=