~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Martin Pool
  • Date: 2010-01-12 01:44:13 UTC
  • mto: (4634.119.3 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: mbp@sourcefrog.net-20100112014413-uw90vrssc3trlzmt
Refuse to build with pyrex 0.9.4*

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
import errno
38
38
import os
39
39
import sys
 
40
import warnings
40
41
 
41
42
from bzrlib import (
 
43
    debug,
42
44
    errors,
43
45
    osutils,
44
46
    trace,
86
88
                             self.lock_url, self.details)
87
89
 
88
90
 
 
91
def cant_unlock_not_held(locked_object):
 
92
    """An attempt to unlock failed because the object was not locked.
 
93
 
 
94
    This provides a policy point from which we can generate either a warning 
 
95
    or an exception.
 
96
    """
 
97
    # This is typically masking some other error and called from a finally
 
98
    # block, so it's useful to have the option not to generate a new error
 
99
    # here.  You can use -Werror to make it fatal.  It should possibly also
 
100
    # raise LockNotHeld.
 
101
    if 'unlock' in debug.debug_flags:
 
102
        warnings.warn("%r is already unlocked" % (locked_object,),
 
103
            stacklevel=3)
 
104
    else:
 
105
        raise errors.LockNotHeld(locked_object)
 
106
 
 
107
 
89
108
try:
90
109
    import fcntl
91
110
    have_fcntl = True
171
190
            if self.filename in _fcntl_WriteLock._open_locks:
172
191
                self._clear_f()
173
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,))
174
200
 
175
201
            self._open(self.filename, 'rb+')
176
202
            # reserve a slot for this lock - even if the lockf call fails,
201
227
        def __init__(self, filename):
202
228
            super(_fcntl_ReadLock, self).__init__()
203
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,))
204
238
            _fcntl_ReadLock._open_locks.setdefault(self.filename, 0)
205
239
            _fcntl_ReadLock._open_locks[self.filename] += 1
206
240
            self._open(filename, 'rb')
399
433
            DWORD,                 # dwFlagsAndAttributes
400
434
            HANDLE                 # hTemplateFile
401
435
        )((_function_name, ctypes.windll.kernel32))
402
 
    
 
436
 
403
437
    INVALID_HANDLE_VALUE = -1
404
 
    
 
438
 
405
439
    GENERIC_READ = 0x80000000
406
440
    GENERIC_WRITE = 0x40000000
407
441
    FILE_SHARE_READ = 1
408
442
    OPEN_ALWAYS = 4
409
443
    FILE_ATTRIBUTE_NORMAL = 128
410
 
    
 
444
 
411
445
    ERROR_ACCESS_DENIED = 5
412
446
    ERROR_SHARING_VIOLATION = 32
413
447