Title: [232827] trunk/Source/ThirdParty/libwebrtc
Revision
232827
Author
you...@apple.com
Date
2018-06-13 21:14:50 -0700 (Wed, 13 Jun 2018)

Log Message

Eliminate static initializers in libwebrtc.dylib
https://bugs.webkit.org/show_bug.cgi?id=186570

Reviewed by Darin Adler.

* Source/webrtc/rtc_base/flags.h: Changed macro to create the static into a function.
* Source/webrtc/rtc_base/logging.cc: Ditto.
Made sure that the scope is created on instantiation of the first Log instance that might use it.
* Source/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm:
* Source/webrtc/system_wrappers/source/runtime_enabled_features_default.cc:

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/libwebrtc/ChangeLog (232826 => 232827)


--- trunk/Source/ThirdParty/libwebrtc/ChangeLog	2018-06-14 02:51:50 UTC (rev 232826)
+++ trunk/Source/ThirdParty/libwebrtc/ChangeLog	2018-06-14 04:14:50 UTC (rev 232827)
@@ -1,3 +1,16 @@
+2018-06-13  Youenn Fablet  <you...@apple.com>
+
+        Eliminate static initializers in libwebrtc.dylib
+        https://bugs.webkit.org/show_bug.cgi?id=186570
+
+        Reviewed by Darin Adler.
+
+        * Source/webrtc/rtc_base/flags.h: Changed macro to create the static into a function.
+        * Source/webrtc/rtc_base/logging.cc: Ditto.
+        Made sure that the scope is created on instantiation of the first Log instance that might use it.
+        * Source/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm:
+        * Source/webrtc/system_wrappers/source/runtime_enabled_features_default.cc:
+
 2018-06-09  Dan Bernstein  <m...@apple.com>
 
         [Xcode] Clean up and modernize some build setting definitions

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/flags.h (232826 => 232827)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/flags.h	2018-06-14 02:51:50 UTC (rev 232826)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/flags.h	2018-06-14 04:14:50 UTC (rev 232827)
@@ -151,19 +151,25 @@
 
 
 // Internal use only.
-#define DEFINE_FLAG(type, c_type, name, default, comment) \
-  /* define and initialize the flag */                    \
-  c_type FLAG_##name = (default);                         \
-  /* register the flag */                                 \
-  static rtc::Flag Flag_##name(__FILE__, #name, (comment),      \
-                               rtc::Flag::type, &FLAG_##name,   \
-                               rtc::FlagValue::New_##type(default))
 
+#define DEFINE_FLAG(type, c_type, name, default, comment)    \
+  static std::pair<std::reference_wrapper<c_type>, std::reference_wrapper<rtc::Flag>> name() { \
+    /* define and initialize the flag */                     \
+    c_type FLAG_##name = (default);                          \
+    /* register the flag */                                  \
+    static rtc::Flag Flag_##name(__FILE__, #name, (comment), \
+      rtc::Flag::type, &FLAG_##name,                         \
+      rtc::FlagValue::New_##type(default));                  \
+    return std::make_pair<std::reference_wrapper<c_type>, std::reference_wrapper<rtc::Flag>>(FLAG_##name, Flag_##name); \
+  }                       \
+  c_type& FLAG_##name() { \
+    return name().first;  \
+  }
 
 // Internal use only.
 #define DECLARE_FLAG(c_type, name)              \
-  /* declare the external flag */               \
-  extern c_type FLAG_##name
+  /* declare the flag getter */                 \
+  c_type& FLAG_##name();
 
 
 // Use the following macros to define a new flag:

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/logging.cc (232826 => 232827)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/logging.cc	2018-06-14 02:51:50 UTC (rev 232826)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/logging.cc	2018-06-14 04:14:50 UTC (rev 232827)
@@ -36,8 +36,10 @@
 
 #include <algorithm>
 #include <iomanip>
+#include <mutex>
 #include <ostream>
 #include <vector>
+#include <type_traits>
 
 #include "rtc_base/criticalsection.h"
 #include "rtc_base/logging.h"
@@ -103,8 +105,14 @@
 bool LogMessage::log_to_stderr_ = true;
 
 namespace {
+
 // Global lock for log subsystem, only needed to serialize access to streams_.
-CriticalSection g_log_crit;
+CriticalSection& logCriticalScope() {
+  static std::aligned_storage<sizeof(CriticalSection), std::alignment_of<CriticalSection>::value>::type g_log_crit_storage;
+  static CriticalSection* g_log_crit = new (&g_log_crit_storage) CriticalSection;
+  return *g_log_crit;
+}
+
 }  // namespace
 
 // The list of logging streams currently configured.
@@ -111,7 +119,7 @@
 // Note: we explicitly do not clean this up, because of the uncertain ordering
 // of destructors at program exit.  Let the person who sets the stream trigger
 // cleanup by setting to null, or let it leak (safe at program exit).
-LogMessage::StreamList LogMessage::streams_ RTC_GUARDED_BY(g_log_crit);
+LogMessage::StreamList LogMessage::streams_ RTC_GUARDED_BY(logCriticalScope());
 
 // Boolean options default to false (0)
 bool LogMessage::thread_, LogMessage::timestamp_;
@@ -123,6 +131,10 @@
                        int err,
                        const char* module)
     : severity_(sev), tag_(kLibjingle) {
+
+  static std::once_flag callLogCriticalScopeOnce;
+  std::call_once(callLogCriticalScopeOnce,[] { logCriticalScope(); });
+
   if (timestamp_) {
     // Use SystemTimeMillis so that even if tests use fake clocks, the timestamp
     // in log messages represents the real system time.
@@ -207,7 +219,7 @@
     OutputToDebug(str, severity_, tag_);
   }
 
-  CritScope cs(&g_log_crit);
+  CritScope cs(&logCriticalScope());
   for (auto& kv : streams_) {
     if (severity_ >= kv.second) {
       kv.first->OnLogMessage(str);
@@ -235,7 +247,7 @@
 
 void LogMessage::LogToDebug(LoggingSeverity min_sev) {
   dbg_sev_ = min_sev;
-  CritScope cs(&g_log_crit);
+  CritScope cs(&logCriticalScope());
   UpdateMinLogSeverity();
 }
 
@@ -244,7 +256,7 @@
 }
 
 int LogMessage::GetLogToStream(LogSink* stream) {
-  CritScope cs(&g_log_crit);
+  CritScope cs(&logCriticalScope());
   LoggingSeverity sev = LS_NONE;
   for (auto& kv : streams_) {
     if (!stream || stream == kv.first) {
@@ -255,13 +267,13 @@
 }
 
 void LogMessage::AddLogToStream(LogSink* stream, LoggingSeverity min_sev) {
-  CritScope cs(&g_log_crit);
+  CritScope cs(&logCriticalScope());
   streams_.push_back(std::make_pair(stream, min_sev));
   UpdateMinLogSeverity();
 }
 
 void LogMessage::RemoveLogToStream(LogSink* stream) {
-  CritScope cs(&g_log_crit);
+  CritScope cs(&logCriticalScope());
   for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) {
     if (stream == it->first) {
       streams_.erase(it);
@@ -334,7 +346,7 @@
 }
 
 void LogMessage::UpdateMinLogSeverity()
-    RTC_EXCLUSIVE_LOCKS_REQUIRED(g_log_crit) {
+    RTC_EXCLUSIVE_LOCKS_REQUIRED(logCriticalScope()) {
   LoggingSeverity min_sev = dbg_sev_;
   for (auto& kv : streams_) {
     min_sev = std::min(dbg_sev_, kv.second);

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm (232826 => 232827)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm	2018-06-14 02:51:50 UTC (rev 232826)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodec.mm	2018-06-14 04:14:50 UTC (rev 232827)
@@ -16,9 +16,9 @@
 
 #include "media/base/mediaconstants.h"
 
-NSString *const kRTCVideoCodecVp8Name = @(cricket::kVp8CodecName);
-NSString *const kRTCVideoCodecVp9Name = @(cricket::kVp9CodecName);
-NSString *const kRTCVideoCodecH264Name = @(cricket::kH264CodecName);
+NSString *const kRTCVideoCodecVp8Name = @"VP8";
+NSString *const kRTCVideoCodecVp9Name = @"VP9";
+NSString *const kRTCVideoCodecH264Name = @"H264";
 NSString *const kRTCLevel31ConstrainedHigh = @"640c1f";
 NSString *const kRTCLevel31ConstrainedBaseline = @"42e01f";
 

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/system_wrappers/source/runtime_enabled_features_default.cc (232826 => 232827)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/system_wrappers/source/runtime_enabled_features_default.cc	2018-06-14 02:51:50 UTC (rev 232826)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/system_wrappers/source/runtime_enabled_features_default.cc	2018-06-14 04:14:50 UTC (rev 232827)
@@ -12,6 +12,9 @@
 
 #include "rtc_base/flags.h"
 
+#include <functional>
+#include <utility>
+
 namespace flags {
 DEFINE_bool(enable_dual_stream_mode,
             false,
@@ -23,7 +26,7 @@
 
 bool IsFeatureEnabled(std::string feature_name) {
   if (feature_name == kDualStreamModeFeatureName)
-    return flags::FLAG_enable_dual_stream_mode;
+    return flags::FLAG_enable_dual_stream_mode();
   return false;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to