Port everything to work with Python 2.6 and (hopefully) 3.0.
Phew, this was harder than I expected, mostly because I noticed I never grokked metaclasses all that well. Now it's slightly better ;-). git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1344 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
59ebcace2a
commit
cd10080cca
8 changed files with 77 additions and 138 deletions
|
@ -1,17 +1,11 @@
|
|||
from Abstract import *
|
||||
from abc import *
|
||||
import sgpem
|
||||
|
||||
## @brief This is the abstract class a user-defined policy
|
||||
# should inherit from
|
||||
#
|
||||
# This class also exposes the method sort(), which can be
|
||||
# used to easily sort the queue of ready process with a
|
||||
# user-defined given compare function.
|
||||
class CPUPolicy:
|
||||
## @var Avoid instantiation of an abstract class.
|
||||
# @see Abstract.Metaclass
|
||||
__metaclass__ = Metaclass
|
||||
|
||||
## @brief The abstract base class needed for compatibility between
|
||||
# Python 2.6 and Python 3.x.
|
||||
#
|
||||
# @see CPUPolicy
|
||||
class CPUPolicyBase(object):
|
||||
## @brief Configure policy to initial values
|
||||
#
|
||||
# This is called just before a simulation starts, and is responsible
|
||||
|
@ -26,7 +20,9 @@ class CPUPolicy:
|
|||
# @endcode
|
||||
#
|
||||
# @see sgpem::Policy::get_parameters()
|
||||
configure = AbstractMethod('configure')
|
||||
@abstractmethod
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
## @brief Sort ready processes queue
|
||||
#
|
||||
|
@ -46,7 +42,9 @@ class CPUPolicy:
|
|||
# swap(positionA, positionB) and size().
|
||||
#
|
||||
# @see Policy::Policy::sort()
|
||||
sort_queue = AbstractMethod('sort_queue')
|
||||
@abstractmethod
|
||||
def sort_queue(self, queue):
|
||||
pass
|
||||
|
||||
## @brief Returns whether the policy wants to be preemptive,
|
||||
# other than by normal time slice termination
|
||||
|
@ -70,7 +68,9 @@ class CPUPolicy:
|
|||
# slice (or a process blocking/termination, of course) before
|
||||
# selecting a new running process, even if it has greater priority
|
||||
# than the current one
|
||||
is_preemptive = AbstractMethod('is_preemptive')
|
||||
@abstractmethod
|
||||
def is_preemptive(self):
|
||||
pass
|
||||
|
||||
## @brief Returns how long is a time-slice for this policy
|
||||
#
|
||||
|
@ -90,7 +90,9 @@ class CPUPolicy:
|
|||
#
|
||||
# @return -1 If the policy doesn't want to use time slices
|
||||
# @return 0+ To specify a time slice duration for this policy
|
||||
get_time_slice = AbstractMethod('get_time_slice')
|
||||
@abstractmethod
|
||||
def get_time_slice(self):
|
||||
pass
|
||||
|
||||
## @brief Returns the PolicyParameters instance you can use in
|
||||
# Policy::Policy::configure()
|
||||
|
@ -178,3 +180,18 @@ class CPUPolicy:
|
|||
# puts pivot in place
|
||||
queue.swap(i,b)
|
||||
return i
|
||||
|
||||
|
||||
|
||||
## @brief This is the abstract class a user-defined policy
|
||||
# should inherit from
|
||||
#
|
||||
# This class also exposes the method sort(), which can be
|
||||
# used to easily sort the queue of ready process with a
|
||||
# user-defined given compare function.
|
||||
#
|
||||
# @see CPUPolicyBase
|
||||
CPUPolicy = ABCMeta('CPUPolicy', (CPUPolicyBase, ), {})
|
||||
|
||||
|
||||
print (dir (CPUPolicy))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue