--- libaitio/src/exec.c 2013/12/05 15:18:22 1.1.2.6 +++ libaitio/src/exec.c 2013/12/05 16:57:08 1.1.2.8 @@ -116,7 +116,7 @@ io_progOpen(prog_t * __restrict prg, u_int execNum) if (!prg) return 0; - if (execNum > prg->prog_maxn) { + if (prg->prog_cnum + execNum > prg->prog_maxn) { io_SetErr(EINVAL, "Requested number for program execution is over pool's limit"); return 0; } @@ -145,6 +145,28 @@ io_progOpen(prog_t * __restrict prg, u_int execNum) } /* + * io_progGrow() - Execute to number of programs in pool + * + * @prg = program pool + * @toNum = execute to number of programs (0 max) + * return: 0 error, >0 executed programs and abs(<0) executed programs with logged error + */ +int +io_progGrow(prog_t * __restrict prg, u_int toNum) +{ + if (!prg) + return 0; + if (toNum > prg->prog_maxn) { + io_SetErr(EINVAL, "Requested number for program execution is over pool's limit"); + return 0; + } + if (!toNum) + toNum = prg->prog_maxn; + + return io_progOpen(prg, toNum - prg->prog_cnum); +} + +/* * io_progVacuum() - Vacuum pool to running number of programs * * @prg = program pool @@ -175,6 +197,31 @@ io_progVacuum(prog_t * __restrict prg, u_int toNum) ret++; } pthread_mutex_unlock(&prg->prog_mtx); + + return ret; +} + +/* + * io_progCheck() - Check exit status of program pool + * + * @prg = program pool + * return: -1 error or >-1 exited programs + */ +int +io_progCheck(prog_t * __restrict prg) +{ + int ret = 0; + struct tagPIOPID *p; + register int i; + + if (!prg) + return -1; + + for (i = 0; i < array_Size(prg->prog_fds); i++) + if (array_Get(prg->prog_fds, i) && + (p = pio_pgetpid(array(prg->prog_fds, i, FILE*)))) + if (waitpid(p->pid, &p->stat, WNOHANG) > 0) + ret++; return ret; }