diff options
author | Torne Wuff <torne@wolfpuppy.org.uk> | 2010-01-05 22:17:32 +0000 |
---|---|---|
committer | Torne Wuff <torne@wolfpuppy.org.uk> | 2010-01-05 22:17:32 +0000 |
commit | 9e1616183230aa37093cfd805ceb9ff3ebea5984 (patch) | |
tree | 33d603a6a0898ad3b66f10fb5fcc3d1e749f2ded /apps/plugins/lib | |
parent | 44fa025d8f252b468f25d598976c780262e46cb2 (diff) |
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
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/pluginlib_exit.h | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/apps/plugins/lib/pluginlib_exit.h b/apps/plugins/lib/pluginlib_exit.h index 1bad12aed2..6cded9d56f 100644 --- a/apps/plugins/lib/pluginlib_exit.h +++ b/apps/plugins/lib/pluginlib_exit.h @@ -29,17 +29,26 @@ #include <setjmp.h> #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) |