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.1 by pcg, Fri Mar 21 20:33:36 2003 UTC vs.
Revision 1.2 by pcg, Fri Mar 21 21:17:02 2003 UTC

31inline bool lowest_first (const time_watcher *a, const time_watcher *b) 31inline bool lowest_first (const time_watcher *a, const time_watcher *b)
32{ 32{
33 return a->at > b->at; 33 return a->at > b->at;
34} 34}
35 35
36timestamp NOW; 36tstamp NOW;
37 37
38io_manager iom; 38io_manager iom;
39 39
40void time_watcher::set (timestamp when) 40void time_watcher::set (tstamp when)
41{ 41{
42 iom.unreg (this); 42 iom.unreg (this);
43 at = when; 43 at = when;
44 iom.reg (this); 44 iom.reg (this);
45} 45}
110{ 110{
111 struct timeval tv; 111 struct timeval tv;
112 112
113 gettimeofday (&tv, 0); 113 gettimeofday (&tv, 0);
114 114
115 NOW = (timestamp)tv.tv_sec + (timestamp)tv.tv_usec / 1000000; 115 NOW = (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000;
116} 116}
117 117
118void io_manager::loop () 118void io_manager::loop ()
119{ 119{
120 set_now (); 120 set_now ();
121 121
122 for (;;) 122 while (!(iow.empty () && tw.empty ()))
123 { 123 {
124 int timeout = tw.empty () ? -1 : (int) ((tw[0]->at - NOW) * 1000); 124 int timeout = tw.empty ()
125 ? 3600 * 1000 // wake up at least every hour
126 : (int) ((tw[0]->at - NOW) * 1000);
125 127
126 //printf ("s%d t%d #%d <%f<%f<\n", pfs.size (), timeout, tw.size (), tw[0]->at - NOW, tw[1]->at - NOW); 128 printf ("s%d t%d #%d\n", pfs.size (), timeout, tw.size ());
127 129
128 if (timeout >= 0) 130 if (timeout >= 0)
129 { 131 {
130 int fds = poll (&pfs[0], pfs.size (), timeout); 132 int fds = poll (&pfs[0], pfs.size (), timeout);
131 133
140 } 142 }
141 143
142 while (!tw.empty () && tw[0]->at <= NOW) 144 while (!tw.empty () && tw[0]->at <= NOW)
143 { 145 {
144 pop_heap (tw.begin (), tw.end (), lowest_first); 146 pop_heap (tw.begin (), tw.end (), lowest_first);
145 time_watcher *w = tw[tw.size () - 1]; 147 (*(tw.end () - 1))->trigger ();
146 w->call (w->at);
147 push_heap (tw.begin (), tw.end (), lowest_first); 148 push_heap (tw.begin (), tw.end (), lowest_first);
148 } 149 }
149 } 150 }
150} 151}
151 152

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines