Back to index

php5  5.3.10
fpm_cleanup.c
Go to the documentation of this file.
00001 
00002        /* $Id: fpm_cleanup.c,v 1.8 2008/05/24 17:38:47 anight Exp $ */
00003        /* (c) 2007,2008 Andrei Nigmatulin */
00004 
00005 #include "fpm_config.h"
00006 
00007 #include <stdlib.h>
00008 
00009 #include "fpm_arrays.h"
00010 #include "fpm_cleanup.h"
00011 
00012 struct cleanup_s {
00013        int type;
00014        void (*cleanup)(int, void *);
00015        void *arg;
00016 };
00017 
00018 static struct fpm_array_s cleanups = { .sz = sizeof(struct cleanup_s) };
00019 
00020 int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *arg) /* {{{ */
00021 {
00022        struct cleanup_s *c;
00023 
00024        c = fpm_array_push(&cleanups);
00025 
00026        if (!c) {
00027               return -1;
00028        }
00029 
00030        c->type = type;
00031        c->cleanup = cleanup;
00032        c->arg = arg;
00033 
00034        return 0;
00035 }
00036 /* }}} */
00037 
00038 void fpm_cleanups_run(int type) /* {{{ */
00039 {
00040        struct cleanup_s *c = fpm_array_item_last(&cleanups);
00041        int cl = cleanups.used;
00042 
00043        for ( ; cl--; c--) {
00044               if (c->type & type) {
00045                      c->cleanup(type, c->arg);
00046               }
00047        }
00048 
00049        fpm_array_free(&cleanups);
00050 }
00051 /* }}} */
00052