MergeProcess: cache syncfs libc library lookup
authorZac Medico <zmedico@gentoo.org>
Thu, 25 Oct 2012 09:32:35 +0000 (02:32 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 25 Oct 2012 09:35:02 +0000 (02:35 -0700)
pym/portage/dbapi/_MergeProcess.py
pym/portage/dbapi/vartree.py

index 829a3d7ce6932d5015b1ed8a1eea19d25053b810..9be68d3f5621ee6e8eb5ec8b7c69b9e24329cc11 100644 (file)
@@ -10,6 +10,7 @@ import errno
 import fcntl
 import portage
 from portage import os, _unicode_decode
+from portage.dbapi.vartree import _get_syncfs
 import portage.elog.messages
 from portage.util._async.ForkProcess import ForkProcess
 
@@ -40,6 +41,11 @@ class MergeProcess(ForkProcess):
                        settings.reset()
                        settings.setcpv(cpv, mydb=self.mydbapi)
 
+               # This caches the libc library lookup in the current
+               # process, so that it's only done once rather than
+               # for each child process.
+               _get_syncfs()
+
                # Inherit stdin by default, so that the pdb SIGUSR1
                # handler is usable for the subprocess.
                if self.fd_pipes is None:
index edc477a09ba4c6d9fba07045d804efab0bfe27f1..beaeda7300fb3b82c842e6abae50b498c460e8a8 100644 (file)
@@ -4694,7 +4694,7 @@ class dblink(object):
                        "merge-sync" not in self.settings.features:
                        return
 
-               syncfs = self._get_syncfs()
+               syncfs = _get_syncfs()
                if syncfs is None:
                        try:
                                proc = subprocess.Popen(["sync"])
@@ -4716,19 +4716,6 @@ class dblink(object):
                                        finally:
                                                os.close(fd)
 
-       def _get_syncfs(self):
-               if platform.system() == "Linux":
-                       filename = find_library("c")
-                       if filename is not None:
-                               library = LoadLibrary(filename)
-                               if library is not None:
-                                       try:
-                                               return library.syncfs
-                                       except AttributeError:
-                                               pass
-
-               return None
-
        def merge(self, mergeroot, inforoot, myroot=None, myebuild=None, cleanup=0,
                mydbapi=None, prev_mtimes=None, counter=None):
                """
@@ -4907,6 +4894,19 @@ class dblink(object):
                finally:
                        self.unlockdb()
 
+def _get_syncfs():
+       if platform.system() == "Linux":
+               filename = find_library("c")
+               if filename is not None:
+                       library = LoadLibrary(filename)
+                       if library is not None:
+                               try:
+                                       return library.syncfs
+                               except AttributeError:
+                                       pass
+
+       return None
+
 def merge(mycat, mypkg, pkgloc, infloc,
        myroot=None, settings=None, myebuild=None,
        mytree=None, mydbapi=None, vartree=None, prev_mtimes=None, blockers=None,