ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/iom.C
(Generate patch)

Comparing gvpe/src/iom.C (file contents):
Revision 1.14 by pcg, Sat Jan 17 14:08:57 2004 UTC vs.
Revision 1.19 by pcg, Sun Mar 28 01:53:33 2004 UTC

19 19
20#include <cstdio> 20#include <cstdio>
21#include <cstdlib> 21#include <cstdlib>
22#include <cerrno> 22#include <cerrno>
23 23
24#include <sys/time.h>
25
26#if 1 // older unices need these includes for select (2)
27# include <unistd.h>
28# include <sys/types.h>
29#endif
30
31// if the BSDs would at least be marginally POSIX-compatible.. *sigh*
32// until that happens, sys/select.h must come last
24#include <sys/select.h> 33#include <sys/select.h>
25#include <sys/time.h>
26 34
27#include "iom.h" 35#include "iom.h"
28 36
29// TSTAMP_MAX must still fit into a positive struct timeval 37// TSTAMP_MAX must still fit into a positive struct timeval
30#define TSTAMP_MAX (double)(1UL<<31) 38#define TSTAMP_MAX (double)(1UL<<31)
31 39
32// this is a dummy time watcher to ensure that the first 40// this is a dummy time watcher to ensure that the first
33// time watcher is _always_ valid, this gets rid of a lot 41// time watcher is _always_ valid, this gets rid of a lot
34// of null-pointer-checks 42// of null-pointer-checks
35// (must come _before_ iom is being defined) 43// (must come _before_ iom is being defined)
36static struct tw0 : time_watcher { 44static struct tw0 : time_watcher
37 void cb (time_watcher &w)
38 { 45 {
46 void cb (time_watcher &w)
47 {
39 // should never get called 48 // should never get called
40 // reached end-of-time, or tstamp has a bogus definition, 49 // reached end-of-time, or tstamp has a bogus definition,
41 // or compiler initilization order broken, or somethine else :) 50 // or compiler initilization order broken, or somethine else :)
42 abort (); 51 abort ();
43 } 52 }
44 53
45 tw0() 54 tw0 ()
46 : time_watcher (this, &tw0::cb) 55 : time_watcher (this, &tw0::cb)
47 { } 56 { }}
48} tw0; 57tw0;
49 58
50tstamp NOW; 59tstamp NOW;
51static bool iom_valid; 60static bool iom_valid;
52io_manager iom; 61io_manager iom;
53 62
57 if (!iom_valid) 66 if (!iom_valid)
58 abort (); 67 abort ();
59 68
60 if (!w->active) 69 if (!w->active)
61 { 70 {
71#if IOM_CHECK
72 queue.activity = true;
73#endif
62 queue.push_back (w); 74 queue.push_back (w);
63 w->active = queue.size (); 75 w->active = queue.size ();
64 } 76 }
65} 77}
66 78
88void io_manager::reg (time_watcher *w) { reg (w, tw); } 100void io_manager::reg (time_watcher *w) { reg (w, tw); }
89void io_manager::unreg (time_watcher *w) { unreg (w, tw); } 101void io_manager::unreg (time_watcher *w) { unreg (w, tw); }
90#endif 102#endif
91 103
92#if IOM_IO 104#if IOM_IO
93void io_manager::reg (io_watcher *w) { reg (w, iow); } 105void io_manager::reg (io_watcher *w) { reg (w, iow); }
94void io_manager::unreg (io_watcher *w) { unreg (w, iow); } 106void io_manager::unreg (io_watcher *w) { unreg (w, iow); }
95#endif 107#endif
96 108
97#if IOM_CHECK 109#if IOM_CHECK
98void io_manager::reg (check_watcher *w) { reg (w, cw); } 110void io_manager::reg (check_watcher *w) { reg (w, cw); }
133 tval.tv_usec = 0; 145 tval.tv_usec = 0;
134 to = &tval; 146 to = &tval;
135 } 147 }
136 else 148 else
137#endif 149#endif
150
138 { 151 {
139#if IOM_TIME 152#if IOM_TIME
140 time_watcher *next; 153 time_watcher *next;
141 154
142 for (;;) 155 for (;;)
153 { 166 {
154 if (next != tw[0]) 167 if (next != tw[0])
155 { 168 {
156 double diff = next->at - NOW; 169 double diff = next->at - NOW;
157 tval.tv_sec = (int)diff; 170 tval.tv_sec = (int)diff;
158 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); 171 tval.tv_usec = (int) ((diff - tval.tv_sec) * 1000000);
159 to = &tval; 172 to = &tval;
160 } 173 }
161 break; 174 break;
162 } 175 }
163 else 176 else
165 unreg (next); 178 unreg (next);
166 next->call (*next); 179 next->call (*next);
167 } 180 }
168 } 181 }
169#endif 182#endif
183
170 } 184 }
171 185
172#if IOM_CHECK 186#if IOM_CHECK
187 tw.activity = false;
188
173 for (int i = cw.size (); i--; ) 189 for (int i = cw.size (); i--; )
174 if (!cw[i]) 190 if (!cw[i])
175 cw.erase_unordered (i); 191 cw.erase_unordered (i);
176 else 192 else
177 cw[i]->call (*cw[i]); 193 cw[i]->call (*cw[i]);
194
195 if (tw.activity)
196 {
197 tval.tv_sec = 0;
198 tval.tv_usec = 0;
199 to = &tval;
200 }
178#endif 201#endif
179 202
180#if IOM_IO 203#if IOM_IO
181 fd_set rfd, wfd, efd; 204 fd_set rfd, wfd;
182 205
183 FD_ZERO (&rfd); 206 FD_ZERO (&rfd);
184 FD_ZERO (&wfd); 207 FD_ZERO (&wfd);
185 208
186 int fds = 0; 209 int fds = 0;
195 } 218 }
196 219
197 if (!to && !fds) //TODO: also check idle_watchers and check_watchers 220 if (!to && !fds) //TODO: also check idle_watchers and check_watchers
198 break; // no events 221 break; // no events
199 222
200 fds = select (fds, &rfd, &wfd, &efd, to); 223 fds = select (fds, &rfd, &wfd, NULL, to);
201# if IOM_TIME 224# if IOM_TIME
202 set_now (); 225 set_now ();
203# endif 226# endif
204 227
205 if (fds > 0) 228 if (fds > 0)
237 select (0, 0, 0, 0, &to); 260 select (0, 0, 0, 0, &to);
238 set_now (); 261 set_now ();
239#else 262#else
240 break; 263 break;
241#endif 264#endif
265
242 } 266 }
243} 267}
244 268
245io_manager::io_manager () 269io_manager::io_manager ()
246{ 270{
248 272
249#if IOM_TIME 273#if IOM_TIME
250 set_now (); 274 set_now ();
251 275
252 tw0.start (TSTAMP_MAX); 276 tw0.start (TSTAMP_MAX);
253 printf ("abort, %f but inly on %f\n", NOW, tw0.at);
254#endif 277#endif
255} 278}
256 279
257io_manager::~io_manager () 280io_manager::~io_manager ()
258{ 281{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines