diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-12-11 09:30:07 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-12-11 09:45:04 -0500 |
commit | 4fd92ec6b203d6b94b9e9f9531fd60a65736e810 (patch) | |
tree | 2b5be989ca839bd97f55f40605e23d7019397be7 /include/multiprocessing.h | |
parent | 1bec4776252cec88ec3336602c0c477c20a1292f (diff) | |
download | stasis-4fd92ec6b203d6b94b9e9f9531fd60a65736e810.tar.gz |
Restructure projectdelivery-lib
* Move headers to relevant include directories within the target tree(s)
* Adjust doxygen configuration to search correct paths
* Adjust CMake configuration to use new include paths
Diffstat (limited to 'include/multiprocessing.h')
-rw-r--r-- | include/multiprocessing.h | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/include/multiprocessing.h b/include/multiprocessing.h deleted file mode 100644 index ec7c1ad..0000000 --- a/include/multiprocessing.h +++ /dev/null @@ -1,134 +0,0 @@ -/// @file multiprocessing.h -#ifndef STASIS_MULTIPROCESSING_H -#define STASIS_MULTIPROCESSING_H - -#include "core.h" -#include <signal.h> -#include <sys/wait.h> -#include <semaphore.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <sys/stat.h> - -struct MultiProcessingTask { - pid_t pid; ///< Program PID - pid_t parent_pid; ///< Program PID (parent process) - int status; ///< Child process exit status - int signaled_by; ///< Last signal received, if any - time_t _now; ///< Current time - time_t _seconds; ///< Time elapsed (used by MultiprocessingPool.status_interval) - char ident[255]; ///< Identity of the pool task - char *cmd; ///< Shell command(s) to be executed - size_t cmd_len; ///< Length of command string (for mmap/munmap) - char working_dir[PATH_MAX]; ///< Path to directory `cmd` should be executed in - char log_file[PATH_MAX]; ///< Full path to stdout/stderr log file - char parent_script[PATH_MAX]; ///< Path to temporary script executing the task - struct { - struct timespec t_start; - struct timespec t_stop; - } time_data; ///< Wall-time counters -}; - -struct MultiProcessingPool { - struct MultiProcessingTask *task; ///< Array of tasks to execute - size_t num_used; ///< Number of tasks populated in the task array - size_t num_alloc; ///< Number of tasks allocated by the task array - char ident[255]; ///< Identity of task pool - char log_root[PATH_MAX]; ///< Base directory to store stderr/stdout log files - int status_interval; ///< Report a pooled task is "running" every n seconds -}; - -/// A multiprocessing task's initial state (i.e. "FAIL") -#define MP_POOL_TASK_STATUS_INITIAL (-1) - -/// Maximum number of multiprocessing tasks STASIS can execute -#define MP_POOL_TASK_MAX 1000 - -/// Value signifies a process is unused or finished executing -#define MP_POOL_PID_UNUSED 0 - -/// Option flags for mp_pool_join() -#define MP_POOL_FAIL_FAST 1 << 1 - -/** - * Create a multiprocessing pool - * - * ```c - * #include "multiprocessing.h" - * #include "utils.h" // for get_cpu_count() - * - * int main(int argc, char *argv[]) { - * struct MultiProcessingPool *mp; - * mp = mp_pool_init("mypool", "/tmp/mypool_logs"); - * if (mp) { - * char *commands[] = { - * "/bin/echo hello world", - * "/bin/echo world hello", - * NULL - * } - * for (size_t i = 0; commands[i] != NULL); i++) { - * struct MultiProcessingTask *task; - * char task_name[100]; - * - * sprintf(task_name, "mytask%zu", i); - * task = mp_task(mp, task_name, commands[i]); - * if (!task) { - * // handle task creation error - * } - * } - * if (mp_pool_join(mp, get_cpu_count(), MP_POOL_FAIL_FAST)) { - * // handle pool execution error - * } - * mp_pool_free(&mp); - * } else { - * // handle pool initialization error - * } - * } - * ``` - * - * @param ident a name to identify the pool - * @param log_root the path to store program output - * @return pointer to initialized MultiProcessingPool - * @return NULL on error - */ -struct MultiProcessingPool *mp_pool_init(const char *ident, const char *log_root); - -/** - * Create a multiprocessing pool task - * - * @param pool a pointer to MultiProcessingPool - * @param ident a name to identify the task - * @param cmd a command to execute - * @return pointer to MultiProcessingTask structure - * @return NULL on error - */ -struct MultiProcessingTask *mp_pool_task(struct MultiProcessingPool *pool, const char *ident, char *working_dir, char *cmd); - -/** - * Execute all tasks in a pool - * - * @param pool a pointer to MultiProcessingPool - * @param jobs the number of processes to spawn at once (for serial execution use `1`) - * @param flags option to be OR'd (MP_POOL_FAIL_FAST) - * @return 0 on success - * @return >0 on failure - * @return <0 on error - */ -int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags); - -/** - * Show summary of pool tasks - * - * @param pool a pointer to MultiProcessingPool - */ -void mp_pool_show_summary(struct MultiProcessingPool *pool); - -/** - * Release resources allocated by mp_pool_init() - * - * @param a pointer to MultiProcessingPool - */ -void mp_pool_free(struct MultiProcessingPool **pool); - - -#endif //STASIS_MULTIPROCESSING_H |