dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnetlib ./ChangeLog Xsharp/Timer.cs


From: Heiko Weiss
Subject: [dotgnu-pnet-commits] pnetlib ./ChangeLog Xsharp/Timer.cs
Date: Tue, 20 Dec 2005 15:35:48 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    pnetlib
Branch:         
Changes by:     Heiko Weiss <address@hidden>    05/12/20 15:35:48

Modified files:
        .              : ChangeLog 
        Xsharp         : Timer.cs 

Log message:
        fixed a loop if system clock was changed

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnetlib/ChangeLog.diff?tr1=1.2341&tr2=1.2342&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnetlib/Xsharp/Timer.cs.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: pnetlib/ChangeLog
diff -u pnetlib/ChangeLog:1.2341 pnetlib/ChangeLog:1.2342
--- pnetlib/ChangeLog:1.2341    Mon Dec 19 10:01:25 2005
+++ pnetlib/ChangeLog   Tue Dec 20 15:35:48 2005
@@ -1,3 +1,7 @@
+2005-12-20  Heiko Weiss <address@hidden>
+
+       * Xsharp/Timer.cs: fixed loop if system clock was changed
+
 2005-12-19  Heiko Weiss <address@hidden>
 
        * Xsharp/Graphics.cs: fixed a memory leak
Index: pnetlib/Xsharp/Timer.cs
diff -u pnetlib/Xsharp/Timer.cs:1.5 pnetlib/Xsharp/Timer.cs:1.6
--- pnetlib/Xsharp/Timer.cs:1.5 Fri May  6 09:03:41 2005
+++ pnetlib/Xsharp/Timer.cs     Tue Dec 20 15:35:48 2005
@@ -359,6 +359,7 @@
                                        {
                                                Timer current = dpy.timerQueue;
                                                Timer prev = null;
+                                               int iCount = 0;
                                                while(current != null && 
current.nextDue <= nextDue)
                                                {
                                                        prev = current;
@@ -483,12 +484,28 @@
                                                        next = timer.nextDue +
                                                                new 
TimeSpan(timer.period *
                                                                                
         TimeSpan.TicksPerMillisecond);
+                                                                               
         
+                                                       // if the next due is 
less than now, the date/time may have changed.
+                                                       // since the timer 
expired right now the next due might be now + period
+                                                       if(next <= now)
+                                                       {
+                                                               next += new 
TimeSpan
+                                                                       
(((((Int64)(now - next).TotalMilliseconds) / timer.period) + 1) *
+                                                                               
timer.period * 
+                                                                               
TimeSpan.TicksPerMillisecond);
+                                                       }
+                                                       
+                                                       /* 
+                                                       do not increment here, 
since the time might have changed with years
+                                                       this would do a long 
loop here 
+                                                       
                                                        while(next <= now)
                                                        {
                                                                next += new 
TimeSpan
                                                                                
(timer.period *
                                                                                
 TimeSpan.TicksPerMillisecond);
                                                        }
+                                                       */
                                                        timer.nextDue = next;
                                                        timer.AddTimer();
                                                }
@@ -497,6 +514,16 @@
                                return activated;
                        }
 
+       // fix all timers in the queue if the system time has been changed
+       internal static void FixTimers( Timer timer ) {
+               DateTime fixTime = DateTime.UtcNow;
+               long tpms = TimeSpan.TicksPerMillisecond;
+               while( null != timer ) {
+                       timer.nextDue = fixTime + new TimeSpan(timer.period * 
tpms);
+                       timer = timer.next;
+               }
+       }
+
        // Get the number of milliseconds until the next timeout.
        // Returns -1 if there are no active timers.
        internal static int GetNextTimeout(Display dpy)
@@ -518,8 +545,11 @@
                                                        // supposed to wait. 
This propably means the system clock has
                                                        // been turned back 
(either manually or by NTP). In this case
                                                        // we must calculate a 
new due time and just return 0.
+                                                       FixTimers( 
dpy.timerQueue );
+                                                       /*
                                                        dpy.timerQueue.nextDue 
= DateTime.UtcNow + new TimeSpan
                                                                
(dpy.timerQueue.period * TimeSpan.TicksPerMillisecond);
+                                                       */
                                                        return 0;
                                                }
                                                else if (diff > (100 * 
TimeSpan.TicksPerSecond))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]