Scheduling list fix and simplifications

Fri, 26 Jan 2018 09:27:07 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 26 Jan 2018 09:27:07 +0000
changeset 69
8705e296c7a0
parent 68
72f821e17123
child 70
3f794760d52e

Scheduling list fix and simplifications

scheduler.py file | annotate | diff | comparison | revisions
sleep.py file | annotate | diff | comparison | revisions
--- a/scheduler.py	Fri Jan 26 00:11:47 2018 +0000
+++ b/scheduler.py	Fri Jan 26 09:27:07 2018 +0000
@@ -21,22 +21,23 @@
         raise NotImplementedError
 
     def insert_after(self, ev):
-        if not self.next:
-            ev.prev=self
-            self.next=ev
-            ev.next=None
-        elif ev<self.next:
+        if not self.next or ev<self.next:
             self.insert_immediately_after(ev)
         else:
             self.next.insert_after(ev)
 
     def insert_immediately_after(self, ev):
+        assert(ev.next is None and ev.prev is None)
         ev.prev=self
         ev.next=self.next
-        if ev.next:
-            ev.next.prev=ev
         self.next=ev
 
+    def insert_immediately_before(self, ev):
+        assert(ev.next is None and ev.prev is None)
+        ev.next=self
+        ev.prev=self.prev
+        self.prev=ev
+
     def unlink(self):
         n=self.next
         p=self.prev
@@ -74,7 +75,7 @@
         if not self._list:
             self._list=ev
         elif ev<self._list:
-            ev.insert_immediately_after(self._list)
+            self._list.insert_immediately_before(ev)
             self._list=ev
         else:
             self._list.insert_after(ev)
--- a/sleep.py	Fri Jan 26 00:11:47 2018 +0000
+++ b/sleep.py	Fri Jan 26 09:27:07 2018 +0000
@@ -5,6 +5,7 @@
 import Foundation
 import AppKit
 import borgend
+import platform
 
 logger=borgend.logger.getChild(__name__)
 

mercurial