~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Martin
  • Date: 2009-11-07 08:02:13 UTC
  • mfrom: (4789 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4809.
  • Revision ID: gzlist@googlemail.com-20091107080213-jad185091b3l69ih
Merge bzr.dev 4789 to resolve conflict from the disabling of plink auto-detection, and relocate NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
            if self.filename in _fcntl_WriteLock._open_locks:
191
191
                self._clear_f()
192
192
                raise errors.LockContention(self.filename)
 
193
            if self.filename in _fcntl_ReadLock._open_locks:
 
194
                if 'strict_locks' in debug.debug_flags:
 
195
                    self._clear_f()
 
196
                    raise errors.LockContention(self.filename)
 
197
                else:
 
198
                    trace.mutter('Write lock taken w/ an open read lock on: %s'
 
199
                                 % (self.filename,))
193
200
 
194
201
            self._open(self.filename, 'rb+')
195
202
            # reserve a slot for this lock - even if the lockf call fails,
220
227
        def __init__(self, filename):
221
228
            super(_fcntl_ReadLock, self).__init__()
222
229
            self.filename = osutils.realpath(filename)
 
230
            if self.filename in _fcntl_WriteLock._open_locks:
 
231
                if 'strict_locks' in debug.debug_flags:
 
232
                    # We raise before calling _open so we don't need to
 
233
                    # _clear_f
 
234
                    raise errors.LockContention(self.filename)
 
235
                else:
 
236
                    trace.mutter('Read lock taken w/ an open write lock on: %s'
 
237
                                 % (self.filename,))
223
238
            _fcntl_ReadLock._open_locks.setdefault(self.filename, 0)
224
239
            _fcntl_ReadLock._open_locks[self.filename] += 1
225
240
            self._open(filename, 'rb')
418
433
            DWORD,                 # dwFlagsAndAttributes
419
434
            HANDLE                 # hTemplateFile
420
435
        )((_function_name, ctypes.windll.kernel32))
421
 
    
 
436
 
422
437
    INVALID_HANDLE_VALUE = -1
423
 
    
 
438
 
424
439
    GENERIC_READ = 0x80000000
425
440
    GENERIC_WRITE = 0x40000000
426
441
    FILE_SHARE_READ = 1
427
442
    OPEN_ALWAYS = 4
428
443
    FILE_ATTRIBUTE_NORMAL = 128
429
 
    
 
444
 
430
445
    ERROR_ACCESS_DENIED = 5
431
446
    ERROR_SHARING_VIOLATION = 32
432
447
 
503
518
# We default to using the first available lock class.
504
519
_lock_type, WriteLock, ReadLock = _lock_classes[0]
505
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