forked from len0rd/rockbox
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
This commit is contained in:
parent
44fa025d8f
commit
9e16161832
1 changed files with 20 additions and 11 deletions
|
@ -29,17 +29,26 @@
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* PLUGINLIB_EXIT_INIT needs to be placed as the first line in plugin_start */
|
#define _PLUGINLIB_EXIT_INIT(atexit) switch(setjmp(__exit_env)) \
|
||||||
#define PLUGINLIB_EXIT_INIT switch(setjmp(__exit_env)) \
|
{ \
|
||||||
{ \
|
case 1: \
|
||||||
case 1: \
|
atexit \
|
||||||
return PLUGIN_OK; \
|
return PLUGIN_OK; \
|
||||||
case 2: \
|
case 2: \
|
||||||
return PLUGIN_ERROR; \
|
atexit \
|
||||||
case 0: \
|
return PLUGIN_ERROR; \
|
||||||
default: \
|
case 0: \
|
||||||
break; \
|
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;
|
extern jmp_buf __exit_env;
|
||||||
#define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1)
|
#define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue