~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-08 23:44:40 UTC
  • mfrom: (4731.1.5 debug-flag-relock)
  • Revision ID: pqm@pqm.ubuntu.com-20091008234440-e0thgiawplpcqomd
(andrew) Add -Drelock debug flag that makes noise about wasteful
        unlocking and relocking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
518
518
# We default to using the first available lock class.
519
519
_lock_type, WriteLock, ReadLock = _lock_classes[0]
520
520
 
 
521
 
 
522
class _RelockDebugMixin(object):
 
523
    """Mixin support for -Drelock flag.
 
524
 
 
525
    Add this as a base class then call self._note_lock with 'r' or 'w' when
 
526
    acquiring a read- or write-lock.  If this object was previously locked (and
 
527
    locked the same way), and -Drelock is set, then this will trace.note a
 
528
    message about it.
 
529
    """
 
530
    
 
531
    _prev_lock = None
 
532
 
 
533
    def _note_lock(self, lock_type):
 
534
        if 'relock' in debug.debug_flags and self._prev_lock == lock_type:
 
535
            if lock_type == 'r':
 
536
                type_name = 'read'
 
537
            else:
 
538
                type_name = 'write'
 
539
            trace.note('%r was %s locked again', self, type_name)
 
540
        self._prev_lock = lock_type
 
541