From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:2.1.9 commit in: pym/portage/dbapi/
Date: Sun, 8 May 2011 20:50:11 +0000 (UTC) [thread overview]
Message-ID: <803ae0b64fd86c66100dc4cf2bd6bb5f2ca71439.zmedico@gentoo> (raw)
commit: 803ae0b64fd86c66100dc4cf2bd6bb5f2ca71439
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May 8 02:57:29 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May 8 18:50:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=803ae0b6
Add vardbapi reentrant lock/unlock methods.
---
pym/portage/dbapi/vartree.py | 61 ++++++++++++++++++++++++++---------------
1 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index c9a02d5..7bef2fc 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -128,6 +128,10 @@ class vardbapi(dbapi):
DeprecationWarning, stacklevel=2)
self._eroot = settings['EROOT']
+ self._dbroot = self._eroot + VDB_PATH
+ self._lock = None
+ self._lock_count = 0
+
if vartree is None:
vartree = portage.db[self.root]["vartree"]
self.vartree = vartree
@@ -164,6 +168,38 @@ class vardbapi(dbapi):
rValue = _os.path.join(rValue, filename)
return rValue
+ def lock(self):
+ """
+ Acquire a reentrant lock, blocking, for cooperation with concurrent
+ processes. State is inherited by subprocesses, allowing subprocesses
+ to reenter a lock that was acquired by a parent process. However,
+ a lock can be released only by the same process that acquired it.
+ """
+ if self._lock_count:
+ self._lock_count += 1
+ else:
+ if self._lock is not None:
+ raise AssertionError("already locked")
+ # At least the parent needs to exist for the lock file.
+ ensure_dirs(self._dbroot)
+ self._lock = lockdir(self._dbroot)
+ self._lock_count += 1
+
+ def unlock(self):
+ """
+ Release a lock, decrementing the recursion level. Each unlock() call
+ must be matched with a prior lock() call, or else an AssertionError
+ will be raised if unlock() is called while not locked.
+ """
+ if self._lock_count > 1:
+ self._lock_count -= 1
+ else:
+ if self._lock is None:
+ raise AssertionError("not locked")
+ self._lock_count = 0
+ unlockdir(self._lock)
+ self._lock = None
+
def _bump_mtime(self, cpv):
"""
This is called before an after any modifications, so that consumers
@@ -1239,9 +1275,6 @@ class dblink(object):
self.dbpkgdir = self.dbcatdir+"/"+pkg
self.dbtmpdir = self.dbcatdir+"/-MERGING-"+pkg
self.dbdir = self.dbpkgdir
-
- self._lock_vdb = None
-
self.settings = mysettings
self._verbose = self.settings.get("PORTAGE_VERBOSE") == "1"
@@ -1280,26 +1313,10 @@ class dblink(object):
self._get_protect_obj().updateprotect()
def lockdb(self):
- if self._lock_vdb:
- raise AssertionError("Lock already held.")
- # At least the parent needs to exist for the lock file.
- ensure_dirs(self.dbroot)
- if self._scheduler is None:
- self._lock_vdb = lockdir(self.dbroot)
- else:
- async_lock = AsynchronousLock(path=self.dbroot,
- scheduler=self._scheduler)
- async_lock.start()
- async_lock.wait()
- self._lock_vdb = async_lock
+ self.vartree.dbapi.lock()
def unlockdb(self):
- if self._lock_vdb is not None:
- if isinstance(self._lock_vdb, AsynchronousLock):
- self._lock_vdb.unlock()
- else:
- unlockdir(self._lock_vdb)
- self._lock_vdb = None
+ self.vartree.dbapi.unlock()
def getpath(self):
"return path to location of db information (for >>> informational display)"
@@ -4052,8 +4069,8 @@ def unmerge(cat, pkg, myroot=None, settings=None,
mylink = dblink(cat, pkg, settings=settings, treetype="vartree",
vartree=vartree, scheduler=scheduler)
vartree = mylink.vartree
+ mylink.lockdb()
try:
- mylink.lockdb()
if mylink.exists():
retval = mylink.unmerge(ldpath_mtimes=ldpath_mtimes)
if retval == os.EX_OK:
next reply other threads:[~2011-05-08 20:51 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-08 20:50 Zac Medico [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-05-27 2:56 [gentoo-commits] proj/portage:2.1.9 commit in: pym/portage/dbapi/ Zac Medico
2011-05-27 2:16 Zac Medico
2011-05-27 0:05 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-26 6:18 Zac Medico
2011-05-12 20:13 Zac Medico
2011-05-12 17:58 Zac Medico
2011-05-12 7:13 Zac Medico
2011-05-12 5:47 Zac Medico
2011-05-12 5:47 Zac Medico
2011-05-12 5:24 Zac Medico
2011-05-12 5:24 Zac Medico
2011-05-12 5:24 Zac Medico
2011-05-12 5:24 Zac Medico
2011-05-12 5:24 Zac Medico
2011-05-12 5:24 Zac Medico
2011-05-08 20:50 Zac Medico
2011-05-08 20:50 Zac Medico
2011-05-08 20:50 Zac Medico
2011-05-04 20:03 Zac Medico
2011-03-27 21:00 Zac Medico
2011-03-18 21:12 Zac Medico
2011-03-14 16:24 Zac Medico
2011-03-14 16:24 Zac Medico
2011-03-14 16:24 Zac Medico
2011-03-01 21:54 Zac Medico
2011-03-01 21:06 Zac Medico
2011-03-01 20:55 Zac Medico
2011-03-01 20:55 Zac Medico
2011-03-01 20:55 Zac Medico
2011-02-14 4:31 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=803ae0b64fd86c66100dc4cf2bd6bb5f2ca71439.zmedico@gentoo \
--to=zmedico@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox