From f154e1f1b6cea07163f364986fb11ccfcb87c3ad Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 21 Nov 2012 21:06:19 +0100 Subject: fix application shutdown crash by not registering anything with atexit() --- CHANGES | 4 ++++ src/keeper.c | 11 +++++++---- src/keeper.h | 9 +++++++++ src/lanes.c | 3 +++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index c9404d8..1eff5c8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ CHANGES: +CHANGE 49: BGe 21-Nov-2012 + * fix application shutdown crash by not registering anything with atexit() + * rockspec for version v3.4.0 + CHANGE 48: BGe 25-Sep-2012 * version 3.4.0 * new method linda:dump() that outputs the full contents of a linda as a table, also linked to __towatch for Decoda support diff --git a/src/keeper.c b/src/keeper.c index b330d67..29f9c71 100644 --- a/src/keeper.c +++ b/src/keeper.c @@ -496,7 +496,11 @@ int keepercall_count( lua_State* L) static struct s_Keeper *GKeepers = NULL; static int GNbKeepers = 0; -static void atexit_close_keepers(void) +#if HAVE_KEEPER_ATEXIT_DESINIT +static void atexit_close_keepers( void) +#else // HAVE_KEEPER_ATEXIT_DESINIT +void close_keepers( void) +#endif // HAVE_KEEPER_ATEXIT_DESINIT { int i; // 2-pass close, in case a keeper holds a reference to a linda bound to another keeoer @@ -579,10 +583,9 @@ char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create) GKeepers[i].L = K; //GKeepers[i].count = 0; } - // call close_keepers at the very last as we want to be sure no thread is GCing after. - // (and therefore may perform linda object dereferencing after keepers are gone) - // problem: maybe on some platforms atexit() is called after DLL/so are unloaded... +#if HAVE_KEEPER_ATEXIT_DESINIT atexit( atexit_close_keepers); +#endif // HAVE_KEEPER_ATEXIT_DESINIT return NULL; // ok } diff --git a/src/keeper.h b/src/keeper.h index a9b5a22..decae4a 100644 --- a/src/keeper.h +++ b/src/keeper.h @@ -8,7 +8,16 @@ struct s_Keeper //int count; }; +// if enabled, call close_keepers at the very last as we want to be sure no thread is GCing after. +// (and therefore may perform linda object dereferencing after keepers are gone) +// problem: maybe on some platforms (linux) atexit() is called after DLL/so are unloaded... +#define HAVE_KEEPER_ATEXIT_DESINIT 0 + char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create); +#if !HAVE_KEEPER_ATEXIT_DESINIT +void close_keepers( void); +#endif // HAVE_KEEPER_ATEXIT_DESINIT + void populate_keepers( lua_State *L); struct s_Keeper *keeper_acquire( const void *ptr); void keeper_release( struct s_Keeper *K); diff --git a/src/lanes.c b/src/lanes.c index 092e282..e0374cc 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -1317,6 +1317,9 @@ static int selfdestruct_gc( lua_State *L) DEBUGEXEC(fprintf( stderr, "Killed %d lane(s) at process end.\n", n )); #endif } +#if !HAVE_KEEPER_ATEXIT_DESINIT + close_keepers(); +#endif // !HAVE_KEEPER_ATEXIT_DESINIT return 0; } -- cgit v1.2.3-55-g6feb