ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/event.c
Revision: 7482
Committed: Wed Mar 16 09:18:18 2016 UTC (9 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 2673 byte(s)
Log Message:
- event.c: remove unused header includes

File Contents

# User Rev Content
1 adx 30 /*
2 michael 4130 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 7006 * Copyright (c) 2000-2016 ircd-hybrid development team
5 adx 30 *
6 michael 4130 * 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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 michael 4130 * USA
20 adx 30 */
21    
22 michael 4130 /*! \file event.c
23     * \brief Timer based event execution
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "ircd.h"
30     #include "event.h"
31 michael 2680 #include "rng_mt.h"
32 adx 30
33 michael 6527
34 michael 6370 static dlink_list event_list;
35 michael 2680
36 michael 6306 const dlink_list *
37     event_get_list(void)
38     {
39 michael 6370 return &event_list;
40 michael 6306 }
41    
42 michael 4094 void
43     event_add(struct event *ev, void *data)
44     {
45     dlink_node *node;
46 adx 30
47 michael 4094 event_delete(ev);
48 michael 3599
49 michael 4094 ev->data = data;
50     ev->next = CurrentTime + ev->when;
51 michael 6642 ev->active = 1;
52 michael 3599
53 michael 6370 DLINK_FOREACH(node, event_list.head)
54 michael 4094 {
55     struct event *e = node->data;
56 michael 3599
57 michael 4094 if (e->next > ev->next)
58 adx 30 {
59 michael 6370 dlinkAddBefore(node, ev, &ev->node, &event_list);
60 adx 30 return;
61     }
62     }
63    
64 michael 6370 dlinkAddTail(ev, &ev->node, &event_list);
65 adx 30 }
66    
67     void
68 michael 4094 event_addish(struct event *ev, void *data)
69 adx 30 {
70 michael 4094 if (ev->when >= 3)
71 adx 30 {
72 michael 7330 const uintmax_t two_third = (2 * ev->when) / 3;
73 michael 4126
74 michael 4094 ev->when = two_third + ((genrand_int32() % 1000) * two_third) / 1000;
75 adx 30 }
76    
77 michael 4094 event_add(ev, data);
78 adx 30 }
79    
80     void
81 michael 4094 event_delete(struct event *ev)
82 adx 30 {
83 michael 6642 if (!ev->active)
84 michael 4094 return;
85    
86 michael 6370 dlinkDelete(&ev->node, &event_list);
87 michael 6642 ev->active = 0;
88 adx 30 }
89    
90 michael 4094 void
91     event_run(void)
92 adx 30 {
93 michael 7330 static uintmax_t last = 0;
94 adx 30
95 michael 4094 if (last == CurrentTime)
96     return;
97     last = CurrentTime;
98    
99 michael 7431 unsigned int len = dlink_list_length(&event_list);
100 michael 6370 while (len-- && dlink_list_length(&event_list))
101 michael 4094 {
102 michael 7431 struct event *ev = event_list.head->data;
103 michael 4094
104 michael 7431 if (ev->next > CurrentTime)
105 michael 4094 break;
106    
107 michael 7431 event_delete(ev);
108 michael 4094
109 michael 7431 ev->handler(ev->data);
110 michael 4094
111 michael 7431 if (!ev->oneshot)
112     event_add(ev, ev->data);
113 michael 4094 }
114 adx 30 }
115    
116     /*
117 michael 7330 * void event_set_back_events(uintmax_t by)
118 michael 4094 * Input: Time to set back events by.
119     * Output: None.
120     * Side-effects: Sets back all events by "by" seconds.
121 adx 30 */
122     void
123 michael 7330 event_set_back_events(uintmax_t by)
124 adx 30 {
125 michael 4094 dlink_node *node;
126    
127 michael 6370 DLINK_FOREACH(node, event_list.head)
128 michael 4094 {
129     struct event *ev = node->data;
130     ev->next -= by;
131     }
132 adx 30 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision