Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/
Date: Sun, 08 May 2011 04:53:59
Message-Id: 646c21b911ca2d14fb0f8489ff22e05fe9c4199a.zmedico@gentoo
1 commit: 646c21b911ca2d14fb0f8489ff22e05fe9c4199a
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun May 8 02:57:29 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun May 8 04:34:58 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=646c21b9
7
8 Add vardbapi reentrant lock/unlock methods.
9
10 ---
11 pym/portage/dbapi/vartree.py | 54 +++++++++++++++++++++++++++++------------
12 1 files changed, 38 insertions(+), 16 deletions(-)
13
14 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
15 index 7f9fb99..bc9916e 100644
16 --- a/pym/portage/dbapi/vartree.py
17 +++ b/pym/portage/dbapi/vartree.py
18 @@ -131,6 +131,10 @@ class vardbapi(dbapi):
19 DeprecationWarning, stacklevel=2)
20
21 self._eroot = settings['EROOT']
22 + self._dbroot = self._eroot + VDB_PATH
23 + self._lock = None
24 + self._lock_count = 0
25 +
26 if vartree is None:
27 vartree = portage.db[self.root]["vartree"]
28 self.vartree = vartree
29 @@ -167,6 +171,38 @@ class vardbapi(dbapi):
30 rValue = _os.path.join(rValue, filename)
31 return rValue
32
33 + def lock(self):
34 + """
35 + Acquire a reentrant lock, blocking, for cooperation with concurrent
36 + processes. State is inherited by subprocesses, allowing subprocesses
37 + to reenter a lock that was acquired by a parent process. However,
38 + a lock can be released only by the same process that acquired it.
39 + """
40 + if self._lock_count:
41 + self._lock_count += 1
42 + else:
43 + if self._lock is not None:
44 + raise AssertionError("already locked")
45 + # At least the parent needs to exist for the lock file.
46 + ensure_dirs(self._dbroot)
47 + self._lock = lockdir(self._dbroot)
48 + self._lock_count += 1
49 +
50 + def unlock(self):
51 + """
52 + Release a lock, decrementing the recursion level. Each unlock() call
53 + must be matched with a prior lock() call, or else an AssertionError
54 + will be raised if unlock() is called while not locked.
55 + """
56 + if self._lock_count > 1:
57 + self._lock_count -= 1
58 + else:
59 + if self._lock is None:
60 + raise AssertionError("not locked")
61 + self._lock_count = 0
62 + unlockdir(self._lock)
63 + self._lock = None
64 +
65 def _bump_mtime(self, cpv):
66 """
67 This is called before an after any modifications, so that consumers
68 @@ -1226,10 +1262,6 @@ class dblink(object):
69 self.dbpkgdir = self.dbcatdir+"/"+pkg
70 self.dbtmpdir = self.dbcatdir+"/-MERGING-"+pkg
71 self.dbdir = self.dbpkgdir
72 -
73 - self._lock_vdb = None
74 - self._lock_vdb_count = 0
75 -
76 self.settings = mysettings
77 self._verbose = self.settings.get("PORTAGE_VERBOSE") == "1"
78
79 @@ -1269,20 +1301,10 @@ class dblink(object):
80 self._get_protect_obj().updateprotect()
81
82 def lockdb(self):
83 - if self._lock_vdb_count:
84 - self._lock_vdb_count += 1
85 - else:
86 - # At least the parent needs to exist for the lock file.
87 - ensure_dirs(self.dbroot)
88 - self._lock_vdb = lockdir(self.dbroot)
89 + self.vartree.dbapi.lock()
90
91 def unlockdb(self):
92 - if self._lock_vdb_count > 1:
93 - self._lock_vdb_count -= 1
94 - else:
95 - self._lock_vdb_count = 0
96 - unlockdir(self._lock_vdb)
97 - self._lock_vdb = None
98 + self.vartree.dbapi.unlock()
99
100 def getpath(self):
101 "return path to location of db information (for >>> informational display)"