1 
2 /*-------------------------------------------------------------*/
3 /***************************************************************
4  * A netwib_wait permits to wait for an event during a user    *
5  * defined duration.                                           *
6  ***************************************************************/
7 
8 /*-------------------------------------------------------------*/
9 typedef struct netwib_wait netwib_wait;
10 
11 /*-------------------------------------------------------------*/
12 /* Name : netwib_wait_init
13    Description :
14      Initialize a netwib_wait : wait for an event decided by a
15      function.
16    Input parameter(s) :
17      pfuncevent : memory address of the function which will
18                   be called to check for an event
19                   For each call, the first parameter ('infos')
20                   will be set with the optional parameter below.
21      pfuncclose : optional parameter (can be NULL) which
22                   contain the function to call to free
23                   resources allocated by infos (when
24                   netwib_wait_close will be called)
25    Input/output parameter(s) :
26      infos : optional parameter (can be NULL) which will be
27              used as the first parameter for *pfunc.
28              This may be used to send information to *pfunc.
29    Output parameter(s) :
30      **ppwait : netwib_wait associated to function
31    Normal return values :
32      NETWIB_ERR_OK : ok
33 */
34 typedef netwib_err (*netwib_wait_event_pf)(netwib_ptr infos,
35                                            netwib_consttime *pabstime,
36                                            netwib_bool *pevent);
37 typedef netwib_err (*netwib_wait_close_pf)(netwib_ptr infos);
38 netwib_err netwib_wait_init(netwib_wait_event_pf pfuncevent,
39                             netwib_ptr infos,
40                             netwib_wait_close_pf pfuncclose,
41                             netwib_wait **ppwait);
42 
43 /*-------------------------------------------------------------*/
44 /* Name : netwib_wait_close
45    Description :
46      Close a netwib_wait.
47    Input parameter(s) :
48    Input/output parameter(s) :
49      **ppwait : netwib_wait to close
50    Output parameter(s) :
51    Normal return values :
52      NETWIB_ERR_OK : ok
53 */
54 netwib_err netwib_wait_close(netwib_wait **ppwait);
55 
56 /*-------------------------------------------------------------*/
57 /* Name : netwib_wait_init_io
58    Description :
59      Initialize a netwib_wait : wait for data from the netwib_io.
60    Input parameter(s) :
61      *pio : netwib_io where to wait for data
62    Input/output parameter(s) :
63    Output parameter(s) :
64      **ppwait : netwib_wait associated to *pio
65    Normal return values :
66      NETWIB_ERR_OK : ok
67 */
68 netwib_err netwib_wait_init_io(netwib_io *pio,
69                                netwib_io_waytype way,
70                                netwib_wait **ppwait);
71 /* netwib_err f(netwib_io *pio, netwib_wait **ppwait); */
72 #define netwib_wait_init_io_read(pio,ppwait) netwib_wait_init_io(pio,NETWIB_IO_WAYTYPE_READ,ppwait)
73 #define netwib_wait_init_io_write(pio,ppwait) netwib_wait_init_io(pio,NETWIB_IO_WAYTYPE_WRITE,ppwait)
74 #define netwib_wait_init_io_rdwr(pio,ppwait) netwib_wait_init_io(pio,NETWIB_IO_WAYTYPE_RDWR,ppwait)
75 
76 /*-------------------------------------------------------------*/
77 /* Name : netwib_wait_init_thread_end
78    Description :
79      Initialize a netwib_wait : wait for the end of a thread.
80    Input parameter(s) :
81      *pthread : thread to wait for
82    Input/output parameter(s) :
83      preturnederror : address of a variable which will contain
84                       returned error
85      pinfosout : address of a variable which will contain
86                  output information
87    Output parameter(s) :
88      *ppwait : netwib_wait associated to *pthread
89    Normal return values :
90      NETWIB_ERR_OK : ok
91 */
92 netwib_err netwib_wait_init_thread_end(netwib_thread *pthread,
93                                        netwib_err *preturnederror,
94                                        netwib_ptr *pinfosout,
95                                        netwib_wait **ppwait);
96 
97 /*-------------------------------------------------------------*/
98 /* Name : netwib_wait_init_thread_cond
99    Description :
100      Initialize a netwib_wait : wait for a condition
101    Input parameter(s) :
102      *pcond : condition to wait for
103    Input/output parameter(s) :
104      *pvalue : address of a variable which will contain
105                condition value
106    Output parameter(s) :
107      *ppwait : netwib_wait associated to *pcond
108    Normal return values :
109      NETWIB_ERR_OK : ok
110 */
111 netwib_err netwib_wait_init_thread_cond(netwib_thread_cond *pcond,
112                                         netwib_uint32 *pvalue,
113                                         netwib_wait **ppwait);
114 
115 /*-------------------------------------------------------------*/
116 /* Name : netwib_wait_wait1
117    Description :
118      Wait for 1 event.
119    Input parameter(s) :
120      *pwait : netwib_wait to wait for
121      *pabstime : end time
122    Input/output parameter(s) :
123    Output parameter(s) :
124      *pevent : an event occurred on *pwait. If *pabstime is
125                reached *pevent is set to NETWIB_FALSE.
126    Normal return values :
127      NETWIB_ERR_OK : ok
128 */
129 netwib_err netwib_wait_wait1(netwib_wait *pwait,
130                              netwib_consttime *pabstime,
131                              netwib_bool *pevent);
132 
133 /*-------------------------------------------------------------*/
134 /* Name : netwib_wait_wait5
135    Description :
136      Wait for 1 event amongst 5 netwib_wait.
137    Input parameter(s) :
138      *pwait1..5 : netwib_wait to wait for
139      *pabstime : end time
140    Input/output parameter(s) :
141    Output parameter(s) :
142      *pevent1..5 : an event occurred on *pwait1..5
143                    If abstime is reached *pevent is set
144                    to NETWIB_FALSE.
145    Normal return values :
146      NETWIB_ERR_OK : ok
147 */
148 netwib_err netwib_wait_wait5(netwib_wait *pwait1,
149                              netwib_wait *pwait2,
150                              netwib_wait *pwait3,
151                              netwib_wait *pwait4,
152                              netwib_wait *pwait5,
153                              netwib_consttime *pabstime,
154                              netwib_bool *pevent1,
155                              netwib_bool *pevent2,
156                              netwib_bool *pevent3,
157                              netwib_bool *pevent4,
158                              netwib_bool *pevent5);
159 #define netwib_wait_wait4(pwait1,pwait2,pwait3,pwait4,pabstime,pevent1,pevent2,pevent3,pevent4) netwib_wait_wait5(pwait1,pwait2,pwait3,pwait4,NULL,pabstime,pevent1,pevent2,pevent3,pevent4,NULL)
160 #define netwib_wait_wait3(pwait1,pwait2,pwait3,pabstime,pevent1,pevent2,pevent3) netwib_wait_wait5(pwait1,pwait2,pwait3,NULL,NULL,pabstime,pevent1,pevent2,pevent3,NULL,NULL)
161 #define netwib_wait_wait2(pwait1,pwait2,pabstime,pevent1,pevent2) netwib_wait_wait5(pwait1,pwait2,NULL,NULL,NULL,pabstime,pevent1,pevent2,NULL,NULL,NULL)
162