Don't use sa_sigaction (which NetBSD doesn't like) at all if we don't use siginfo.
[tinc] / src / event.c
1 /*
2     event.c -- event queue
3     Copyright (C) 2002 Guus Sliepen <guus@sliepen.warande.net>,
4                   2002 Ivo Timmermans <itimmermans@bigfoot.com>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: event.c,v 1.1.4.1 2002/02/11 10:05:58 guus Exp $
21 */
22
23 #include "config.h"
24
25 #include <stdlib.h>
26 #include <xalloc.h>
27 #include <string.h>
28 #include <utils.h>
29 #include <avl_tree.h>
30 #include <time.h>
31
32 #include "event.h"
33
34 #include "system.h"
35
36 avl_tree_t *event_tree;
37
38 int id;
39
40 int event_compare(event_t *a, event_t *b)
41 {
42   if(a->time > b->time)
43     return 1;
44   if(a->time < b->time)
45     return -1;
46   return a->id - b->id; 
47 }
48
49 void init_events(void)
50 {
51 cp
52   event_tree = avl_alloc_tree((avl_compare_t)event_compare, NULL);
53 cp
54 }
55
56 void exit_events(void)
57 {
58 cp
59   avl_delete_tree(event_tree);
60 cp
61 }
62
63 event_t *new_event(void)
64 {
65   event_t *event;
66 cp
67   event = (event_t *)xmalloc_and_zero(sizeof(*event));
68 cp
69   return event;
70 }
71
72 void free_event(event_t *event)
73 {
74 cp
75   free(event);
76 cp
77 }
78
79 void event_add(event_t *event)
80 {
81 cp
82   event->id = ++id;
83   avl_insert(event_tree, event);
84 cp
85 }
86
87 void event_del(event_t *event)
88 {
89 cp
90   avl_delete(event_tree, event);
91 cp
92 }
93
94 event_t *get_expired_event(void)
95 {
96   event_t *event;
97 cp
98   if(event_tree->head)
99   {
100     event = (event_t *)event_tree->head->data;
101     if(event->time < time(NULL))
102     {
103       avl_delete(event_tree, event);
104       return event;
105     }
106   }
107 cp  
108   return NULL;
109 }