scheduler.py

changeset 69
8705e296c7a0
parent 59
8d0a815022cc
child 75
2a44b9649212
equal deleted inserted replaced
68:72f821e17123 69:8705e296c7a0
19 19
20 def __lt__(self, other): 20 def __lt__(self, other):
21 raise NotImplementedError 21 raise NotImplementedError
22 22
23 def insert_after(self, ev): 23 def insert_after(self, ev):
24 if not self.next: 24 if not self.next or ev<self.next:
25 ev.prev=self
26 self.next=ev
27 ev.next=None
28 elif ev<self.next:
29 self.insert_immediately_after(ev) 25 self.insert_immediately_after(ev)
30 else: 26 else:
31 self.next.insert_after(ev) 27 self.next.insert_after(ev)
32 28
33 def insert_immediately_after(self, ev): 29 def insert_immediately_after(self, ev):
30 assert(ev.next is None and ev.prev is None)
34 ev.prev=self 31 ev.prev=self
35 ev.next=self.next 32 ev.next=self.next
36 if ev.next:
37 ev.next.prev=ev
38 self.next=ev 33 self.next=ev
34
35 def insert_immediately_before(self, ev):
36 assert(ev.next is None and ev.prev is None)
37 ev.next=self
38 ev.prev=self.prev
39 self.prev=ev
39 40
40 def unlink(self): 41 def unlink(self):
41 n=self.next 42 n=self.next
42 p=self.prev 43 p=self.prev
43 if n: 44 if n:
72 73
73 def _insert(self, ev): 74 def _insert(self, ev):
74 if not self._list: 75 if not self._list:
75 self._list=ev 76 self._list=ev
76 elif ev<self._list: 77 elif ev<self._list:
77 ev.insert_immediately_after(self._list) 78 self._list.insert_immediately_before(ev)
78 self._list=ev 79 self._list=ev
79 else: 80 else:
80 self._list.insert_after(ev) 81 self._list.insert_after(ev)
81 82
82 self._cond.notify() 83 self._cond.notify()

mercurial