2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* ---------------------------- included header files ---------------------- */
22 #include "safemalloc.h"
25 /* ---------------------------- local definitions -------------------------- */
27 /* ---------------------------- local macros ------------------------------- */
29 /* ---------------------------- imports ------------------------------------ */
31 /* ---------------------------- included code files ------------------------ */
33 /* ---------------------------- local types -------------------------------- */
35 /* ---------------------------- forward declarations ----------------------- */
37 /* ---------------------------- local variables ---------------------------- */
39 /* ---------------------------- exported variables (globals) --------------- */
41 /* ---------------------------- local functions ---------------------------- */
43 /* ---------------------------- interface functions ------------------------ */
45 timeout_t
*timeout_create(
50 if (n_timeouts
< 0 || n_timeouts
> TIMEOUT_MAX_TIMEOUTS
)
54 to
= (timeout_t
*)safecalloc(1, sizeof(timeout_t
));
55 to
->n_timeouts
= n_timeouts
;
56 to
->timeouts
= (timeout_time_t
*)safecalloc(
57 1, n_timeouts
* sizeof(timeout_time_t
));
69 if (to
->timeouts
!= NULL
)
78 timeout_mask_t
timeout_tick(
79 timeout_t
*to
, timeout_time_t n_ticks
)
88 for (i
= 0, mask
= 0; i
< to
->n_timeouts
; i
++)
90 if (to
->timeouts
[i
] > n_ticks
)
92 to
->timeouts
[i
] -= n_ticks
;
94 else if (to
->timeouts
[i
] > 0)
105 timeout_t
*to
, timeout_mask_t mask
, timeout_time_t ticks_before_alarm
)
109 if (ticks_before_alarm
< 0)
113 for (i
= 0; i
< to
->n_timeouts
; i
++)
117 to
->timeouts
[i
] = ticks_before_alarm
;