瀏覽代碼

optimized dolaters and timer change

Joe Shochet 23 年之前
父節點
當前提交
d7cb1260c4
共有 1 個文件被更改,包括 18 次插入14 次删除
  1. 18 14
      direct/src/task/Task.py

+ 18 - 14
direct/src/task/Task.py

@@ -259,22 +259,26 @@ class TaskPriorityList(list):
 
 
 
 
 class DoLaterList(list):
 class DoLaterList(list):
+    """
+    This is a list that maintains sorted order of wakeTimes on tasks
+    """
     def __init__(self):
     def __init__(self):
         list.__init__(self)
         list.__init__(self)
-        self.__wakeTimeList = []
 
 
     def add(self, task):
     def add(self, task):
-        # Find the insertion point with a binary search
-        index = bisect(self.__wakeTimeList, task.wakeTime)
-        # Insert this new wake time
-        self.__wakeTimeList.insert(index, task.wakeTime)
-        # And the task itself
-        list.insert(self, index, task)
-
-    def __delitem__(self, index):
-        del self.__wakeTimeList[index]
-        list.__delitem__(self, index)
-
+        """
+        Add task, keeping the list sorted.
+        This does a binary search for the index to insert into.
+        """
+        lo = 0
+        hi = len(self)
+        while lo < hi:
+            mid = (lo+hi)//2
+            if task.wakeTime < self[mid].wakeTime:
+                hi = mid
+            else:
+                lo = mid+1
+        list.insert(self, lo, task)
 
 
 class TaskManager:
 class TaskManager:
 
 
@@ -556,9 +560,9 @@ class TaskManager:
             # Run the task and check the return value
             # Run the task and check the return value
             if task.pstats:
             if task.pstats:
                 task.pstats.start()
                 task.pstats.start()
-            startTime = time.clock()
+            startTime = globalClock.getRealTime()
             ret = task(task)
             ret = task(task)
-            endTime = time.clock()
+            endTime = globalClock.getRealTime()
             if task.pstats:
             if task.pstats:
                 task.pstats.stop()
                 task.pstats.stop()