Bug 809950 - fix mtransport logging macros to not introduce static initializers; r=jesup
authorNathan Froyd <froydnj@mozilla.com>
Thu, 08 Nov 2012 13:44:41 -0500
changeset 112775 5905e2a217b9ee8a8cb0feead3d19fc31361d7a6
parent 112774 3347658971cdec8587b3b5a4ab0594201ddffa1a
child 112776 244ced46ac1132d55bce9a0dd37e244059df7ad6
push id23838
push usereakhgari@mozilla.com
push dateFri, 09 Nov 2012 15:21:51 +0000
treeherdermozilla-central@c39596b46863 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs809950
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 809950 - fix mtransport logging macros to not introduce static initializers; r=jesup
media/mtransport/logging.h
--- a/media/mtransport/logging.h
+++ b/media/mtransport/logging.h
@@ -7,36 +7,24 @@
 // Original author: ekr@rtfm.com
 
 #ifndef logging_h__
 #define logging_h__
 
 #include <sstream>
 
 #include <prlog.h>
-#include "mozilla/Scoped.h"
-
-namespace mozilla {
-
-class LogCtx {
- public:
-  LogCtx(const char* name) : module_(PR_NewLogModule(name)) {}
-  LogCtx(std::string& name) : module_(PR_NewLogModule(name.c_str())) {}
-
-  PRLogModuleInfo* module() const { return module_; }
-
-private:
-  PRLogModuleInfo* module_;
-};
-
 
 #define MOZ_MTLOG_MODULE(n) \
-  static ScopedDeletePtr<LogCtx> mlog_ctx;      \
-  static const char *mlog_name = n
+  static PRLogModuleInfo* getLogModule() {      \
+    static PRLogModuleInfo* log;                \
+    if (!log)                                   \
+      log = PR_NewLogModule(n);                 \
+    return log;                                 \
+  }
 
 #define MOZ_MTLOG(level, b) \
-  do { if (!mlog_ctx) mlog_ctx = new LogCtx(mlog_name);    \
-    if (mlog_ctx) {                                             \
+  do {                                                             \
     std::stringstream str;                                              \
     str << b;                                                           \
-    PR_LOG(mlog_ctx->module(), level, ("%s", str.str().c_str())); }} while(0)
-}  // close namespace
+    PR_LOG(getLogModule(), level, ("%s", str.str().c_str())); } while(0)
+
 #endif