~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

Merge landed readdir acceleration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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
110
110
from bzrlib import (
111
111
    debug,
112
112
    errors,
 
113
    lock,
113
114
    )
114
115
import bzrlib.config
115
116
from bzrlib.errors import (
126
127
        TransportError,
127
128
        UnlockableTransport,
128
129
        )
 
130
from bzrlib.hooks import Hooks
129
131
from bzrlib.trace import mutter, note
130
132
from bzrlib.transport import Transport
131
133
from bzrlib.osutils import rand_chars, format_delta, get_host_name
152
154
_DEFAULT_POLL_SECONDS = 1.0
153
155
 
154
156
 
155
 
class LockDir(object):
156
 
    """Write-lock guarding access to data."""
 
157
class LockDir(lock.Lock):
 
158
    """Write-lock guarding access to data.
 
159
    """
157
160
 
158
161
    __INFO_NAME = '/info'
159
162
 
296
299
            self._locked_via_token = False
297
300
            self._lock_held = False
298
301
        else:
 
302
            old_nonce = self.nonce
299
303
            # rename before deleting, because we can't atomically remove the
300
304
            # whole tree
301
305
            start_time = time.time()
321
325
                self.transport.delete_tree(tmpname)
322
326
            self._trace("... unlock succeeded after %dms",
323
327
                    (time.time() - start_time) * 1000)
 
328
            result = lock.LockResult(self.transport.abspath(self.path),
 
329
                old_nonce)
 
330
            for hook in self.hooks['lock_released']:
 
331
                hook(result)
324
332
 
325
333
    def break_lock(self):
326
334
        """Break a lock not held by this instance of LockDir.
450
458
        """
451
459
        if self._fake_read_lock:
452
460
            raise LockContention(self)
453
 
        return self._attempt_lock()
 
461
        result = self._attempt_lock()
 
462
        hook_result = lock.LockResult(self.transport.abspath(self.path),
 
463
                self.nonce)
 
464
        for hook in self.hooks['lock_acquired']:
 
465
            hook(hook_result)
 
466
        return result
454
467
 
455
468
    def wait_lock(self, timeout=None, poll=None, max_attempts=None):
456
469
        """Wait a certain period for a lock.