mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
use flywheel for round-robin
This commit is contained in:
parent
2e9142fe53
commit
2e55c5bc14
@ -30,11 +30,8 @@ class JobManager:
|
|||||||
# how many timeslices to give each job; this is used to efficiently implement
|
# how many timeslices to give each job; this is used to efficiently implement
|
||||||
# the relative job priorities
|
# the relative job priorities
|
||||||
self._jobId2timeslices = {}
|
self._jobId2timeslices = {}
|
||||||
# this is the working copy of _jobId2timeslices that we use to count down how
|
# this is a generator that we use to give high-priority jobs more timeslices
|
||||||
# many timeslices to give each job
|
self._jobIdGenerator = None
|
||||||
self._jobId2timeslicesLeft = {}
|
|
||||||
# this is used to round-robin the jobs in _jobId2timeslicesLeft
|
|
||||||
self._curJobIndex = 0
|
|
||||||
self._highestPriority = Job.Priorities.Normal
|
self._highestPriority = Job.Priorities.Normal
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
@ -73,8 +70,6 @@ class JobManager:
|
|||||||
job._cleanupGenerator()
|
job._cleanupGenerator()
|
||||||
# remove the job's timeslice count
|
# remove the job's timeslice count
|
||||||
self._jobId2timeslices.pop(jobId)
|
self._jobId2timeslices.pop(jobId)
|
||||||
if jobId in self._jobId2timeslicesLeft:
|
|
||||||
del self._jobId2timeslicesLeft[jobId]
|
|
||||||
if len(self._pri2jobId2job[pri]) == 0:
|
if len(self._pri2jobId2job[pri]) == 0:
|
||||||
del self._pri2jobId2job[pri]
|
del self._pri2jobId2job[pri]
|
||||||
if pri == self._highestPriority:
|
if pri == self._highestPriority:
|
||||||
@ -136,17 +131,22 @@ class JobManager:
|
|||||||
# figure out how long we can run
|
# figure out how long we can run
|
||||||
endT = globalClock.getRealTime() + (self._timeslice * .9)
|
endT = globalClock.getRealTime() + (self._timeslice * .9)
|
||||||
while True:
|
while True:
|
||||||
# round-robin the jobs, dropping them as they run out of priority timeslices
|
if self._jobIdGenerator is None:
|
||||||
# until all timeslices are used
|
# round-robin the jobs, giving high-priority jobs more timeslices
|
||||||
if len(self._jobId2timeslicesLeft) == 0:
|
self._jobIdGenerator = flywheel(
|
||||||
self._jobId2timeslicesLeft = dict(self._jobId2timeslices)
|
self._jobId2timeslices.keys(),
|
||||||
self._curJobIndex = (self._curJobIndex + 1) % len(self._jobId2timeslicesLeft)
|
countFunc = lambda jobId: self._jobId2timeslices[jobId])
|
||||||
jobId = self._jobId2timeslicesLeft.keys()[self._curJobIndex]
|
try:
|
||||||
# use up one of this job's timeslices
|
# grab the next jobId in the sequence
|
||||||
self._jobId2timeslicesLeft[jobId] -= 1
|
jobId = self._jobIdGenerator.next()
|
||||||
if self._jobId2timeslicesLeft[jobId] == 0:
|
except StopIteration:
|
||||||
del self._jobId2timeslicesLeft[jobId]
|
self._jobIdGenerator = None
|
||||||
pri = self._jobId2pri[jobId]
|
continue
|
||||||
|
# OK, we've selected a job to run
|
||||||
|
pri = self._jobId2pri.get(jobId)
|
||||||
|
if pri is None:
|
||||||
|
# this job is no longer present
|
||||||
|
continue
|
||||||
job = self._pri2jobId2job[pri][jobId]
|
job = self._pri2jobId2job[pri][jobId]
|
||||||
gen = job._getGenerator()
|
gen = job._getGenerator()
|
||||||
if __debug__:
|
if __debug__:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user