1 /*
2  * $Id: watchdog.h,v 1.7 2001/03/28 22:30:40 shane Exp $
3  */
4 
5 #ifndef WATCHDOG_H
6 #define WATCHDOG_H
7 
8 #include <pthread.h>
9 
10 #if TIME_WITH_SYS_TIME
11 # include <sys/time.h>
12 # include <time.h>
13 #else
14 # if HAVE_SYS_TIME_H
15 #  include <sys/time.h>
16 # else
17 #  include <time.h>
18 # endif
19 #endif
20 
21 #include "error.h"
22 
23 /* each watched thread gets one of these structures */
24 typedef struct watched {
25     /* thread to monitor */
26     pthread_t watched_thread;
27 
28     /* flag whether in a watchdog list */
29     int in_list;
30 
31     /* time when to cancel thread if no activity */
32     time_t alarm_time;
33 
34     /* for location in doubly-linked list */
35     struct watched *older;
36     struct watched *newer;
37 
38     /* watchdog that this watched_t is in */
39     void *watchdog;
40 } watched_t;
41 
42 /* the watchdog keeps track of all information */
43 typedef struct {
44     pthread_mutex_t mutex;
45     int inactivity_timeout;
46 
47     /* the head and tail of our list */
48     watched_t *oldest;
49     watched_t *newest;
50 } watchdog_t;
51 
52 int watchdog_init(watchdog_t *w, int inactivity_timeout, error_t *err);
53 void watchdog_add_watched(watchdog_t *w, watched_t *watched);
54 void watchdog_defer_watched(watched_t *watched);
55 void watchdog_remove_watched(watched_t *watched);
56 
57 #endif /* WATCHDOG_H */
58 
59