]> git.itanic.dy.fi Git - rrdd/blob - process.h
process: Remove fork based concurrenct management
[rrdd] / process.h
1 #ifndef _PROCESS_H
2 #define _PROCESS_H
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include <sys/wait.h>
9 #include <error.h>
10 #include <errno.h>
11 #include <stdint.h>
12 #include <pthread.h>
13
14 struct event_handler;
15
16 typedef int (handle_event_fn_t)(struct event_handler *);
17
18 struct event_handler {
19         int fd;
20         uint32_t events;
21         handle_event_fn_t *handle_event;
22         char *name;
23 };
24
25 struct mutex {
26         pthread_mutex_t lock;
27         int line;
28         char *file;
29         time_t lock_time;
30         char *name;
31 };
32
33 int register_event_handler(struct event_handler *handler);
34
35 int init_jobcontrol(int max_jobs_requested);
36 int poll_job_requests(int timeout);
37 int do_fork(void);
38 int run(const char *p, char *const argv[]);
39 int clear_zombie(int pid);
40 int run_piped(const char *cmd, char *const argv[],
41               int *stdinfd, int *stdoutfd, int *stderrfd);
42 int run_piped_stream(const char *cmd, char *const argv[],
43                      FILE **stdinf, FILE **stdoutf, FILE **stderrf);
44
45 void _mutex_lock_acquired(struct mutex *lock, char *file, int line);
46 int _mutex_lock(struct mutex *lock, char *file, int line);
47 int _mutex_unlock(struct mutex *lock);
48
49 #define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__)
50 #define mutex_unlock(lock) _mutex_unlock(lock)
51 #define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__)
52
53 enum {
54         WORK_PRIORITY_HIGH,
55         WORK_PRIORITY_LOW,
56         WORK_PRIORITIES_NUM,
57 };
58
59 int queue_work(unsigned int priority, char *name,
60         int (work_fn)(void *arg), void *arg);
61
62 #endif