Back to index

avfs  1.0.1
exit.c
Go to the documentation of this file.
00001 /*
00002     AVFS: A Virtual File System Library
00003     Copyright (C) 1998  Miklos Szeredi <miklos@szeredi.hu>
00004 
00005     This program can be distributed under the terms of the GNU GPL.
00006     See the file COPYING.
00007 */
00008 
00009 #include "exit.h"
00010 #include "avfs.h"
00011 
00012 struct exithandler {
00013     void (*func) ();
00014     struct exithandler *next;
00015 };
00016 
00017 static AV_LOCK_DECL(exit_lock);
00018 static struct exithandler *exit_handlers = NULL;
00019 
00020 void av_do_exit()
00021 {
00022     struct exithandler *hand;
00023 
00024     AV_LOCK(exit_lock);
00025     for(hand = exit_handlers; hand != NULL; hand = exit_handlers) {
00026         exit_handlers = hand->next;
00027         hand->func();
00028         av_free(hand);
00029     }
00030     AV_UNLOCK(exit_lock);
00031 }
00032 
00033 void av_add_exithandler(void (*func)())
00034 {
00035     struct exithandler *hand;
00036     
00037     AV_NEW(hand);
00038     hand->func = func;
00039     AV_LOCK(exit_lock);
00040     hand->next = exit_handlers;
00041     exit_handlers = hand;
00042     AV_UNLOCK(exit_lock);
00043 }