From 9e1616183230aa37093cfd805ceb9ff3ebea5984 Mon Sep 17 00:00:00 2001 From: Torne Wuff Date: Tue, 5 Jan 2010 22:17:32 +0000 Subject: pluginlib: Support calling a function at exit time to clean up open files or other similar work. This is not quite the same as atexit() on POSIX as the function is *not* called if the plugin exits by returning from plugin_start; only if exit() is called. No code overhead if it's not used. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24189 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/lib/pluginlib_exit.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'apps/plugins/lib') diff --git a/apps/plugins/lib/pluginlib_exit.h b/apps/plugins/lib/pluginlib_exit.h index 1bad12a..6cded9d 100644 --- a/apps/plugins/lib/pluginlib_exit.h +++ b/apps/plugins/lib/pluginlib_exit.h @@ -29,17 +29,26 @@ #include #endif -/* PLUGINLIB_EXIT_INIT needs to be placed as the first line in plugin_start */ -#define PLUGINLIB_EXIT_INIT switch(setjmp(__exit_env)) \ - { \ - case 1: \ - return PLUGIN_OK; \ - case 2: \ - return PLUGIN_ERROR; \ - case 0: \ - default: \ - break; \ - } +#define _PLUGINLIB_EXIT_INIT(atexit) switch(setjmp(__exit_env)) \ + { \ + case 1: \ + atexit \ + return PLUGIN_OK; \ + case 2: \ + atexit \ + return PLUGIN_ERROR; \ + case 0: \ + default: \ + break; \ + } + +/* Either PLUGINLIB_EXIT_INIT or PLUGINLIB_EXIT_INIT_ATEXIT needs to be placed + * as the first line in plugin_start. The _ATEXIT version will call the named + * no-argument function when exit() is called before exiting the plugin, to + * allow for cleanup. + */ +#define PLUGINLIB_EXIT_INIT _PLUGINLIB_EXIT_INIT() +#define PLUGINLIB_EXIT_INIT_ATEXIT(atexit) _PLUGINLIB_EXIT_INIT(atexit();) extern jmp_buf __exit_env; #define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1) -- cgit v1.1