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.16 by pcg, Sat Jan 17 16:49:01 2004 UTC vs.
Revision 1.18 by pcg, Sun Mar 28 01:43:50 2004 UTC

21#include <cstdlib> 21#include <cstdlib>
22#include <cerrno> 22#include <cerrno>
23 23
24#include <sys/time.h> 24#include <sys/time.h>
25 25
26#if 1 // older unices need these includes for select(2) 26#if 1 // older unices need these includes for select (2)
27# include <unistd.h> 27# include <unistd.h>
28# include <sys/types.h> 28# include <sys/types.h>
29#endif 29#endif
30 30
31// if the BSDs would at least be marginally POSIX-compatible.. *sigh* 31// if the BSDs would at least be marginally POSIX-compatible.. *sigh*
39 39
40// this is a dummy time watcher to ensure that the first 40// this is a dummy time watcher to ensure that the first
41// time watcher is _always_ valid, this gets rid of a lot 41// time watcher is _always_ valid, this gets rid of a lot
42// of null-pointer-checks 42// of null-pointer-checks
43// (must come _before_ iom is being defined) 43// (must come _before_ iom is being defined)
44static struct tw0 : time_watcher { 44static struct tw0 : time_watcher
45 void cb (time_watcher &w)
46 { 45 {
46 void cb (time_watcher &w)
47 {
47 // should never get called 48 // should never get called
48 // reached end-of-time, or tstamp has a bogus definition, 49 // reached end-of-time, or tstamp has a bogus definition,
49 // or compiler initilization order broken, or somethine else :) 50 // or compiler initilization order broken, or somethine else :)
50 abort (); 51 abort ();
51 } 52 }
52 53
53 tw0() 54 tw0 ()
54 : time_watcher (this, &tw0::cb) 55 : time_watcher (this, &tw0::cb)
55 { } 56 { }}
56} tw0; 57tw0;
57 58
58tstamp NOW; 59tstamp NOW;
59static bool iom_valid; 60static bool iom_valid;
60io_manager iom; 61io_manager iom;
61 62
65 if (!iom_valid) 66 if (!iom_valid)
66 abort (); 67 abort ();
67 68
68 if (!w->active) 69 if (!w->active)
69 { 70 {
71#if IOM_CHECK
72 queue.activity = true;
73#endif
70 queue.push_back (w); 74 queue.push_back (w);
71 w->active = queue.size (); 75 w->active = queue.size ();
72 } 76 }
73} 77}
74 78
96void io_manager::reg (time_watcher *w) { reg (w, tw); } 100void io_manager::reg (time_watcher *w) { reg (w, tw); }
97void io_manager::unreg (time_watcher *w) { unreg (w, tw); } 101void io_manager::unreg (time_watcher *w) { unreg (w, tw); }
98#endif 102#endif
99 103
100#if IOM_IO 104#if IOM_IO
101void io_manager::reg (io_watcher *w) { reg (w, iow); } 105void io_manager::reg (io_watcher *w) { reg (w, iow); }
102void io_manager::unreg (io_watcher *w) { unreg (w, iow); } 106void io_manager::unreg (io_watcher *w) { unreg (w, iow); }
103#endif 107#endif
104 108
105#if IOM_CHECK 109#if IOM_CHECK
106void io_manager::reg (check_watcher *w) { reg (w, cw); } 110void io_manager::reg (check_watcher *w) { reg (w, cw); }
141 tval.tv_usec = 0; 145 tval.tv_usec = 0;
142 to = &tval; 146 to = &tval;
143 } 147 }
144 else 148 else
145#endif 149#endif
150
146 { 151 {
147#if IOM_TIME 152#if IOM_TIME
148 time_watcher *next; 153 time_watcher *next;
149 154
150 for (;;) 155 for (;;)
161 { 166 {
162 if (next != tw[0]) 167 if (next != tw[0])
163 { 168 {
164 double diff = next->at - NOW; 169 double diff = next->at - NOW;
165 tval.tv_sec = (int)diff; 170 tval.tv_sec = (int)diff;
166 tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); 171 tval.tv_usec = (int) ((diff - tval.tv_sec) * 1000000);
167 to = &tval; 172 to = &tval;
168 } 173 }
169 break; 174 break;
170 } 175 }
171 else 176 else
173 unreg (next); 178 unreg (next);
174 next->call (*next); 179 next->call (*next);
175 } 180 }
176 } 181 }
177#endif 182#endif
183
178 } 184 }
179 185
180#if IOM_CHECK 186#if IOM_CHECK
187 tw.activity = false;
188
181 for (int i = cw.size (); i--; ) 189 for (int i = cw.size (); i--; )
182 if (!cw[i]) 190 if (!cw[i])
183 cw.erase_unordered (i); 191 cw.erase_unordered (i);
184 else 192 else
185 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 }
186#endif 201#endif
187 202
188#if IOM_IO 203#if IOM_IO
189 fd_set rfd, wfd, efd; 204 fd_set rfd, wfd;
190 205
191 FD_ZERO (&rfd); 206 FD_ZERO (&rfd);
192 FD_ZERO (&wfd); 207 FD_ZERO (&wfd);
193 208
194 int fds = 0; 209 int fds = 0;
245 select (0, 0, 0, 0, &to); 260 select (0, 0, 0, 0, &to);
246 set_now (); 261 set_now ();
247#else 262#else
248 break; 263 break;
249#endif 264#endif
265
250 } 266 }
251} 267}
252 268
253io_manager::io_manager () 269io_manager::io_manager ()
254{ 270{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines