aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-03 12:00:29 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-03 12:00:29 +0000
commit6aa4c54709797a52c468059e2e5120126a9b3042 (patch)
tree5727dc5d6161ec2ad637d23d7cd47d3450e2694e
parent5b096137be44c5354713cfc02b30767c7b9da0f6 (diff)
downloadpaludis-6aa4c54709797a52c468059e2e5120126a9b3042.tar.gz
paludis-6aa4c54709797a52c468059e2e5120126a9b3042.tar.xz
Fix qualudis deadlock
-rw-r--r--paludis/repositories/e/qa/qa_controller.cc28
1 files changed, 18 insertions, 10 deletions
diff --git a/paludis/repositories/e/qa/qa_controller.cc b/paludis/repositories/e/qa/qa_controller.cc
index 95367e0..a4203c1 100644
--- a/paludis/repositories/e/qa/qa_controller.cc
+++ b/paludis/repositories/e/qa/qa_controller.cc
@@ -44,7 +44,7 @@ namespace
QAReporter
{
QAReporter & base;
- Mutex mutex;
+ Mutex mutex, flush_mutex;
std::multimap<const FSEntry, const QAMessage> message_buf;
typedef std::multimap<const FSEntry, const QAMessage>::iterator MessageIterator;
@@ -67,18 +67,26 @@ namespace
void flush(const FSEntry & f)
{
- Lock lock(mutex);
-
- std::string root(stringify(f));
+ std::list<QAMessage> to_flush;
- for (MessageIterator i(message_buf.lower_bound(f)), i_end(message_buf.end()) ; i != i_end ; )
{
- if (0 != stringify(i->first).compare(0, root.length(), root))
- break;
-
- base.message(i->second);
- message_buf.erase(i++);
+ Lock lock(mutex);
+ std::string root(stringify(f));
+
+ for (MessageIterator i(message_buf.lower_bound(f)), i_end(message_buf.end()) ; i != i_end ; )
+ {
+ if (0 != stringify(i->first).compare(0, root.length(), root))
+ break;
+
+ /* don't call base.message whilst we hold the map lock. It'll deadlock. */
+ to_flush.push_back(i->second);
+ message_buf.erase(i++);
+ }
}
+
+ using namespace tr1::placeholders;
+ Lock lock(flush_mutex);
+ std::for_each(to_flush.begin(), to_flush.end(), tr1::bind(&QAReporter::message, &base, _1));
}
void message(const QAMessage & msg)