counter_tick_core: don't lock if parallel-install
authorZac Medico <zmedico@gentoo.org>
Sun, 15 May 2011 09:30:15 +0000 (02:30 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 May 2011 09:30:15 +0000 (02:30 -0700)
This is the same as commit 461564ae94ff936918eeaa18493bc1da3846796f
but this time with comments that make sense.

pym/portage/dbapi/vartree.py

index 40f0cfb0fd6bc243dbf255b3827ce87b48699c88..d602a37c01776e13c0db079d699cf821cc0a1197 100644 (file)
@@ -815,7 +815,18 @@ class vardbapi(dbapi):
                """
                myroot = None
                mycpv = None
-               self.lock()
+               locked_vdb = False
+               if "parallel-install" not in self.settings.features:
+                       # If parallel-install is enabled, it's unsafe to
+                       # lock the vdb here because it can deadlock the
+                       # Scheduler by preventing it from servicing its
+                       # poll loop which is essential for at least a
+                       # couple of reasons:
+                       # 1) releasing locks held by the scheduler
+                       # 2) handling output of subprocesses so that they
+                       #    don't deadlock due to blocking on stdout
+                       self.lock()
+                       locked_vdb = True
                try:
                        counter = self.get_counter_tick_core() - 1
                        if self._cached_counter != counter:
@@ -829,7 +840,8 @@ class vardbapi(dbapi):
                                        write_atomic(self._counter_path, str(counter))
                                self._cached_counter = counter
                finally:
-                       self.unlock()
+                       if locked_vdb:
+                               self.unlock()
 
                return counter