From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QJAwT-0000Wl-38 for garchives@archives.gentoo.org; Sun, 08 May 2011 20:51:05 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 34D051C04C; Sun, 8 May 2011 20:50:13 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id E60231C04D for ; Sun, 8 May 2011 20:50:12 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5C0E51BC00A for ; Sun, 8 May 2011 20:50:12 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id B9A227448B for ; Sun, 8 May 2011 20:50:11 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <803ae0b64fd86c66100dc4cf2bd6bb5f2ca71439.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:2.1.9 commit in: pym/portage/dbapi/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dbapi/vartree.py X-VCS-Directories: pym/portage/dbapi/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 803ae0b64fd86c66100dc4cf2bd6bb5f2ca71439 Date: Sun, 8 May 2011 20:50:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 7bcf6e10358c096839f5d02c6745e7ed commit: 803ae0b64fd86c66100dc4cf2bd6bb5f2ca71439 Author: Zac Medico gentoo org> AuthorDate: Sun May 8 02:57:29 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun May 8 18:50:33 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D803ae0b6 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=3D2) =20 self._eroot =3D settings['EROOT'] + self._dbroot =3D self._eroot + VDB_PATH + self._lock =3D None + self._lock_count =3D 0 + if vartree is None: vartree =3D portage.db[self.root]["vartree"] self.vartree =3D vartree @@ -164,6 +168,38 @@ class vardbapi(dbapi): rValue =3D _os.path.join(rValue, filename) return rValue =20 + 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 +=3D 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 =3D lockdir(self._dbroot) + self._lock_count +=3D 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 -=3D 1 + else: + if self._lock is None: + raise AssertionError("not locked") + self._lock_count =3D 0 + unlockdir(self._lock) + self._lock =3D 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 =3D self.dbcatdir+"/"+pkg self.dbtmpdir =3D self.dbcatdir+"/-MERGING-"+pkg self.dbdir =3D self.dbpkgdir - - self._lock_vdb =3D None - self.settings =3D mysettings self._verbose =3D self.settings.get("PORTAGE_VERBOSE") =3D=3D "1" =20 @@ -1280,26 +1313,10 @@ class dblink(object): self._get_protect_obj().updateprotect() =20 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 =3D lockdir(self.dbroot) - else: - async_lock =3D AsynchronousLock(path=3Dself.dbroot, - scheduler=3Dself._scheduler) - async_lock.start() - async_lock.wait() - self._lock_vdb =3D async_lock + self.vartree.dbapi.lock() =20 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 =3D None + self.vartree.dbapi.unlock() =20 def getpath(self): "return path to location of db information (for >>> informational disp= lay)" @@ -4052,8 +4069,8 @@ def unmerge(cat, pkg, myroot=3DNone, settings=3DNon= e, mylink =3D dblink(cat, pkg, settings=3Dsettings, treetype=3D"vartree", vartree=3Dvartree, scheduler=3Dscheduler) vartree =3D mylink.vartree + mylink.lockdb() try: - mylink.lockdb() if mylink.exists(): retval =3D mylink.unmerge(ldpath_mtimes=3Dldpath_mtimes) if retval =3D=3D os.EX_OK: