Interrupt API
-
structresume_data
data for resume after interrupt
Definition
struct resume_data { jmp_buf jump; ulong code; };
Members
jump
longjmp buffer
code
exception code
-
voidset_resume(structresume_data *data)
set longjmp buffer for resuming after exception
Parameters
struct resume_data *data
pointer to structure with longjmp address
Description
By calling this function it is possible to use a long jump to catch an exception. The caller sets the long jump buffer with set_resume() and then executes setjmp(). If an exception occurs, the code will return to the setjmp caller(). The exception code will be returned in data->code.
After the critical operation call set_resume(NULL) so that an exception in another part of the code will not accidently invoke the long jump.
// This example shows how to use set_resume(). structresume_dataresume; intret; set_resume(&resume); ret=setjmp(resume.jump); if(ret){ printf("An exception %ld occurred\n",resume.code); }else{ // Do what might raise an exception here. } set_resume(NULL);
Return
0 before an exception, 1 after an exception occurred