aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-13 00:18:30 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-07-13 00:18:30 +0000
commit131d5c3498ebd5d4838c0e091a76cdad47d8bb66 (patch)
tree5cf5d3ecd6d5c9c1ec5aca2a2221ac0d64189c9e
parent12efa1daab03424c213845607285594e5c475bbe (diff)
downloadpaludis-131d5c3498ebd5d4838c0e091a76cdad47d8bb66.tar.gz
paludis-131d5c3498ebd5d4838c0e091a76cdad47d8bb66.tar.xz
More idle actions
-rw-r--r--paludis/repositories/e/e_key.cc113
-rw-r--r--paludis/repositories/e/ebuild_id.cc44
-rw-r--r--paludis/repositories/e/ebuild_id.hh2
-rw-r--r--paludis/util/idle_action_pool.cc28
-rw-r--r--paludis/util/idle_action_pool.hh3
5 files changed, 138 insertions, 52 deletions
diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc
index 923c55a..8309517 100644
--- a/paludis/repositories/e/e_key.cc
+++ b/paludis/repositories/e/e_key.cc
@@ -28,6 +28,8 @@
#include <paludis/util/log.hh>
#include <paludis/util/mutex.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/tr1_functional.hh>
+#include <paludis/util/idle_action_pool.hh>
#include <paludis/portage_dep_parser.hh>
#include <paludis/eapi.hh>
@@ -69,6 +71,7 @@ namespace paludis
const std::string string_value;
mutable Mutex value_mutex;
mutable tr1::shared_ptr<const DependencySpecTree::ConstItem> value;
+ mutable tr1::function<void () throw ()> value_used;
Implementation(const tr1::shared_ptr<const PackageID> & i, const std::string & v) :
id(i),
@@ -95,7 +98,16 @@ EDependenciesKey::value() const
{
Lock l(_imp->value_mutex);
if (_imp->value)
+ {
+ if (_imp->value_used)
+ {
+ _imp->value_used();
+ _imp->value_used = tr1::function<void () throw ()>();
+ }
return _imp->value;
+ }
+
+ IdleActionPool::get_instance()->increase_unprepared_stat();
Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "':");
_imp->value = PortageDepParser::parse_depend(_imp->string_value, *_imp->id->eapi());
@@ -108,9 +120,18 @@ EDependenciesKey::idle_load() const
TryLock l(_imp->value_mutex);
if (l() && ! _imp->value)
{
- Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
- _imp->value = PortageDepParser::parse_depend(_imp->string_value, *_imp->id->eapi());
- return iar_success;
+ try
+ {
+ Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
+ _imp->value = PortageDepParser::parse_depend(_imp->string_value, *_imp->id->eapi());
+ _imp->value_used = tr1::bind(tr1::mem_fn(&IdleActionPool::increase_used_stat), IdleActionPool::get_instance());
+ return iar_success;
+ }
+ catch (...)
+ {
+ // the exception will be repeated in the relevant thread
+ return iar_failure;
+ }
}
return iar_already_completed;
@@ -125,6 +146,7 @@ namespace paludis
const std::string string_value;
mutable Mutex value_mutex;
mutable tr1::shared_ptr<const LicenseSpecTree::ConstItem> value;
+ mutable tr1::function<void () throw ()> value_used;
Implementation(const tr1::shared_ptr<const PackageID> & i, const std::string & v) :
id(i),
@@ -151,7 +173,16 @@ ELicenseKey::value() const
{
Lock l(_imp->value_mutex);
if (_imp->value)
+ {
+ if (_imp->value_used)
+ {
+ _imp->value_used();
+ _imp->value_used = tr1::function<void () throw ()>();
+ }
return _imp->value;
+ }
+
+ IdleActionPool::get_instance()->increase_unprepared_stat();
Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "':");
_imp->value = PortageDepParser::parse_license(_imp->string_value, *_imp->id->eapi());
@@ -164,9 +195,18 @@ ELicenseKey::idle_load() const
TryLock l(_imp->value_mutex);
if (l() && ! _imp->value)
{
- Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
- _imp->value = PortageDepParser::parse_license(_imp->string_value, *_imp->id->eapi());
- return iar_success;
+ try
+ {
+ Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
+ _imp->value = PortageDepParser::parse_license(_imp->string_value, *_imp->id->eapi());
+ _imp->value_used = tr1::bind(tr1::mem_fn(&IdleActionPool::increase_used_stat), IdleActionPool::get_instance());
+ return iar_success;
+ }
+ catch (...)
+ {
+ // the exception will be repeated in the relevant thread
+ return iar_failure;
+ }
}
return iar_already_completed;
@@ -301,6 +341,7 @@ namespace paludis
const std::string string_value;
mutable Mutex value_mutex;
mutable tr1::shared_ptr<IUseFlagSet> value;
+ mutable tr1::function<void () throw ()> value_used;
Implementation(const tr1::shared_ptr<const PackageID> & i, const std::string & v) :
id(i),
@@ -327,7 +368,16 @@ EIUseKey::value() const
{
Lock l(_imp->value_mutex);
if (_imp->value)
+ {
+ if (_imp->value_used)
+ {
+ _imp->value_used();
+ _imp->value_used = tr1::function<void () throw ()>();
+ }
return _imp->value;
+ }
+
+ IdleActionPool::get_instance()->increase_unprepared_stat();
Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "':");
_imp->value.reset(new IUseFlagSet);
@@ -346,13 +396,22 @@ EIUseKey::idle_load() const
TryLock l(_imp->value_mutex);
if (l() && ! _imp->value)
{
- Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
- _imp->value.reset(new IUseFlagSet);
- std::list<std::string> tokens;
- WhitespaceTokeniser::get_instance()->tokenise(_imp->string_value, std::back_inserter(tokens));
- for (std::list<std::string>::const_iterator t(tokens.begin()), t_end(tokens.end()) ;
- t != t_end ; ++t)
- _imp->value->insert(IUseFlag(*t, _imp->id->eapi()->supported->iuse_flag_parse_mode));
+ try
+ {
+ _imp->value.reset(new IUseFlagSet);
+ std::list<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(_imp->string_value, std::back_inserter(tokens));
+ for (std::list<std::string>::const_iterator t(tokens.begin()), t_end(tokens.end()) ;
+ t != t_end ; ++t)
+ _imp->value->insert(IUseFlag(*t, _imp->id->eapi()->supported->iuse_flag_parse_mode));
+ _imp->value_used = tr1::bind(tr1::mem_fn(&IdleActionPool::increase_used_stat), IdleActionPool::get_instance());
+ }
+ catch (...)
+ {
+ // the exception will be repeated in the relevant thread
+ _imp->value.reset();
+ return iar_failure;
+ }
return iar_success;
}
@@ -369,6 +428,7 @@ namespace paludis
const std::string string_value;
mutable Mutex value_mutex;
mutable tr1::shared_ptr<KeywordNameSet> value;
+ mutable tr1::function<void () throw ()> value_used;
Implementation(const tr1::shared_ptr<const PackageID> & i, const std::string & v) :
id(i),
@@ -395,7 +455,16 @@ EKeywordsKey::value() const
{
Lock l(_imp->value_mutex);
if (_imp->value)
+ {
+ if (_imp->value_used)
+ {
+ _imp->value_used();
+ _imp->value_used = tr1::function<void () throw ()>();
+ }
return _imp->value;
+ }
+
+ IdleActionPool::get_instance()->increase_unprepared_stat();
_imp->value.reset(new KeywordNameSet);
Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "':");
@@ -409,10 +478,20 @@ EKeywordsKey::idle_load() const
TryLock l(_imp->value_mutex);
if (l() && ! _imp->value)
{
- _imp->value.reset(new KeywordNameSet);
- Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
- WhitespaceTokeniser::get_instance()->tokenise(_imp->string_value, create_inserter<KeywordName>(_imp->value->inserter()));
- return iar_success;
+ try
+ {
+ _imp->value.reset(new KeywordNameSet);
+ Context context("When parsing metadata key '" + raw_name() + "' from '" + stringify(*_imp->id) + "' as idle action:");
+ WhitespaceTokeniser::get_instance()->tokenise(_imp->string_value, create_inserter<KeywordName>(_imp->value->inserter()));
+ _imp->value_used = tr1::bind(tr1::mem_fn(&IdleActionPool::increase_used_stat), IdleActionPool::get_instance());
+ return iar_success;
+ }
+ catch (...)
+ {
+ // the exception will be repeated in the relevant thread
+ _imp->value.reset();
+ return iar_failure;
+ }
}
return iar_already_completed;
diff --git a/paludis/repositories/e/ebuild_id.cc b/paludis/repositories/e/ebuild_id.cc
index cef5c79..74ee632 100644
--- a/paludis/repositories/e/ebuild_id.cc
+++ b/paludis/repositories/e/ebuild_id.cc
@@ -233,7 +233,20 @@ EbuildID::need_keys_added() const
}
if (_imp->eapi->supported)
- IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&EbuildID::_idle_load), this));
+ {
+ if (_imp->build_dependencies)
+ IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&EDependenciesKey::idle_load), _imp->build_dependencies));
+ if (_imp->run_dependencies)
+ IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&EDependenciesKey::idle_load), _imp->run_dependencies));
+ if (_imp->post_dependencies)
+ IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&EDependenciesKey::idle_load), _imp->post_dependencies));
+ if (_imp->keywords)
+ IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&EKeywordsKey::idle_load), _imp->keywords));
+ if (_imp->iuse)
+ IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&EIUseKey::idle_load), _imp->iuse));
+ if (_imp->license)
+ IdleActionPool::get_instance()->optional_idle_action(tr1::bind(tr1::mem_fn(&ELicenseKey::idle_load), _imp->license));
+ }
}
const std::string
@@ -562,35 +575,6 @@ EbuildID::load_inherited(const std::string & r, const std::string & h, const std
add_metadata_key(_imp->inherited);
}
-IdleActionResult
-EbuildID::_idle_load() const throw ()
-{
- IdleActionResult result(iar_success);
-
- try
- {
- if (_imp->build_dependencies)
- result = std::max(result, _imp->build_dependencies->idle_load());
- if (_imp->run_dependencies)
- result = std::max(result, _imp->run_dependencies->idle_load());
- if (_imp->post_dependencies)
- result = std::max(result, _imp->post_dependencies->idle_load());
- if (_imp->license)
- result = std::max(result, _imp->license->idle_load());
- if (_imp->keywords)
- result = std::max(result, _imp->keywords->idle_load());
- if (_imp->iuse)
- result = std::max(result, _imp->iuse->idle_load());
- }
- catch (...)
- {
- // exception will be regenerated outside of the idle task.
- result = iar_failure;
- }
-
- return result;
-}
-
namespace
{
struct SupportsActionQuery :
diff --git a/paludis/repositories/e/ebuild_id.hh b/paludis/repositories/e/ebuild_id.hh
index 3406286..cafe338 100644
--- a/paludis/repositories/e/ebuild_id.hh
+++ b/paludis/repositories/e/ebuild_id.hh
@@ -40,8 +40,6 @@ namespace paludis
private:
Implementation<EbuildID> * const _imp;
- IdleActionResult _idle_load() const throw ();
-
protected:
virtual void need_keys_added() const;
diff --git a/paludis/util/idle_action_pool.cc b/paludis/util/idle_action_pool.cc
index b1e70ce..2cfd7d5 100644
--- a/paludis/util/idle_action_pool.cc
+++ b/paludis/util/idle_action_pool.cc
@@ -41,21 +41,25 @@ namespace
struct Stats
{
Mutex mutex;
- unsigned success, failure, already_completed, enqueued;
+ unsigned success, failure, already_completed, enqueued, used, unprepared;
Stats() :
success(0),
failure(0),
already_completed(0),
- enqueued(0)
+ enqueued(0),
+ used(0),
+ unprepared(0)
{
}
~Stats()
{
+ Lock l(mutex);
Log::get_instance()->message(ll_debug, lc_no_context) << "Idle action pool stats: success "
<< success << " failure " << failure << " already completed " << already_completed
- << " forgotten " << (enqueued - success - failure - already_completed);
+ << " forgotten " << (enqueued - success - failure - already_completed) << " used " << used
+ << " unprepared " << unprepared;
}
};
#endif
@@ -151,3 +155,21 @@ IdleActionPool::_count_result(const tr1::function<IdleActionResult () throw ()>
#endif
}
+void
+IdleActionPool::increase_used_stat()
+{
+#ifdef PALUDIS_ENABLE_THREADS
+ Lock l(_imp->stats.mutex);
+ ++_imp->stats.used;
+#endif
+}
+
+void
+IdleActionPool::increase_unprepared_stat()
+{
+#ifdef PALUDIS_ENABLE_THREADS
+ Lock l(_imp->stats.mutex);
+ ++_imp->stats.unprepared;
+#endif
+}
+
diff --git a/paludis/util/idle_action_pool.hh b/paludis/util/idle_action_pool.hh
index 0a37717..70bae7a 100644
--- a/paludis/util/idle_action_pool.hh
+++ b/paludis/util/idle_action_pool.hh
@@ -42,6 +42,9 @@ namespace paludis
public:
void required_idle_action(const tr1::function<IdleActionResult () throw ()> &);
void optional_idle_action(const tr1::function<IdleActionResult () throw ()> &);
+
+ void increase_used_stat();
+ void increase_unprepared_stat();
};
}