aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 18:59:16 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 18:59:16 +0100
commitdcb89a887b28a6d83dc4fd9d7790ff7cb562278b (patch)
treee5c77ac0bbe56282c73fd7b063a3c6fc786fae1a
parent5c74698d6925da426632d0497a5751b9003d8ba0 (diff)
downloadpaludis-dcb89a887b28a6d83dc4fd9d7790ff7cb562278b.tar.gz
paludis-dcb89a887b28a6d83dc4fd9d7790ff7cb562278b.tar.xz
Mutex rather than active object for Log
-rw-r--r--paludis/util/log.cc38
-rw-r--r--paludis/util/log.hh5
-rw-r--r--paludis/util/log_TEST.cc7
3 files changed, 16 insertions, 34 deletions
diff --git a/paludis/util/log.cc b/paludis/util/log.cc
index 5e2c1cd..1df5342 100644
--- a/paludis/util/log.cc
+++ b/paludis/util/log.cc
@@ -23,7 +23,7 @@
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/singleton-impl.hh>
#include <paludis/util/exception.hh>
-#include <paludis/util/action_queue.hh>
+#include <paludis/util/mutex.hh>
#include "config.h"
#ifdef __linux__
@@ -44,18 +44,16 @@ namespace paludis
template<>
struct Imp<Log>
{
+ Mutex mutex;
LogLevel log_level;
std::ostream * stream;
std::string program_name;
std::string previous_context;
- mutable ActionQueue action_queue;
-
Imp() :
log_level(ll_qa),
stream(&std::cerr),
- program_name("paludis"),
- action_queue(1, false, false)
+ program_name("paludis")
{
}
@@ -138,31 +136,31 @@ Log::~Log()
void
Log::set_log_level(const LogLevel l)
{
- _imp->action_queue.enqueue(std::bind(std::mem_fn(&Imp<Log>::set_log_level), _imp.get(), l));
+ Lock lock(_imp->mutex);
+ _imp->log_level = l;
}
LogLevel
Log::log_level() const
{
- LogLevel result(static_cast<LogLevel>(1337));
- _imp->action_queue.enqueue(std::bind(std::mem_fn(&Imp<Log>::get_log_level), _imp.get(), std::ref(result)));
- _imp->action_queue.complete_pending();
- return result;
+ return _imp->log_level;
}
void
Log::_message(const std::string & id, const LogLevel l, const LogContext c, const std::string & s)
{
+ Lock lock(_imp->mutex);
+
if (lc_context == c)
- _imp->action_queue.enqueue(std::bind(std::mem_fn(&Imp<Log>::message), _imp.get(), id, l, c,
+ _imp->message(id, l, c,
#ifdef __linux__
- "In thread ID '" + stringify(syscall(SYS_gettid)) + "':\n ... " +
+ "In thread ID '" + stringify(syscall(SYS_gettid)) + "':\n ... " +
#else
# warning "Don't know how to get a thread ID on your platform"
#endif
- Context::backtrace("\n ... "), s));
+ Context::backtrace("\n ... "), s);
else
- _imp->action_queue.enqueue(std::bind(std::mem_fn(&Imp<Log>::message), _imp.get(), id, l, c, "", s));
+ _imp->message(id, l, c, "", s);
}
LogMessageHandler::LogMessageHandler(const LogMessageHandler & o) :
@@ -182,19 +180,15 @@ Log::message(const std::string & id, const LogLevel l, const LogContext c)
void
Log::set_log_stream(std::ostream * const s)
{
- _imp->action_queue.enqueue(std::bind(std::mem_fn(&Imp<Log>::set_log_stream), _imp.get(), s));
-}
-
-void
-Log::complete_pending() const
-{
- _imp->action_queue.complete_pending();
+ Lock lock(_imp->mutex);
+ _imp->stream = s;
}
void
Log::set_program_name(const std::string & s)
{
- _imp->action_queue.enqueue(std::bind(std::mem_fn(&Imp<Log>::set_program_name), _imp.get(), s));
+ Lock lock(_imp->mutex);
+ _imp->program_name = s;
}
LogMessageHandler::LogMessageHandler(Log * const ll, const std::string & id, const LogLevel l, const LogContext c) :
diff --git a/paludis/util/log.hh b/paludis/util/log.hh
index cddd70a..a2b93d6 100644
--- a/paludis/util/log.hh
+++ b/paludis/util/log.hh
@@ -97,11 +97,6 @@ namespace paludis
* Set our program name.
*/
void set_program_name(const std::string &);
-
- /**
- * Finish any pending writes.
- */
- void complete_pending() const;
};
/**
diff --git a/paludis/util/log_TEST.cc b/paludis/util/log_TEST.cc
index f609186..3e2ac6c 100644
--- a/paludis/util/log_TEST.cc
+++ b/paludis/util/log_TEST.cc
@@ -65,7 +65,6 @@ TEST(Log, Messages)
EXPECT_TRUE(s.str().empty());
Log::get_instance()->message("test.log", ll_debug, lc_no_context) << "one";
- Log::get_instance()->complete_pending();
EXPECT_TRUE(! s.str().empty());
EXPECT_TRUE(std::string::npos != s.str().find("one"));
@@ -75,10 +74,8 @@ TEST(Log, Messages)
Log::get_instance()->set_log_level(ll_warning);
Log::get_instance()->message("test.log", ll_debug, lc_no_context) << "two";
- Log::get_instance()->complete_pending();
EXPECT_TRUE(t.str().empty());
Log::get_instance()->message("test.log", ll_warning, lc_no_context) << "three" << "." << 14;
- Log::get_instance()->complete_pending();
EXPECT_TRUE(! t.str().empty());
EXPECT_TRUE(std::string::npos == t.str().find("one"));
EXPECT_TRUE(std::string::npos == t.str().find("two"));
@@ -95,19 +92,15 @@ TEST(Log, Exceptions)
EXPECT_TRUE(s.str().empty());
EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context) << throws_a_monkey(), Monkey);
- Log::get_instance()->complete_pending();
EXPECT_TRUE(s.str().empty());
EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context)
<< "one" << throws_a_monkey() << "two", Monkey);
- Log::get_instance()->complete_pending();
EXPECT_TRUE(s.str().empty());
EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context) << throws_a_monkey_when_stringified(), Monkey);
- Log::get_instance()->complete_pending();
EXPECT_TRUE(s.str().empty());
EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context)
<< "one" << throws_a_monkey_when_stringified() << "two", Monkey);
- Log::get_instance()->complete_pending();
EXPECT_TRUE(s.str().empty());
}