aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-01-06 21:08:16 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-01-08 16:34:27 +0000
commit67d0b6ec6a6f936c79e717190a74f590bce185da (patch)
treed8108e4e7675dad548a3f0a2f4a1f057d732538e
parentefa3668957f10f9e4a12dad8a203abd9bb58e85c (diff)
downloadpaludis-67d0b6ec6a6f936c79e717190a74f590bce185da.tar.gz
paludis-67d0b6ec6a6f936c79e717190a74f590bce185da.tar.xz
IPCInputManager::underlying_output_manager_if_constructed
-rw-r--r--paludis/ipc_output_manager.cc21
-rw-r--r--paludis/ipc_output_manager.hh14
2 files changed, 31 insertions, 4 deletions
diff --git a/paludis/ipc_output_manager.cc b/paludis/ipc_output_manager.cc
index db874e6..939b979 100644
--- a/paludis/ipc_output_manager.cc
+++ b/paludis/ipc_output_manager.cc
@@ -35,6 +35,7 @@
#include <paludis/util/join.hh>
#include <paludis/util/thread.hh>
#include <paludis/util/pipe.hh>
+#include <paludis/util/mutex.hh>
#include <paludis/standard_output_manager.hh>
#include <paludis/create_output_manager_info.hh>
#include <paludis/serialise.hh>
@@ -181,6 +182,7 @@ namespace paludis
const Environment * const env;
const OutputExclusivity exclusivity;
+ mutable Mutex mutex;
std::tr1::shared_ptr<OutputManager> output_manager;
std::tr1::shared_ptr<Thread> copy_thread;
@@ -240,14 +242,18 @@ IPCInputManager::_pipe_command_handler(const std::string & s)
if (tokens.size() != 3 || tokens[1] != "1")
return "Ebad CREATE subcommand";
- if (_imp->output_manager)
- return "Ealready constructed";
-
Deserialiser deserialiser(_imp->env, tokens[2]);
Deserialisation deserialisation("CreateOutputManagerInfo", deserialiser);
const std::tr1::shared_ptr<CreateOutputManagerInfo> i(CreateOutputManagerInfo::deserialise(deserialisation));
- _imp->output_manager = _imp->env->create_output_manager(*i);
+ {
+ Lock lock(_imp->mutex);
+ if (_imp->output_manager)
+ return "Ealready constructed";
+
+ _imp->output_manager = _imp->env->create_output_manager(*i);
+ }
+
_imp->copy_thread.reset(new Thread(std::tr1::bind(&IPCInputManager::_copy_thread, this)));
return "O 1 " + stringify(_imp->stdout_pipe.write_fd()) + " " + stringify(_imp->stderr_pipe.write_fd());
@@ -348,6 +354,13 @@ IPCInputManager::_copy_thread()
}
}
+const std::tr1::shared_ptr<OutputManager>
+IPCInputManager::underlying_output_manager_if_constructed() const
+{
+ Lock lock(_imp->mutex);
+ return _imp->output_manager;
+}
+
namespace paludis
{
template <>
diff --git a/paludis/ipc_output_manager.hh b/paludis/ipc_output_manager.hh
index 24fde29..255b362 100644
--- a/paludis/ipc_output_manager.hh
+++ b/paludis/ipc_output_manager.hh
@@ -71,6 +71,20 @@ namespace paludis
const std::tr1::function<std::string (const std::string &)> pipe_command_handler()
PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ /**
+ * The underlying output manager.
+ *
+ * The underlying output manager is not constructed until the child
+ * process requests it, so a null pointer may be returned.
+ *
+ * Normally the output manager is destroyed when the
+ * IPCInputManager is destroyed, but keeping the shared pointer
+ * this method returns around for longer will also work, if, for
+ * example, any 'finished' messages are to be displayed later on.
+ */
+ const std::tr1::shared_ptr<OutputManager> underlying_output_manager_if_constructed() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE OutputManagerFromIPC :