| iMatix home page
| << | < | > | >>
SMT Logo SMT
Version 2.81

 

smt_atexit

#include "smtlib.h"
int
smt_atexit (function handler)

Synopsis

Registers a termination function. The function is defined as a void function without arguments. The termination functions are called in the order that they are declared. Multiple instances of the same function are ignored. Returns 0 if okay, -1 if there was an error. In the case of an error, sets smt_errno to one of:
SMT NOTREADY smt_init() was not called, or failed
SMT OUTOFMEMORY Not enough heap memory left
The kernel executes termination functions before destroying agents and other objects. Thus, termination functions can access the object symbol table ('lookup' functions), but not send or receive events.

Source Code - (smtlib.c)

{
    EXITFCT *exitfct;                   /*  Agent information block          */

#if (defined (SMT_TRACE))
    trace ("smt_atexit");
#endif
    ASSERT (handler);
    if (!smt_alive)                     /*  If SMT API was not correctly     */
      {                                 /*    initialised, forget it         */
        smt_errno = SMT_NOTREADY;
        return (-1);
      }

    /*  Check that exit function is not already defined; if so, ignore it    */
    FORLIST (exitfct, exitfcts)
        if (exitfct-> handler == handler)
            return (0);

    /*  Allocate an EXITFCT block and attach it to the exitfcts list         */
    exitfct = (EXITFCT *) node_create (exitfcts.prev, sizeof (EXITFCT));
    if (exitfct == NULL)
      {
        smt_errno = SMT_OUTOFMEMORY;
        return (-1);
      }
    exitfct-> handler = handler;
    return (0);
}

| << | < | > | >> iMatix Copyright © 1996-99 iMatix Corporation