2 Copyright (C) 2001-2007, The Perl Foundation.
7 src/exit.c - Exit Handling
11 Parrot's version of C<exit()>, C<on_exit()>, and friends.
13 C<Parrot_on_exit()> allows you register exit handlers which will be
14 called by C<Parrot_exit()> when the interpreter exits.
21 #include "parrot/parrot.h"
23 /* HEADERIZER HFILE: include/parrot/exit.h */
27 FUNCDOC: Parrot_on_exit
29 Register the specified function to be called on exit.
35 Parrot_on_exit(PARROT_INTERP
, NOTNULL(exit_handler_f function
), NULLOK(void *arg
))
37 /* XXX we might want locking around the list access. I'm sure this
38 * will be the least of the threading issues. */
40 handler_node_t
* const new_node
= mem_allocate_typed(handler_node_t
);
42 new_node
->function
= function
;
44 new_node
->next
= interp
->exit_handler_list
;
45 interp
->exit_handler_list
= new_node
;
52 Exit, calling any registered exit handlers.
57 PARROT_DOES_NOT_RETURN
59 Parrot_exit(PARROT_INTERP
, int status
)
61 /* call all the exit handlers */
62 /* we are well "below" the runloop now, where lo_var_ptr
63 * is set usually - exit handlers may run some resource-hungry
64 * stuff like printing profile stats - a DOD run would kill
65 * resources - TODO reset stacktop or better disable GC
68 * we don't allow new exit_handlers being installed inside exit handlers
70 * and: interp->exit_handler_list is gone, after the last exit handler
71 * (Parrot_really_destroy) has run
73 handler_node_t
*node
= interp
->exit_handler_list
;
75 Parrot_block_DOD(interp
);
76 Parrot_block_GC(interp
);
79 handler_node_t
* const next
= node
->next
;
81 (node
->function
)(interp
, status
, node
->arg
);
92 F<include/parrot/exit.h> and F<t/src/exit.t>.
96 Initial version by Josh Wilmes.
103 * c-file-style: "parrot"
105 * vim: expandtab shiftwidth=4: