ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/event.c
Revision: 7329
Committed: Thu Feb 18 21:07:50 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 2735 byte(s)
Log Message:
- Now that we got time_t to work nicely on openbsd with snprintf's conversion specifiers,
  we ran into a similiar issue on Raspbian/ARMv7's time_t which is of signed 32 bit and
  doesn't cope at all with %j. Instead of doing tricks, get rid of time_t everywhere and
  forever and use uintmax_t instead which has at least a 'standardized' conversion specifier
  associated with it.

File Contents

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

Properties

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