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 1SkEn7-00074U-EX for garchives@archives.gentoo.org; Thu, 28 Jun 2012 13:29:49 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6401AE0730; Thu, 28 Jun 2012 13:29:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 22D72E0730 for ; Thu, 28 Jun 2012 13:29:06 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3D0FC1B4052 for ; Thu, 28 Jun 2012 13:29:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id B197DE543C for ; Thu, 28 Jun 2012 13:29:03 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1340889935.7d3d0d7ffc8b2c24198da55dfc4812b90c48e4f9.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/depres/depresolver.py X-VCS-Directories: roverlay/depres/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 7d3d0d7ffc8b2c24198da55dfc4812b90c48e4f9 X-VCS-Branch: master Date: Thu, 28 Jun 2012 13:29:03 +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: 8760c8a7-4e3f-48be-a9cb-91918173e8e9 X-Archives-Hash: f93fb12bafccb545a6412f2ab4ff2d1c commit: 7d3d0d7ffc8b2c24198da55dfc4812b90c48e4f9 Author: Andr=C3=A9 Erdmann mailerd de> AuthorDate: Thu Jun 28 13:25:35 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Thu Jun 28 13:25:35 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3D7d3d0d7f depresolver: ensure that channel ids are unique modified: roverlay/depres/depresolver.py --- roverlay/depres/depresolver.py | 53 +++++++++++++++++++++++++++++++---= ----- 1 files changed, 42 insertions(+), 11 deletions(-) diff --git a/roverlay/depres/depresolver.py b/roverlay/depres/depresolver= .py index 3b0e481..26040c0 100644 --- a/roverlay/depres/depresolver.py +++ b/roverlay/depres/depresolver.py @@ -22,18 +22,20 @@ from roverlay.depres import simpledeprule, communicat= ion, events # unresolvable deps in a set for should-be faster lookups USING_DEPRES_CACHE =3D True =20 +# if True: verify that channels are unique for a resolver instance +SAFE_CHANNEL_IDS =3D True + class DependencyResolver ( object ): """Main object for dependency resolution.""" =20 - LOGGER =3D logging.getLogger ( "DependencyResolver" ) =20 - NUMTHREADS =3D config.get ( "DEPRES.jobcount", 2 ) + NUMTHREADS =3D config.get ( "DEPRES.jobcount", 0 ) =20 def __init__ ( self ): """Initializes a DependencyResolver.""" =20 # these loggers are temporary helpers - self.logger =3D DependencyResolver.LOGGER + self.logger =3D logging.getLogger ( self.__class__.__name= __ ) self.logger_unresolvable =3D self.logger.getChild ( "UNRESOLVABLE" ) self.logger_resolved =3D self.logger.getChild ( "RESOLVED" ) =20 @@ -54,7 +56,6 @@ class DependencyResolver ( object ): self.listeners =3D list () =20 # fifo queue for dep resolution - # (threads: could use queue.Queue instead of collections.deque) self._depqueue =3D queue.Queue() =20 # the queue of failed dep resolutions @@ -76,6 +77,13 @@ class DependencyResolver ( object ): =20 # list of rule pools that have been created from reading files self.static_rule_pools =3D list () + + + if SAFE_CHANNEL_IDS: + # this lock is used in register_channel + self._chanlock =3D threading.Lock() + # this stores all channel ids ever registered to this resolver + self.all_channel_ids =3D set() # --- end of __init__ (...) --- =20 def _sort ( self ): @@ -184,15 +192,34 @@ class DependencyResolver ( object ): =20 returns: channel """ - if channel in self._depqueue_done: - raise Exception ( "channel is already registered." ) + if SAFE_CHANNEL_IDS: + try: + self._chanlock.acquire() =20 - # register channel and allocate a queue in depqueue_done - self._depqueue_done [channel.ident] =3D queue.Queue() + if channel.ident in self.all_channel_ids: + raise Exception ( "channel id reused!" ) + else: + self.all_channel_ids.add ( channel.ident ) =20 - channel.set_resolver ( - self, channel_queue=3Dself._depqueue_done [channel.ident] - ) + # register channel and allocate a queue in depqueue_done + self._depqueue_done [channel.ident] =3D queue.Queue() + + channel.set_resolver ( + self, channel_queue=3Dself._depqueue_done [channel.ident] + ) + + finally: + self._chanlock.release() + else: + if channel.ident in self._depqueue_done: + raise Exception ( "channel is already registered." ) + + # register channel and allocate a queue in depqueue_done + self._depqueue_done [channel.ident] =3D queue.Queue() + + channel.set_resolver ( + self, channel_queue=3Dself._depqueue_done [channel.ident] + ) =20 return channel # --- end of register_channel (...) --- @@ -408,4 +435,8 @@ class DependencyResolver ( object ): self._mainthread.join() for lis in self.listeners: lis.close() del self.listeners + if SAFE_CHANNEL_IDS: + self.logger.debug ( + "%i channels were in use." % len ( self.all_channel_ids ) + ) # --- end of close (...) ---