int fpm_scoreboard_proc_alloc(struct fpm_child_s *child) /* {{{ */
{
	int i = -1;
	struct fpm_worker_pool_s *wp = child->wp;
	struct fpm_scoreboard_s *scoreboard = wp->scoreboard;
	int nprocs = wp->config->pm_max_children;

	if (!scoreboard) {
		return -1;
	}

	/* first try the slot which is supposed to be free */
	if (scoreboard->free_proc >= 0 && scoreboard->free_proc < nprocs) {
		if (!scoreboard->procs[scoreboard->free_proc].used) {
			i = scoreboard->free_proc;
		}
	}

	if (i < 0) { /* the supposed free slot is not, let's search for a free slot */
		zlog(ZLOG_DEBUG, "[pool %s] the proc->free_slot was not free. Let's search", scoreboard->pool);
		for (i = 0; i < nprocs; i++) {
			if (!scoreboard->procs[i].used) { /* found */
				break;
			}
		}
	}

	/* no free slot */
	if (i < 0 || i >= nprocs) {
		zlog(ZLOG_ERROR, "[pool %s] no free scoreboard slot", scoreboard->pool);
		return -1;
	}

	scoreboard->procs[i].used = 1;
	child->scoreboard_i = i;

	/* supposed next slot is free */
	if (i + 1 >= nprocs) {
		scoreboard->free_proc = 0;
	} else {
		scoreboard->free_proc = i + 1;
	}

	return 0;
}
int fpm_scoreboard_proc_alloc(struct fpm_child_s *child)  
{
	int i = -1;
	struct fpm_worker_pool_s *wp = child->wp;
	struct fpm_scoreboard_s *scoreboard = wp->scoreboard;
	int nprocs = wp->config->pm_max_children;

	if (!scoreboard) {
		return -1;
	}

	 
	if (scoreboard->free_proc >= 0 && scoreboard->free_proc < nprocs) {
		if (!scoreboard->procs[scoreboard->free_proc].used) {
			i = scoreboard->free_proc;
		}
	}

	if (i < 0) {  
		zlog(ZLOG_DEBUG, "[pool %s] the proc->free_slot was not free. Let's search", scoreboard->pool);
		for (i = 0; i < nprocs; i++) {
			if (!scoreboard->procs[i].used) {  
				break;
			}
		}
	}

	 
	if (i < 0 || i >= nprocs) {
		zlog(ZLOG_ERROR, "[pool %s] no free scoreboard slot", scoreboard->pool);
		return -1;
	}

	scoreboard->procs[i].used = 1;
	child->scoreboard_i = i;

	 
	if (i + 1 >= nprocs) {
		scoreboard->free_proc = 0;
	} else {
		scoreboard->free_proc = i + 1;
	}

	return 0;
}