aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-04 07:06:25 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-04 07:06:25 +0000
commit48bdff1a499e40190adef7c32ee6469540a50b6e (patch)
tree7b9f4f0aa831ec13f9110b21b783d79ed29beaaf
parent2415f6b3f34965628f50ef42b77367e0aea0ecc8 (diff)
downloadpaludis-48bdff1a499e40190adef7c32ee6469540a50b6e.tar.gz
paludis-48bdff1a499e40190adef7c32ee6469540a50b6e.tar.xz
Nuke futures, parallel_for_each for now
-rw-r--r--paludis/query.cc65
-rw-r--r--paludis/repositories/e/qa/spec_keys.cc3
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/future-impl.hh120
-rw-r--r--paludis/util/future.cc100
-rw-r--r--paludis/util/future.hh132
-rw-r--r--paludis/util/future_TEST.cc89
-rw-r--r--paludis/util/parallel_for_each.cc28
-rw-r--r--paludis/util/parallel_for_each.hh124
-rw-r--r--paludis/util/parallel_for_each_TEST.cc64
-rw-r--r--src/clients/inquisitio/do_search.cc3
-rw-r--r--src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc7
12 files changed, 37 insertions, 700 deletions
diff --git a/paludis/query.cc b/paludis/query.cc
index e1aa792..5488593 100644
--- a/paludis/query.cc
+++ b/paludis/query.cc
@@ -24,7 +24,6 @@
#include <paludis/util/sequence.hh>
#include <paludis/util/set.hh>
#include <paludis/util/make_shared_ptr.hh>
-#include <paludis/util/future-impl.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/package_database.hh>
#include <paludis/environment.hh>
@@ -333,83 +332,83 @@ namespace
tr1::shared_ptr<RepositoryNameSequence>
repositories(const Environment & e) const
{
- Future<tr1::shared_ptr<RepositoryNameSequence> >
- r1(tr1::bind(&QueryDelegate::repositories, q1, tr1::cref(e))),
- r2(tr1::bind(&QueryDelegate::repositories, q2, tr1::cref(e)));
+ tr1::shared_ptr<RepositoryNameSequence>
+ r1(q1->repositories(e)),
+ r2(q2->repositories(e));
- if (r1() && r2())
+ if (r1 && r2)
{
- std::set<RepositoryName, RepositoryNameComparator> s1(r1()->begin(), r1()->end()), s2(r2()->begin(), r2()->end());
+ std::set<RepositoryName, RepositoryNameComparator> s1(r1->begin(), r1->end()), s2(r2->begin(), r2->end());
tr1::shared_ptr<RepositoryNameSequence> result(new RepositoryNameSequence);
std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), result->back_inserter(),
RepositoryNameComparator());
return result;
}
- else if (r1())
- return r1();
+ else if (r1)
+ return r1;
else
- return r2();
+ return r2;
}
tr1::shared_ptr<CategoryNamePartSet>
categories(const Environment & e, tr1::shared_ptr<const RepositoryNameSequence> r) const
{
- Future<tr1::shared_ptr<CategoryNamePartSet> >
- r1(tr1::bind(&QueryDelegate::categories, q1, tr1::cref(e), tr1::cref(r))),
- r2(tr1::bind(&QueryDelegate::categories, q2, tr1::cref(e), tr1::cref(r)));
+ tr1::shared_ptr<CategoryNamePartSet>
+ r1(q1->categories(e, r)),
+ r2(q2->categories(e, r));
- if (r1() && r2())
+ if (r1 && r2)
{
tr1::shared_ptr<CategoryNamePartSet> result(new CategoryNamePartSet);
- std::set_intersection(r1()->begin(), r1()->end(), r2()->begin(), r2()->end(), result->inserter());
+ std::set_intersection(r1->begin(), r1->end(), r2->begin(), r2->end(), result->inserter());
return result;
}
- else if (r1())
- return r1();
+ else if (r1)
+ return r1;
else
- return r2();
+ return r2;
}
tr1::shared_ptr<QualifiedPackageNameSet>
packages(const Environment & e, tr1::shared_ptr<const RepositoryNameSequence> r,
tr1::shared_ptr<const CategoryNamePartSet> c) const
{
- Future<tr1::shared_ptr<QualifiedPackageNameSet> >
- r1(tr1::bind(&QueryDelegate::packages, q1, tr1::cref(e), tr1::cref(r), tr1::cref(c))),
- r2(tr1::bind(&QueryDelegate::packages, q2, tr1::cref(e), tr1::cref(r), tr1::cref(c)));
+ tr1::shared_ptr<QualifiedPackageNameSet>
+ r1(q1->packages(e, r, c)),
+ r2(q2->packages(e, r, c));
- if (r1() && r2())
+ if (r1 && r2)
{
tr1::shared_ptr<QualifiedPackageNameSet> result(new QualifiedPackageNameSet);
- std::set_intersection(r1()->begin(), r1()->end(), r2()->begin(), r2()->end(), result->inserter());
+ std::set_intersection(r1->begin(), r1->end(), r2->begin(), r2->end(), result->inserter());
return result;
}
- else if (r1())
- return r1();
+ else if (r1)
+ return r1;
else
- return r2();
+ return r2;
}
tr1::shared_ptr<PackageIDSequence>
ids(const Environment & e, tr1::shared_ptr<const RepositoryNameSequence> r,
tr1::shared_ptr<const QualifiedPackageNameSet> q) const
{
- Future<tr1::shared_ptr<PackageIDSequence> >
- r1(tr1::bind(&QueryDelegate::ids, q1, tr1::cref(e), tr1::cref(r), tr1::cref(q))),
- r2(tr1::bind(&QueryDelegate::ids, q2, tr1::cref(e), tr1::cref(r), tr1::cref(q)));
+ tr1::shared_ptr<PackageIDSequence>
+ r1(q1->ids(e, r, q)),
+ r2(q2->ids(e, r, q));
- if (r1() && r2())
+ if (r1 && r2)
{
std::set<tr1::shared_ptr<const PackageID>, PackageIDSetComparator>
- s1(r1()->begin(), r1()->end()), s2(r2()->begin(), r2()->end());
+ s1(r1->begin(), r1->end()), s2(r2->begin(), r2->end());
tr1::shared_ptr<PackageIDSequence> result(new PackageIDSequence);
std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), result->back_inserter(), PackageIDSetComparator());
return result;
}
- else if (r1())
- return r1();
+ else if (r1)
+ return r1;
else
- return r2();
+ return r2;
}
};
}
diff --git a/paludis/repositories/e/qa/spec_keys.cc b/paludis/repositories/e/qa/spec_keys.cc
index 0660597..a7b130f 100644
--- a/paludis/repositories/e/qa/spec_keys.cc
+++ b/paludis/repositories/e/qa/spec_keys.cc
@@ -32,7 +32,6 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/iterator_funcs.hh>
-#include <paludis/util/parallel_for_each.hh>
#include <paludis/util/mutex.hh>
#include <paludis/util/options.hh>
#include <paludis/util/log.hh>
@@ -425,7 +424,7 @@ paludis::erepository::spec_keys_check(
using namespace tr1::placeholders;
CheckForwarder f(entry, reporter, id, name);
- parallel_for_each(id->begin_metadata(), id->end_metadata(), tr1::bind(&CheckForwarder::visit_sptr, &f, _1));
+ std::for_each(id->begin_metadata(), id->end_metadata(), tr1::bind(&CheckForwarder::visit_sptr, &f, _1));
return true;
}
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index ab35915..514823f 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -20,7 +20,6 @@ add(`dir_iterator', `hh', `cc', `test', `testscript')
add(`exception', `hh', `cc')
add(`fast_unique_copy', `hh', `test')
add(`fd_output_stream', `hh')
-add(`future', `hh', `impl', `cc', `test')
add(`fs_entry', `hh', `cc', `fwd', `test', `testscript')
add(`fd_holder', `hh')
add(`graph', `hh', `cc', `fwd', `impl', `test')
@@ -39,7 +38,6 @@ add(`no_type', `hh')
add(`operators', `hh')
add(`options', `hh', `fwd', `cc', `test')
add(`output_wrapper', `test', `testscript')
-add(`parallel_for_each', `hh', `cc', `test')
add(`pipe', `hh', `cc')
add(`private_implementation_pattern', `hh', `impl')
add(`pstream', `hh', `cc', `test')
diff --git a/paludis/util/future-impl.hh b/paludis/util/future-impl.hh
deleted file mode 100644
index e53eefc..0000000
--- a/paludis/util/future-impl.hh
+++ /dev/null
@@ -1,120 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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_PALUDIS_UTIL_FUTURE_IMPL_HH
-#define PALUDIS_GUARD_PALUDIS_UTIL_FUTURE_IMPL_HH 1
-
-#include <paludis/util/future.hh>
-#include <paludis/util/mutex.hh>
-#include <paludis/util/condition_variable.hh>
-#include <paludis/util/tr1_memory.hh>
-#include <paludis/util/destringify.hh>
-#include <paludis/util/private_implementation_pattern-impl.hh>
-
-namespace paludis
-{
- template <typename T_>
- void adapt_for_future(
- tr1::function<T_ () throw ()> f,
- tr1::shared_ptr<tr1::shared_ptr<T_> > result,
- tr1::shared_ptr<Mutex> mutex,
- tr1::shared_ptr<ConditionVariable> condition);
-
- /**
- * Implementation data for a Future.
- *
- * \ingroup g_threads
- * \nosubgrouping
- */
- template <>
- template <typename T_>
- struct Implementation<Future<T_> >
- {
- const tr1::function<T_ () throw ()> f;
- mutable tr1::shared_ptr<tr1::shared_ptr<T_> > result;
- mutable tr1::shared_ptr<Mutex> mutex;
- mutable tr1::shared_ptr<ConditionVariable> condition;
-
- Implementation(const tr1::function<T_ () throw ()> & fn) :
- f(fn),
- result(new tr1::shared_ptr<T_>),
- mutex(new Mutex),
- condition(new ConditionVariable)
- {
- FutureActionQueue::get_instance()->enqueue(tr1::bind(paludis::adapt_for_future<T_>, f, result, mutex, condition));
- }
- };
-}
-
-template <typename T_>
-paludis::Future<T_>::Future(const tr1::function<T_ () throw ()> & f) :
- PrivateImplementationPattern<Future<T_> >(new Implementation<Future<T_> >(f))
-{
-}
-
-template <typename T_>
-paludis::Future<T_>::~Future()
-{
- Lock l(*_imp->mutex);
- if (! *_imp->result)
- {
- _imp->result->reset(new T_(_imp->f()));
- _imp->condition->broadcast();
- }
-}
-
-template <typename T_>
-T_
-paludis::Future<T_>::operator() () const
-{
- Lock l(*_imp->mutex);
-
- if (! *_imp->result)
- {
- _imp->result->reset(new T_(_imp->f()));
- _imp->condition->broadcast();
- }
-
- return **_imp->result;
-}
-
-template <typename T_>
-void paludis::adapt_for_future(
- tr1::function<T_ () throw ()> f,
- tr1::shared_ptr<tr1::shared_ptr<T_> > result,
- tr1::shared_ptr<Mutex> mutex,
- tr1::shared_ptr<ConditionVariable> condition)
-{
- try
- {
- TryLock l(*mutex);
- if (l())
- {
- if (! *result)
- result->reset(new T_(f()));
- condition->broadcast();
- }
- }
- catch (...)
- {
- // exception will be raised when operator() is called
- }
-}
-
-#endif
diff --git a/paludis/util/future.cc b/paludis/util/future.cc
deleted file mode 100644
index 7d0bd69..0000000
--- a/paludis/util/future.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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 <paludis/util/future.hh>
-#include <paludis/util/future-impl.hh>
-#include <paludis/util/instantiation_policy-impl.hh>
-#include <paludis/util/system.hh>
-#include <paludis/util/destringify.hh>
-
-using namespace paludis;
-
-template class InstantiationPolicy<FutureActionQueue, instantiation_method::SingletonTag>;
-
-FutureActionQueue::FutureActionQueue() :
- ActionQueue(destringify<int>(getenv_with_default("PALUDIS_FUTURE_THREAD_COUNT", "5")), false)
-{
-}
-
-FutureActionQueue::~FutureActionQueue()
-{
-}
-
-namespace
-{
- unsigned make_non_void(const tr1::function<void () throw ()> & f)
- {
- f();
- return 0;
- }
-}
-
-namespace paludis
-{
- template <>
- template <>
- struct Implementation<Future<void> >
- {
- const tr1::function<void () throw ()> f;
- const tr1::function<unsigned () throw ()> adapted_f;
- mutable tr1::shared_ptr<tr1::shared_ptr<unsigned > > result;
- mutable tr1::shared_ptr<Mutex> mutex;
- mutable tr1::shared_ptr<ConditionVariable> condition;
-
- Implementation(const tr1::function<void () throw ()> & fn) :
- f(fn),
- adapted_f(tr1::bind(&make_non_void, fn)),
- result(new tr1::shared_ptr<unsigned >),
- mutex(new Mutex),
- condition(new ConditionVariable)
- {
- FutureActionQueue::get_instance()->enqueue(
- tr1::bind(&adapt_for_future<unsigned>, adapted_f, result, mutex, condition));
- }
- };
-}
-
-Future<void>::Future(const tr1::function<void () throw ()> & f) :
- PrivateImplementationPattern<Future<void> >(new Implementation<Future<void> >(f))
-{
-}
-
-Future<void>::~Future()
-{
- Lock l(*_imp->mutex);
- if (! *_imp->result)
- {
- _imp->f();
- _imp->result->reset(new unsigned(0));
- _imp->condition->broadcast();
- }
-}
-
-void
-Future<void>::operator() () const
-{
- Lock l(*_imp->mutex);
- if (! *_imp->result)
- {
- _imp->f();
- _imp->result->reset(new unsigned(0));
- _imp->condition->broadcast();
- }
-}
-
diff --git a/paludis/util/future.hh b/paludis/util/future.hh
deleted file mode 100644
index 14c1f7f..0000000
--- a/paludis/util/future.hh
+++ /dev/null
@@ -1,132 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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_PALUDIS_UTIL_FUTURE_HH
-#define PALUDIS_GUARD_PALUDIS_UTIL_FUTURE_HH 1
-
-#include <paludis/util/attributes.hh>
-#include <paludis/util/tr1_functional.hh>
-#include <paludis/util/private_implementation_pattern.hh>
-#include <paludis/util/instantiation_policy.hh>
-#include <paludis/util/action_queue.hh>
-
-/** \file
- * Declarations for the Future class.
- *
- * \ingroup g_threads
- *
- * \section Examples
- *
- * - None at this time.
- */
-
-namespace paludis
-{
- /**
- * Internal use by Future.
- *
- * \ingroup g_threads
- * \since 0.26
- * \nosubgrouping
- */
- class PALUDIS_VISIBLE FutureActionQueue :
- public ActionQueue,
- public InstantiationPolicy<FutureActionQueue, instantiation_method::SingletonTag>
- {
- friend class InstantiationPolicy<FutureActionQueue, instantiation_method::SingletonTag>;
-
- public:
- ///\name Basic operations
- ///\{
-
- FutureActionQueue();
- ~FutureActionQueue();
-
- ///\}
- };
-
- /**
- * A Future<T_> holds an expression whose result will be needed sometime in the
- * future.
- *
- * If threading is disabled, the result is calculated when it is needed.
- *
- * If threading is enabled, the expression is queued in FutureActionQueue,
- * where it will be executed at some point in the future. If it is needed
- * before FutureActionQueue has executed, it is executed at that point in
- * the active thread.
- *
- * \ingroup g_threads
- * \since 0.26
- * \nosubgrouping
- */
- template <typename T_>
- class PALUDIS_VISIBLE Future :
- private PrivateImplementationPattern<Future<T_> >
- {
- private:
- using PrivateImplementationPattern<Future<T_> >::_imp;
-
- public:
- ///\name Basic operations
- ///\{
-
- Future(const tr1::function<T_ () throw ()> &);
- ~Future();
-
- ///\}
-
- /**
- * Fetch a copy of our result. If our result has not yet been
- * calculated, calculate it first.
- */
- T_ operator() () const PALUDIS_ATTRIBUTE((warn_unused_result));
- };
-
- /**
- * Specialisation of Future for expressions with no result.
- *
- * \ingroup g_threads
- * \since 0.26
- * \nosubgrouping
- */
- template <>
- class PALUDIS_VISIBLE Future<void> :
- private PrivateImplementationPattern<Future<void> >
- {
- private:
- using PrivateImplementationPattern<Future<void> >::_imp;
-
- public:
- ///\name Basic operations
- ///\{
-
- Future(const tr1::function<void () throw ()> &);
- ~Future();
-
- ///\}
-
- /**
- * Evaluate our expression, if it has not already been evaluated.
- */
- void operator() () const;
- };
-}
-
-#endif
diff --git a/paludis/util/future_TEST.cc b/paludis/util/future_TEST.cc
deleted file mode 100644
index 777a7c9..0000000
--- a/paludis/util/future_TEST.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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 <paludis/util/future-impl.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-
-using namespace paludis;
-using namespace test;
-
-namespace
-{
- int f()
- {
- return 42;
- }
-
- int g()
- {
- Future<int> r1(&f), r2(&f), r3(&f), r4(&f);
- return r1() + r2() + r3() - r4();
- }
-
- void h(int & i)
- {
- i = 42;
- }
-}
-
-namespace test_cases
-{
- struct FutureTest : TestCase
- {
- FutureTest() : TestCase("future") { }
-
- void run()
- {
- Future<int> f1(&f);
- TEST_CHECK_EQUAL(f1(), 42);
- TEST_CHECK_EQUAL(f1(), 42);
- }
- } test_future;
-
- struct FutureFutureTest : TestCase
- {
- FutureFutureTest() : TestCase("future future") { }
-
- void run()
- {
- Future<int> f1(&g), f2(&g);
- TEST_CHECK_EQUAL(f1(), 84);
- TEST_CHECK_EQUAL(f2(), 84);
- }
- } test_future_future;
-
- struct VoidFutureTest : TestCase
- {
- VoidFutureTest() : TestCase("void future") { }
-
- void run()
- {
- int x(17), y(23);
- {
- Future<void> f1(tr1::bind(&h, tr1::ref(x))), f2(tr1::bind(&h, tr1::ref(y)));
- f1();
- TEST_CHECK_EQUAL(x, 42);
- }
- TEST_CHECK_EQUAL(y, 42);
- }
- } test_void_future;
-}
-
-
diff --git a/paludis/util/parallel_for_each.cc b/paludis/util/parallel_for_each.cc
deleted file mode 100644
index b7d673a..0000000
--- a/paludis/util/parallel_for_each.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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 <paludis/util/parallel_for_each.hh>
-#include <paludis/util/sequence-impl.hh>
-#include <paludis/util/future-impl.hh>
-
-using namespace paludis;
-
-template class Sequence<tr1::shared_ptr<Future<void> > >;
-template class Future<void>;
-
diff --git a/paludis/util/parallel_for_each.hh b/paludis/util/parallel_for_each.hh
deleted file mode 100644
index 829b201..0000000
--- a/paludis/util/parallel_for_each.hh
+++ /dev/null
@@ -1,124 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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_PALUDIS_UTIL_PARALLEL_FOR_EACH_HH
-#define PALUDIS_GUARD_PALUDIS_UTIL_PARALLEL_FOR_EACH_HH 1
-
-#include <paludis/util/future.hh>
-#include <paludis/util/sequence.hh>
-#include <paludis/util/make_shared_ptr.hh>
-#include <paludis/util/tr1_memory.hh>
-#include <paludis/util/tr1_type_traits.hh>
-
-#ifndef PALUDIS_ENABLE_THREADS
-# include <algorithm>
-#endif
-
-namespace paludis
-{
- /**
- * Advance an iterator by up to the specified amount, not going past another
- * iterator.
- *
- * \ingroup g_iterator
- * \since 0.26
- * \nosubgrouping
- */
- template <typename I_, bool is_random_access_>
- struct CappedAdvance
- {
- typedef typename std::iterator_traits<I_>::difference_type Distance;
- static void advance(I_ & cur, const I_ & end, Distance d)
- {
- for (Distance x(0) ; x < d ; ++x, ++cur)
- if (cur == end)
- break;
- }
- };
-
- /**
- * Advance an iterator by up to the specified amount, not going past another
- * iterator.
- *
- * \ingroup g_iterator
- * \since 0.26
- * \nosubgrouping
- */
- template <typename I_>
- struct CappedAdvance<I_, true>
- {
- typedef typename std::iterator_traits<I_>::difference_type Distance;
- static void advance(I_ & cur, const I_ & end, Distance d)
- {
- if (end - cur > d)
- cur += d;
- else
- cur = end;
- }
- };
-
- /**
- * Used by parallel_for_each to do one thread's work.
- *
- * \ingroup g_threads
- * \since 0.26
- */
- template <typename I_, typename P_>
- void parallel_for_each_worker(I_ cur, const I_ & end, const unsigned partition_size, const P_ & op)
- {
- while (cur != end)
- {
- op(*cur);
- CappedAdvance<I_, tr1::is_same<typename std::iterator_traits<I_>::iterator_category,
- std::random_access_iterator_tag>::value>::advance(cur, end, partition_size);
- }
- }
-
- /**
- * Execute op on every item in the provided range, possibly in parallel.
- *
- * \ingroup g_threads
- * \since 0.26
- */
- template <typename I_, typename P_>
- void parallel_for_each(I_ cur, const I_ & end, const P_ & op,
-#ifdef PALUDIS_ENABLE_THREADS
- const unsigned partition_size = FutureActionQueue::get_instance()->number_of_threads()
-#else
- const unsigned = 0
-#endif
- )
- {
-#ifdef PALUDIS_ENABLE_THREADS
- Sequence<tr1::shared_ptr<Future<void> > > futures;
- for (unsigned x(0) ; x < partition_size ; ++x, ++cur)
- {
- if (cur == end)
- break;
-
- futures.push_back(make_shared_ptr(new Future<void>(
- tr1::bind(parallel_for_each_worker<I_, P_>, I_(cur), tr1::cref(end), partition_size, tr1::cref(op)))));
- }
-#else
- std::for_each(cur, end, op);
-#endif
- }
-}
-
-#endif
diff --git a/paludis/util/parallel_for_each_TEST.cc b/paludis/util/parallel_for_each_TEST.cc
deleted file mode 100644
index adf8bdb..0000000
--- a/paludis/util/parallel_for_each_TEST.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Ciaran McCreesh
- *
- * 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 <paludis/util/join.hh>
-#include <paludis/util/parallel_for_each.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
-#include <vector>
-
-using namespace paludis;
-using namespace test;
-
-namespace
-{
- int factorial(const int i)
- {
- if (i < 2)
- return 1;
- else
- return i * factorial(i - 1);
- }
-
- void factorialify(int & i)
- {
- i = factorial(i);
- }
-}
-
-namespace test_cases
-{
- struct ParallelForEachTest : TestCase
- {
- ParallelForEachTest() : TestCase("parallel_for_each") { }
-
- void run()
- {
- std::vector<int> v;
- v.push_back(2);
- v.push_back(4);
- v.push_back(6);
-
- parallel_for_each(v.begin(), v.end(), &factorialify);
-
- TEST_CHECK_EQUAL(join(v.begin(), v.end(), " "), "2 24 720");
- }
- } test_parallel_for_each;
-}
-
diff --git a/src/clients/inquisitio/do_search.cc b/src/clients/inquisitio/do_search.cc
index 1c961ff..d7276e7 100644
--- a/src/clients/inquisitio/do_search.cc
+++ b/src/clients/inquisitio/do_search.cc
@@ -34,7 +34,6 @@
#include <paludis/util/sequence.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/tr1_functional.hh>
-#include <paludis/util/parallel_for_each.hh>
#include <paludis/util/create_iterator-impl.hh>
#include <list>
#include <set>
@@ -272,7 +271,7 @@ do_search(const Environment & env)
extractors
);
- parallel_for_each(ids.begin(), ids.end(), tr1::bind(&set_id, tr1::cref(env), tr1::cref(repos), _1, eligible, matches));
+ std::for_each(ids.begin(), ids.end(), tr1::bind(&set_id, tr1::cref(env), tr1::cref(repos), _1, eligible, matches));
bool any(false);
InquisitioQueryTask task(&env);
diff --git a/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc b/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc
index 3ea1aab..3fad117 100644
--- a/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc
+++ b/src/clients/reconcilio/broken_linkage_finder/broken_linkage_finder.cc
@@ -29,7 +29,6 @@
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/log.hh>
#include <paludis/util/mutex.hh>
-#include <paludis/util/parallel_for_each.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/set-impl.hh>
#include <paludis/util/tr1_functional.hh>
@@ -156,7 +155,7 @@ BrokenLinkageFinder::BrokenLinkageFinder(const Environment * env, const std::str
std::inserter(_imp->extra_lib_dirs, _imp->extra_lib_dirs.begin()),
tr1::bind(realpath_with_current_and_root, _1, FSEntry("/"), env->root()));
- parallel_for_each(search_dirs_pruned.begin(), search_dirs_pruned.end(),
+ std::for_each(search_dirs_pruned.begin(), search_dirs_pruned.end(),
tr1::bind(&Implementation<BrokenLinkageFinder>::search_directory, _imp.get(), _1));
for (Configuration::DirsIterator it(_imp->extra_lib_dirs.begin()),
@@ -221,7 +220,7 @@ Implementation<BrokenLinkageFinder>::walk_directory(const FSEntry & directory)
try
{
- parallel_for_each(DirIterator(directory, false), DirIterator(),
+ std::for_each(DirIterator(directory, false), DirIterator(),
tr1::bind(&Implementation<BrokenLinkageFinder>::check_file, this, _1));
}
catch (const FSError & ex)
@@ -278,7 +277,7 @@ Implementation<BrokenLinkageFinder>::add_breakage(const FSEntry & file, const st
tr1::shared_ptr<const PackageIDSequence> pkgs(
db->query(query::InstalledAtRoot(env->root()), qo_whatever));
- parallel_for_each(pkgs->begin(), pkgs->end(),
+ std::for_each(pkgs->begin(), pkgs->end(),
tr1::bind(&Implementation<BrokenLinkageFinder>::gather_package, this, _1));
}