home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <exec/lists.h>
- #include <exec/nodes.h>
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #include <clib/alib_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #endif
-
-
- #include "AutoCleanUp.h"
-
- struct CleanUpNode
- {
- struct MinNode cun_Node;
- ptr2func CleanUpFunc;
- void *UserData;
- };
-
- #define NEWNODE ( (struct CleanUpNode *)AllocMem( sizeof( struct CleanUpNode ), MEMF_CLEAR ) )
- #define FREENODE(n) FreeMem( n, sizeof( struct CleanUpNode ) )
-
- #define NEVER_INITIALIZED ( CleanUpList.mlh_Head == NULL )
-
- struct MinList CleanUpList;
-
- void*
- RegisterCleanUp( ptr2func CleanUpFunc, void *UserData )
- {
- struct CleanUpNode *node;
-
- if NEVER_INITIALIZED
- NewList( (struct List*)&CleanUpList );
-
- if( ( node = NEWNODE ) != NULL )
- {
- node->CleanUpFunc = CleanUpFunc;
- node->UserData = UserData;
-
- AddHead( (struct List *)&CleanUpList,
- (struct Node *)node );
- }
-
- return node;
- }
-
-
- void
- AutoCleanUp( void )
- {
- struct CleanUpNode *node;
-
- if NEVER_INITIALIZED
- {
- return;
- }
-
- while( ( node = (struct CleanUpNode *)
- RemHead( (struct List *)&CleanUpList ) ) != NULL )
- {
- (*node->CleanUpFunc)( node->UserData );
- FREENODE( node );
- }
- }
-
-