Back to index

php5  5.3.10
fpm_worker_pool.c
Go to the documentation of this file.
00001 
00002        /* $Id: fpm_worker_pool.c,v 1.15.2.1 2008/12/13 03:21:18 anight Exp $ */
00003        /* (c) 2007,2008 Andrei Nigmatulin */
00004 
00005 #include "fpm_config.h"
00006 
00007 #include <string.h>
00008 #include <stdlib.h>
00009 #include <unistd.h>
00010 
00011 #include "fpm.h"
00012 #include "fpm_worker_pool.h"
00013 #include "fpm_cleanup.h"
00014 #include "fpm_children.h"
00015 #include "fpm_shm.h"
00016 #include "fpm_scoreboard.h"
00017 #include "fpm_conf.h"
00018 
00019 struct fpm_worker_pool_s *fpm_worker_all_pools;
00020 
00021 static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */
00022 {
00023        struct fpm_worker_pool_s *wp, *wp_next;
00024 
00025        for (wp = fpm_worker_all_pools; wp; wp = wp_next) {
00026               wp_next = wp->next;
00027               fpm_worker_pool_config_free(wp->config);
00028               fpm_children_free(wp->children);
00029               if ((which & FPM_CLEANUP_CHILD) == 0 && fpm_globals.parent_pid == getpid()) {
00030                      fpm_scoreboard_free(wp->scoreboard);
00031               }
00032               free(wp->config);
00033               free(wp->user);
00034               free(wp->home);
00035               free(wp);
00036        }
00037        fpm_worker_all_pools = NULL;
00038 }
00039 /* }}} */
00040 
00041 struct fpm_worker_pool_s *fpm_worker_pool_alloc() /* {{{ */
00042 {
00043        struct fpm_worker_pool_s *ret;
00044 
00045        ret = malloc(sizeof(struct fpm_worker_pool_s));
00046        if (!ret) {
00047               return 0;
00048        }
00049 
00050        memset(ret, 0, sizeof(struct fpm_worker_pool_s));
00051 
00052        ret->idle_spawn_rate = 1;
00053        ret->log_fd = -1;
00054        return ret;
00055 }
00056 /* }}} */
00057 
00058 int fpm_worker_pool_init_main() /* {{{ */
00059 {
00060        if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_worker_pool_cleanup, 0)) {
00061               return -1;
00062        }
00063        return 0;
00064 }
00065 /* }}} */