STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
multiprocessing.h File Reference
#include "core.h"
#include "sem.h"
#include "timespec.h"
#include <signal.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <math.h>
Include dependency graph for multiprocessing.h:

Go to the source code of this file.

Data Structures

struct  MultiProcessingTimer
 
struct  MultiProcessingTask
 
struct  MultiProcessingPool
 

Macros

#define MP_POOL_TASK_STATUS_INITIAL   (-1)
 A multiprocessing task's initial state (i.e. "FAIL")
 
#define MP_POOL_TASK_MAX   1000
 Maximum number of multiprocessing tasks STASIS can execute.
 
#define MP_POOL_PID_UNUSED   0
 Value signifies a process is unused or finished executing.
 
#define MP_POOL_FAIL_FAST   1 << 1
 Option flags for mp_pool_join()
 

Functions

struct MultiProcessingPoolmp_pool_init (const char *ident, const char *log_root)
 
struct MultiProcessingTaskmp_pool_task (struct MultiProcessingPool *pool, const char *ident, char *working_dir, char *cmd)
 
int mp_pool_join (struct MultiProcessingPool *pool, size_t jobs, size_t flags)
 
void mp_pool_show_summary (struct MultiProcessingPool *pool)
 
void mp_pool_free (struct MultiProcessingPool **pool)
 

Function Documentation

◆ mp_pool_free()

void mp_pool_free ( struct MultiProcessingPool ** pool)

Release resources allocated by mp_pool_init()

Parameters
apointer to MultiProcessingPool
Here is the call graph for this function:

◆ mp_pool_init()

struct MultiProcessingPool * mp_pool_init ( const char * ident,
const char * log_root )

Create a multiprocessing pool

#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
}
}
// handle pool execution error
}
} else {
// handle pool initialization error
}
}
struct MultiProcessingPool * mp_pool_init(const char *ident, const char *log_root)
Definition multiprocessing.c:538
int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags)
Definition multiprocessing.c:357
void mp_pool_free(struct MultiProcessingPool **pool)
Definition multiprocessing.c:597
#define MP_POOL_FAIL_FAST
Option flags for mp_pool_join()
Definition multiprocessing.h:58
Definition multiprocessing.h:38
Definition multiprocessing.h:21
long get_cpu_count()
Definition utils.c:857
Parameters
identa name to identify the pool
log_rootthe path to store program output
Returns
pointer to initialized MultiProcessingPool
NULL on error
Here is the call graph for this function:

◆ mp_pool_join()

int mp_pool_join ( struct MultiProcessingPool * pool,
size_t jobs,
size_t flags )

Execute all tasks in a pool

Parameters
poola pointer to MultiProcessingPool
jobsthe number of processes to spawn at once (for serial execution use 1)
flagsoption to be OR'd (MP_POOL_FAIL_FAST)
Returns
0 on success
>0 on failure
<0 on error

◆ mp_pool_show_summary()

void mp_pool_show_summary ( struct MultiProcessingPool * pool)

Show summary of pool tasks

Parameters
poola pointer to MultiProcessingPool
Here is the call graph for this function:

◆ mp_pool_task()

struct MultiProcessingTask * mp_pool_task ( struct MultiProcessingPool * pool,
const char * ident,
char * working_dir,
char * cmd )

Create a multiprocessing pool task

Parameters
poola pointer to MultiProcessingPool
identa name to identify the task
cmda command to execute
Returns
pointer to MultiProcessingTask structure
NULL on error
Here is the call graph for this function: