~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Martin Pool
  • Date: 2009-09-11 06:36:50 UTC
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090911063650-yvb522sbe6k0i62r
Only mutter extension load errors when they occur, and record for later

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
84
84
        return self.lock_url == other.lock_url and self.details == other.details
85
85
 
86
86
    def __repr__(self):
87
 
        return '%s(%s, %s)' % (self.__class__.__name__,
 
87
        return '%s(%s%s)' % (self.__class__.__name__,
88
88
                             self.lock_url, self.details)
89
89
 
90
90
 
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,))
200
193
 
201
194
            self._open(self.filename, 'rb+')
202
195
            # reserve a slot for this lock - even if the lockf call fails,
203
 
            # at this point unlock() will be called, because self.f is set.
 
196
            # at thisi point unlock() will be called, because self.f is set.
204
197
            # TODO: make this fully threadsafe, if we decide we care.
205
198
            _fcntl_WriteLock._open_locks.add(self.filename)
206
199
            try:
227
220
        def __init__(self, filename):
228
221
            super(_fcntl_ReadLock, self).__init__()
229
222
            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,))
238
223
            _fcntl_ReadLock._open_locks.setdefault(self.filename, 0)
239
224
            _fcntl_ReadLock._open_locks[self.filename] += 1
240
225
            self._open(filename, 'rb')
433
418
            DWORD,                 # dwFlagsAndAttributes
434
419
            HANDLE                 # hTemplateFile
435
420
        )((_function_name, ctypes.windll.kernel32))
436
 
 
 
421
    
437
422
    INVALID_HANDLE_VALUE = -1
438
 
 
 
423
    
439
424
    GENERIC_READ = 0x80000000
440
425
    GENERIC_WRITE = 0x40000000
441
426
    FILE_SHARE_READ = 1
442
427
    OPEN_ALWAYS = 4
443
428
    FILE_ATTRIBUTE_NORMAL = 128
444
 
 
 
429
    
445
430
    ERROR_ACCESS_DENIED = 5
446
431
    ERROR_SHARING_VIOLATION = 32
447
432
 
518
503
# We default to using the first available lock class.
519
504
_lock_type, WriteLock, ReadLock = _lock_classes[0]
520
505
 
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