Rev 2402: Start adding CountedLock (stub) in http://sourcefrog.net/bzr/no-controlfiles

Martin Pool mbp at sourcefrog.net
Thu Apr 5 08:36:35 BST 2007


At http://sourcefrog.net/bzr/no-controlfiles

------------------------------------------------------------
revno: 2402
revision-id: mbp at sourcefrog.net-20070405073634-nj1kqkt01ctx7eak
parent: mbp at sourcefrog.net-20070405071152-mqx7c8gad3eti1n4
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: no-controlfiles
timestamp: Thu 2007-04-05 17:36:34 +1000
message:
  Start adding CountedLock (stub)
added:
  bzrlib/counted_lock.py         counted_lock.py-20070405073557-tvmrfbnrh71brkoi-1
modified:
  bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
=== added file 'bzrlib/counted_lock.py'
--- a/bzrlib/counted_lock.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/counted_lock.py	2007-04-05 07:36:34 +0000
@@ -0,0 +1,33 @@
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+class CountedLock(object):
+    """Lock decorator that maintains a reentrancy count.
+
+    A single instance of this lock may be acquired any number
+    of times.  Only the initial acquisition/release is passed 
+    through to the underlying lock.
+
+    :ivar _lock_mode: None, or 'r' or 'w'
+    
+    :ivar _lock_count: If _lock_mode is true, a positive count of the number of
+    times the lock has been taken.
+    """
+
+    def peek_lock_mode(self):
+        return self._lock_mode
+

=== modified file 'bzrlib/lockable_files.py'
--- a/bzrlib/lockable_files.py	2007-04-05 07:11:52 +0000
+++ b/bzrlib/lockable_files.py	2007-04-05 07:36:34 +0000
@@ -19,6 +19,9 @@
 #import traceback
 
 import bzrlib
+from bzrlib import (
+    counted_lock,
+    )
 from bzrlib.decorators import (needs_read_lock,
         needs_write_lock)
 import bzrlib.errors as errors
@@ -58,11 +61,6 @@
     OSLocks for the local filesystem.
     """
 
-    # _lock_mode: None, or 'r' or 'w'
-
-    # _lock_count: If _lock_mode is true, a positive count of the number of
-    # times the lock has been taken *by this process*.   
-    
     # If set to False (by a plugin, etc) BzrBranch will not set the
     # mode on created files or directories
     _set_file_mode = True




More information about the bazaar-commits mailing list