aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-08-14 14:58:25 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-08-14 14:58:25 +0000
commit8c159f511ee47855454f1c45916c9b3a08c83bbf (patch)
treefb0ebcc589b1af5a73e929e7ed29a728a4379638
parentbb9dba60f87d94ef62b77369a794634bac174dd6 (diff)
downloadpaludis-8c159f511ee47855454f1c45916c9b3a08c83bbf.tar.gz
paludis-8c159f511ee47855454f1c45916c9b3a08c83bbf.tar.xz
(python) Thread safety.
-rw-r--r--python/Makefile.am1
-rw-r--r--python/mutex.cc32
-rw-r--r--python/mutex.hh34
-rw-r--r--python/paludis_python.hh1
-rw-r--r--python/query.cc10
5 files changed, 78 insertions, 0 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 37ca2dd..e0fd749 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -57,6 +57,7 @@ IF_PYTHON_SOURCES = \
fs_entry.cc \
mask.cc \
metadata_key.hh metadata_key.cc \
+ mutex.hh mutex.cc \
name.cc \
log.cc \
package_database.cc \
diff --git a/python/mutex.cc b/python/mutex.cc
new file mode 100644
index 0000000..59602a2
--- /dev/null
+++ b/python/mutex.cc
@@ -0,0 +1,32 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński <peper@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "mutex.hh"
+
+namespace paludis
+{
+ namespace python
+ {
+ Mutex & get_mutex()
+ {
+ static Mutex mutex;
+ return mutex;
+ }
+ } // namespace paludis::python
+} // namespace paludis
diff --git a/python/mutex.hh b/python/mutex.hh
new file mode 100644
index 0000000..5244ea7
--- /dev/null
+++ b/python/mutex.hh
@@ -0,0 +1,34 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński <peper@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PYTHON_MUTEX_HH
+#define PALUDIS_GUARD_PYTHON_MUTEX_HH 1
+
+#include <paludis/util/mutex.hh>
+
+namespace paludis
+{
+ namespace python
+ {
+ //global mutex for thread safety.
+ Mutex & PALUDIS_VISIBLE get_mutex();
+ } // namespace paludis::python
+} // namespace paludis
+
+#endif
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 95e9ebb..7bbfb9e 100644
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -20,6 +20,7 @@
#ifndef PALUDIS_GUARD_PYTHON_PALUDIS_PYTHON_HH
#define PALUDIS_GUARD_PYTHON_PALUDIS_PYTHON_HH 1
+#include <python/mutex.hh>
#include <paludis/util/tr1_memory.hh>
#include <paludis/util/stringify.hh>
diff --git a/python/query.cc b/python/query.cc
index c7d1325..8f894fb 100644
--- a/python/query.cc
+++ b/python/query.cc
@@ -119,6 +119,8 @@ struct PythonQueryWrapper :
{
tr1::shared_ptr<RepositoryNameSequence> repositories(const Environment & e) const
{
+ Lock l(get_mutex());
+
if (bp::override f = get_override("repositories"))
return f(boost::cref(e));
return PythonQuery::repositories(e);
@@ -132,6 +134,8 @@ struct PythonQueryWrapper :
tr1::shared_ptr<CategoryNamePartSet> categories(const Environment & e,
tr1::shared_ptr<const RepositoryNameSequence> r) const
{
+ Lock l(get_mutex());
+
if (bp::override f = get_override("categories"))
return f(boost::cref(e), r);
return PythonQuery::categories(e, r);
@@ -147,6 +151,8 @@ struct PythonQueryWrapper :
tr1::shared_ptr<const RepositoryNameSequence> r,
tr1::shared_ptr<const CategoryNamePartSet> c) const
{
+ Lock l(get_mutex());
+
if (bp::override f = get_override("packages"))
return f(boost::cref(e), r, c);
return PythonQuery::packages(e, r, c);
@@ -163,6 +169,8 @@ struct PythonQueryWrapper :
tr1::shared_ptr<const RepositoryNameSequence> r,
tr1::shared_ptr<const QualifiedPackageNameSet> q) const
{
+ Lock l(get_mutex());
+
if (bp::override f = get_override("ids"))
return f(boost::cref(e), r, q);
return PythonQuery::ids(e, r, q);
@@ -177,6 +185,8 @@ struct PythonQueryWrapper :
std::string as_human_readable_string() const
{
+ Lock l(get_mutex());
+
if (bp::override f = get_override("as_human_readable_string"))
return f();
else