Proof of concept scriptlet queue, single or multi threaded.
[platform/upstream/rpm.git] / rpmio / rpmsq.h
1 #ifndef H_RPMSQ
2 #define H_RPMSQ
3
4 /** \ingroup rpmio
5  * \file rpmio/rpmsq.h
6  *
7  */
8
9 #include <pthread.h>
10 #include <signal.h>
11 #include <sys/signal.h>
12 #include <search.h>             /* XXX insque(3)/remque(3) protos. */
13
14 typedef struct rpmsig_s * rpmsig;
15
16 typedef struct rpmsqElem * rpmsq;
17
18 /*@-redecl@*/
19 /*@unchecked@*/
20 extern int _rpmsq_debug;
21 /*@=redecl@*/
22
23 /**
24  * SIGCHLD queue element.
25  */
26 struct rpmsqElem {
27     struct rpmsqElem * q_forw;  /*!< for use by insque(3)/remque(3). */
28     struct rpmsqElem * q_back;
29     pid_t child;                /*!< Currently running child. */
30     volatile pid_t reaped;      /*!< Reaped waitpid(3) return. */
31     volatile int status;        /*!< Reaped waitpid(3) status. */
32     int reaper;                 /*!< Register SIGCHLD handler? */
33     void * id;                  /*!< Blocking thread id (pthread_t). */
34     pthread_mutex_t mutex;
35     pthread_cond_t cond;
36 };
37
38 /*@unchecked@*/
39 extern rpmsq rpmsqQueue;
40
41 /*@unchecked@*/
42 extern sigset_t rpmsqCaught;
43
44 #ifdef __cplusplus
45 {
46 #endif
47
48 /**
49  */
50 int rpmsqInsert(/*@null@*/ void * elem, /*@null@*/ void * prev)
51         /*@globals rpmsqQueue @*/
52         /*@modifies elem, rpmsqQueue @*/;
53
54 /**
55  */
56 int rpmsqRemove(/*@null@*/ void * elem)
57         /*@modifies elem @*/;
58
59 /**
60  */
61 void rpmsqHandler(int signum)
62         /*@globals rpmsqCaught, fileSystem @*/
63         /*@modifies rpmsqCaught, fileSystem @*/;
64
65 /**
66  * Enable or disable a signal handler.
67  * @param signum        signal to enable (or disable if negative)
68  * @param handler       signal handler (or NULL to use rpmsqHandler())
69  * @return              no. of refs, -1 on error
70  */
71 int rpmsqEnable(int signum, /*@null@*/ sighandler_t handler)
72         /*@globals rpmsqCaught, fileSystem, internalState @*/
73         /*@modifies rpmsqCaught, fileSystem, internalState @*/;
74
75 /**
76  * Fork a child process.
77  * @param sq            scriptlet queue element
78  * @return              fork(2) pid
79  */
80 pid_t rpmsqFork(rpmsq sq)
81         /*@globals fileSystem, internalState @*/
82         /*@modifies sq, fileSystem, internalState @*/;
83
84 /**
85  * Wait for child process to be reaped.
86  * @param sq            scriptlet queue element
87  * @return              reaped child pid
88  */
89 pid_t rpmsqWait(rpmsq sq)
90         /*@globals fileSystem, internalState @*/
91         /*@modifies sq, fileSystem, internalState @*/;
92
93 /**
94  * Execute a command, returning its status.
95  */
96 int rpmsqExecve (const char ** argv)
97         /*@*/;
98
99 #ifdef __cplusplus
100 }
101 #endif
102
103 #endif  /* H_RPMSQ */