Rebase webrtc/base with r6682 version of talk/base:
cls ported: r6671, r6672, r6679 (reverts and unreverts in r6680, r6682).
svn diff -r 6656:6682 http://webrtc.googlecode.com/svn/trunk/talk/base >
6682.diff
sed -i.bak "s/talk_base/rtc/g" 6682.diff
sed -i.bak "s/#ifdef WIN32/#if defined(WEBRTC_WIN)/g" 6682.diff
sed -i.bak "s/#if defined(WIN32)/#if defined(WEBRTC_WIN)/g" 6682.diff
patch -p0 -i 6682.diff
BUG=3379
TBR=tommi@webrtc.org,jiayl@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/14969004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@6683 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/base/logging.h b/webrtc/base/logging.h
index 91d61b3..e07045f 100644
--- a/webrtc/base/logging.h
+++ b/webrtc/base/logging.h
@@ -246,21 +246,7 @@
const void* data, size_t len, bool hex_mode,
LogMultilineState* state);
-//////////////////////////////////////////////////////////////////////
-// Macros which automatically disable logging when LOGGING == 0
-//////////////////////////////////////////////////////////////////////
-
-// If LOGGING is not explicitly defined, default to enabled in debug mode
-#if !defined(LOGGING)
-#if defined(_DEBUG) && !defined(NDEBUG)
-#define LOGGING 1
-#else
-#define LOGGING 0
-#endif
-#endif // !defined(LOGGING)
-
#ifndef LOG
-#if LOGGING
// The following non-obvious technique for implementation of a
// conditional log stream was stolen from google3/base/logging.h.
@@ -317,30 +303,6 @@
#define LOG_T(sev) LOG(sev) << this << ": "
-#else // !LOGGING
-
-// Hopefully, the compiler will optimize away some of this code.
-// Note: syntax of "1 ? (void)0 : LogMessage" was causing errors in g++,
-// converted to "while (false)"
-#define LOG(sev) \
- while (false)rtc:: LogMessage(NULL, 0, rtc::sev).stream()
-#define LOG_V(sev) \
- while (false) rtc::LogMessage(NULL, 0, sev).stream()
-#define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": "
-#define LOG_CHECK_LEVEL(sev) \
- false
-#define LOG_CHECK_LEVEL_V(sev) \
- false
-
-#define LOG_E(sev, ctx, err, ...) \
- while (false) rtc::LogMessage(__FILE__, __LINE__, rtc::sev, \
- rtc::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \
- .stream()
-
-#define LOG_T(sev) LOG(sev) << this << ": "
-#define LOG_T_F(sev) LOG(sev) << this << ": " << __FUNCTION__ <<
-#endif // !LOGGING
-
#define LOG_ERRNO_EX(sev, err) \
LOG_E(sev, ERRNO, err)
#define LOG_ERRNO(sev) \
diff --git a/webrtc/base/openssladapter.cc b/webrtc/base/openssladapter.cc
index 601b4af..68a1fcb 100644
--- a/webrtc/base/openssladapter.cc
+++ b/webrtc/base/openssladapter.cc
@@ -695,7 +695,10 @@
}
STACK_OF(CONF_VALUE)* value = meth->i2v(meth, ext_str, NULL);
- for (int j = 0; j < sk_CONF_VALUE_num(value); ++j) {
+
+ // Cast to size_t to be compilable for both OpenSSL and BoringSSL.
+ for (size_t j = 0; j < static_cast<size_t>(sk_CONF_VALUE_num(value));
+ ++j) {
CONF_VALUE* nval = sk_CONF_VALUE_value(value, j);
// The value for nval can contain wildcards
if (!strcmp(nval->name, "DNS") && string_match(host, nval->value)) {
diff --git a/webrtc/base/thread.cc b/webrtc/base/thread.cc
index 49a299d..6da9a7f 100644
--- a/webrtc/base/thread.cc
+++ b/webrtc/base/thread.cc
@@ -125,6 +125,16 @@
Runnable* runnable;
};
+Thread::ScopedDisallowBlockingCalls::ScopedDisallowBlockingCalls()
+ : thread_(Thread::Current()),
+ previous_state_(thread_->SetAllowBlockingCalls(false)) {
+}
+
+Thread::ScopedDisallowBlockingCalls::~ScopedDisallowBlockingCalls() {
+ ASSERT(thread_->IsCurrent());
+ thread_->SetAllowBlockingCalls(previous_state_);
+}
+
Thread::Thread(SocketServer* ss)
: MessageQueue(ss),
priority_(PRIORITY_NORMAL),
@@ -133,7 +143,8 @@
thread_(NULL),
thread_id_(0),
#endif
- owned_(true) {
+ owned_(true),
+ blocking_calls_allowed_(true) {
SetName("Thread", this); // default name
}
@@ -143,6 +154,8 @@
}
bool Thread::SleepMs(int milliseconds) {
+ AssertBlockingIsAllowedOnCurrentThread();
+
#if defined(WEBRTC_WIN)
::Sleep(milliseconds);
return true;
@@ -276,6 +289,8 @@
}
void Thread::Join() {
+ AssertBlockingIsAllowedOnCurrentThread();
+
if (running()) {
ASSERT(!IsCurrent());
#if defined(WEBRTC_WIN)
@@ -291,6 +306,21 @@
}
}
+bool Thread::SetAllowBlockingCalls(bool allow) {
+ ASSERT(IsCurrent());
+ bool previous = blocking_calls_allowed_;
+ blocking_calls_allowed_ = allow;
+ return previous;
+}
+
+// static
+void Thread::AssertBlockingIsAllowedOnCurrentThread() {
+#ifdef _DEBUG
+ Thread* current = Thread::Current();
+ ASSERT(!current || current->blocking_calls_allowed_);
+#endif
+}
+
#if defined(WEBRTC_WIN)
// As seen on MSDN.
// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx
@@ -357,6 +387,8 @@
}
void Thread::Send(MessageHandler *phandler, uint32 id, MessageData *pdata) {
+ AssertBlockingIsAllowedOnCurrentThread();
+
if (fStop_)
return;
diff --git a/webrtc/base/thread.h b/webrtc/base/thread.h
index 3872746..6132aa0 100644
--- a/webrtc/base/thread.h
+++ b/webrtc/base/thread.h
@@ -108,6 +108,19 @@
static Thread* Current();
+ // Used to catch performance regressions. Use this to disallow blocking calls
+ // (Invoke) for a given scope. If a synchronous call is made while this is in
+ // effect, an assert will be triggered.
+ // Note that this is a single threaded class.
+ class ScopedDisallowBlockingCalls {
+ public:
+ ScopedDisallowBlockingCalls();
+ ~ScopedDisallowBlockingCalls();
+ private:
+ Thread* const thread_;
+ const bool previous_state_;
+ };
+
bool IsCurrent() const {
return Current() == this;
}
@@ -148,8 +161,11 @@
// Uses Send() internally, which blocks the current thread until execution
// is complete.
// Ex: bool result = thread.Invoke<bool>(&MyFunctionReturningBool);
+ // NOTE: This function can only be called when synchronous calls are allowed.
+ // See ScopedDisallowBlockingCalls for details.
template <class ReturnT, class FunctorT>
ReturnT Invoke(const FunctorT& functor) {
+ AssertBlockingIsAllowedOnCurrentThread();
FunctorMessageHandler<ReturnT, FunctorT> handler(functor);
Send(&handler);
return handler.result();
@@ -212,6 +228,14 @@
// Blocks the calling thread until this thread has terminated.
void Join();
+ // Sets the per-thread allow-blocking-calls flag and returns the previous
+ // value.
+ bool SetAllowBlockingCalls(bool allow);
+
+ static void AssertBlockingIsAllowedOnCurrentThread();
+
+ friend class ScopedDisallowBlockingCalls;
+
private:
static void *PreRun(void *pv);
@@ -238,6 +262,7 @@
#endif
bool owned_;
+ bool blocking_calls_allowed_; // By default set to |true|.
friend class ThreadManager;