Skip to content

Commit

Permalink
Updated after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-slac committed Feb 26, 2016
1 parent ca4a6bb commit ebbeda7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
27 changes: 15 additions & 12 deletions python/lsst/log/logLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ Access to the classes from the log library
#include "lsst/log/logInterface.h"
%}

namespace std {
template <class Func>
class function {
};
}

%template(VoidFunc) std::function<void()>;

%{
// warpper for callable object to track lifetime
// Wrapper for Python callable object to make sure that we have GIL
// when we call Python. Note that we are leaking Python callable,
// as C++ callables may be (and actually are in our particular case)
// outliving Python interpreter and attempt to delete Python object
// will result in crash.
class callable_wrapper {
public:
callable_wrapper(PyObject* callable) : _callable(callable) {}
void operator()() { PyObject_CallObject(_callable, nullptr); }
callable_wrapper(PyObject* callable) : _callable(callable) {
Py_XINCREF(_callable);
}
void operator()() {
// make sure we own GIL before doing Python call
auto state = PyGILState_Ensure();
PyObject_CallObject(_callable, nullptr);
PyGILState_Release(state);
}
private:
swig::SwigPtr_PyObject _callable;
PyObject* _callable;
};
%}

Expand Down
17 changes: 9 additions & 8 deletions src/Log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ int Log::MDCRegisterInit(std::function<void()> function) {

std::lock_guard<std::mutex> lock(mdcInitMutex);

// store function for later use
::mdcInitFunctions.push_back(function);

// logMsg may have been called already in this thread, to make sure that
// this function is executed in this thread call it explicitly
function();

// store function for later use
::mdcInitFunctions.push_back(std::move(function));

// return arbitrary number
return 1;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ bool Log::isEnabledFor(std::string const& loggername, int level) {
*/
void Log::log(log4cxx::LoggerPtr logger, ///< the logger
log4cxx::LevelPtr level, ///< message level
log4cxx::spi::LocationInfo const& location,
log4cxx::spi::LocationInfo const& location, ///< message origin location
char const* fmt, ///< message format string
... ///< message arguments
) {
Expand All @@ -372,10 +372,11 @@ void Log::log(log4cxx::LoggerPtr logger, ///< the logger

/** Method used by LOGS_INFO and similar macros to process a log message..
*/
void Log::logMsg(log4cxx::LoggerPtr logger,
log4cxx::LevelPtr level,
log4cxx::spi::LocationInfo const& location,
std::string const& msg) {
void Log::logMsg(log4cxx::LoggerPtr logger, ///< the logger
log4cxx::LevelPtr level, ///< message level
log4cxx::spi::LocationInfo const& location, ///< message origin location
std::string const& msg ///< message string
) {

// do one-time per-thread initialization
thread_local static bool threadInit = false;
Expand Down

0 comments on commit ebbeda7

Please sign in to comment.