|
# This file is part of Buildbot. Buildbot is free software: you can # redistribute it and/or modify it under the terms of the GNU General Public # License as published by the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Copyright Buildbot Team Members
debuglog = log.msg else:
""" Class handling claiming and releasing of L{self}, and keeping track of current and waiting owners.
@note: Ideally, we'd like to maintain FIFO order. The place to do that would be the L{isAvailable()} function. However, this function is called by builds/steps both for the first time, and after waking them up by L{self} from the L{self.waiting} queue. There is currently no way of distinguishing between them. """
# subscriptions to this lock being released % (self,))
def __repr__(self): return self.description
""" Return the number of current exclusive and counting owners.
@return: Tuple (number exclusive owners, number counting owners) """ num_excl = num_excl + 1 else: # mode == 'counting'
or (num_excl == 0 and num_counting <= self.maxCount)
""" Return a boolean whether the lock is available for claiming """ % (self, access, self.owners)) # Wants counting access else: # Wants exclusive access return num_excl == 0 and num_counting == 0
""" Claim the lock (lock must be available) """
"""Schedule C{callback} to be invoked every time this lock is released. Returns a L{Subscription}."""
""" Release the lock """
debuglog("%s already released" % self) return # who can we wake up? # After an exclusive access, we may need to wake up several waiting. # Break out of the loop when the first waiting client should not be awakened. access, d = self.waiting[0] if access.mode == 'counting': if num_excl > 0 or num_counting == self.maxCount: break else: num_counting = num_counting + 1 else: # access.mode == 'exclusive' if num_excl > 0 or num_counting > 0: break else: num_excl = num_excl + 1
del self.waiting[0] reactor.callLater(0, d.callback, self)
# notify any listeners
"""Fire when the lock *might* be available. The caller will need to check with isAvailable() when the deferred fires. This loose form is used to avoid deadlocks. If we were interested in a stronger form, this would be named 'waitUntilAvailable', and the deferred would fire after the lock had been claimed. """ return defer.succeed(self)
debuglog("%s stopWaitingUntilAvailable(%s)" % (self, owner)) assert isinstance(access, LockAccess) assert (access, d) in self.waiting self.waiting.remove( (access, d) )
self.maxCount, self.maxCountForSlave)
def __repr__(self): return self.description
self.maxCount) slavename, id(lock))
""" I am an object representing a way to access a lock.
@param lockid: LockId instance that should be accessed. @type lockid: A MasterLock or SlaveLock instance.
@param mode: Mode of accessing the lock. @type mode: A string, either 'counting' or 'exclusive'. """
""" Abstract base class for LockId classes.
Sets up the 'access()' function for the LockId's available to the user (MasterLock and SlaveLock classes). Derived classes should add - Comparison with the L{util.ComparableMixin} via the L{compare_attrs} class variable. - Link to the actual lock class should be added with the L{lockClass} class variable. """ """ Express how the lock should be accessed """
""" For buildbot 0.7.7 compability: When user doesn't specify an access mode, this one is chosen. """
# master.cfg should only reference the following MasterLock and SlaveLock # classes. They are identifiers that will be turned into real Locks later, # via the BotMaster.getLockByID method.
"""I am a semaphore that limits the number of simultaneous actions.
Builds and BuildSteps can declare that they wish to claim me as they run. Only a limited number of such builds or steps will be able to run simultaneously. By default this number is one, but my maxCount parameter can be raised to allow two or three or more operations to happen at the same time.
Use this to protect a resource that is shared among all builders and all slaves, for example to limit the load on a common SVN repository. """
"""I am a semaphore that limits simultaneous actions on each buildslave.
Builds and BuildSteps can declare that they wish to claim me as they run. Only a limited number of such builds or steps will be able to run simultaneously on any given buildslave. By default this number is one, but my maxCount parameter can be raised to allow two or three or more operations to happen on a single buildslave at the same time.
Use this to protect a resource that is shared among all the builds taking place on each slave, for example to limit CPU or memory load on an underpowered machine.
Each buildslave will get an independent copy of this semaphore. By default each copy will use the same owner count (set with maxCount), but you can provide maxCountForSlave with a dictionary that maps slavename to owner count, to allow some slaves more parallelism than others.
"""
# for comparison purposes, turn this dictionary into a stably-sorted # list of tuples |