support/package-builder/ThreadPool.py
b37b4c63
 import WorkerThread
87815216
 
d024e640
 class ThreadPool(object):
87815216
 
     mapWorkerThreads = {}
     activeWorkerThreads = []
     inactiveWorkerThreads = []
     mapPackageToCycle = {}
     listAvailableCyclicPackages = []
     pkgBuildType = "chroot"
     logger = None
     statusEvent = None
 
d024e640
     @staticmethod
     def clear():
         ThreadPool.mapWorkerThreads.clear()
87815216
         ThreadPool.activeWorkerThreads = []
         ThreadPool.inactiveWorkerThreads = []
 
d024e640
     @staticmethod
     def getAllWorkerObjects():
87815216
         listWorkerObjs = []
d024e640
         listWorkerKeys = ThreadPool.mapWorkerThreads.keys()
         for x in listWorkerKeys:
87815216
             xobj = ThreadPool.mapWorkerThreads[x]
d024e640
             listWorkerObjs.append(xobj)
         return listWorkerObjs
87815216
 
d024e640
     @staticmethod
b37b4c63
     def addWorkerThread(workerThreadName):
90d8acae
         workerThread = WorkerThread.WorkerThread(
87815216
             ThreadPool.statusEvent,
             workerThreadName,
             ThreadPool.mapPackageToCycle,
             ThreadPool.listAvailableCyclicPackages,
             ThreadPool.logger,
             ThreadPool.pkgBuildType)
         ThreadPool.mapWorkerThreads[workerThreadName] = workerThread
 
d024e640
     @staticmethod
     def makeWorkerThreadActive(threadName):
         if threadName in ThreadPool.inactiveWorkerThreads:
             ThreadPool.inactiveWorkerThreads.remove(threadName)
         ThreadPool.activeWorkerThreads.append(threadName)
87815216
 
d024e640
     @staticmethod
     def makeWorkerThreadInActive(threadName):
         if threadName in ThreadPool.activeWorkerThreads:
             ThreadPool.activeWorkerThreads.remove(threadName)
         ThreadPool.inactiveWorkerThreads.append(threadName)
87815216
 
d024e640
     @staticmethod
     def startWorkerThread(threadName):
         ThreadPool.mapWorkerThreads[threadName].start()
87815216
 
d024e640
     @staticmethod
     def getListInactiveWorkerThreads():
         return ThreadPool.inactiveWorkerThreads
87815216
 
d024e640
     @staticmethod
     def activateWorkerThreads(numOfThreadsToActivate):
         while len(ThreadPool.inactiveWorkerThreads) > 0 and numOfThreadsToActivate > 0:
87815216
             threadName = ThreadPool.inactiveWorkerThreads.pop()
b37b4c63
             ThreadPool.addWorkerThread(threadName)
d024e640
             ThreadPool.startWorkerThread(threadName)
             ThreadPool.makeWorkerThreadActive(threadName)
             numOfThreadsToActivate = numOfThreadsToActivate -1