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
This commit is contained in:
henrike@webrtc.org 2014-07-14 22:03:57 +00:00
parent 1b84116417
commit 92a9bacf9a
4 changed files with 62 additions and 40 deletions

View File

@ -246,21 +246,7 @@ void LogMultiline(LoggingSeverity level, const char* label, bool input,
const void* data, size_t len, bool hex_mode, const void* data, size_t len, bool hex_mode,
LogMultilineState* state); 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 #ifndef LOG
#if LOGGING
// The following non-obvious technique for implementation of a // The following non-obvious technique for implementation of a
// conditional log stream was stolen from google3/base/logging.h. // conditional log stream was stolen from google3/base/logging.h.
@ -317,30 +303,6 @@ inline bool LogCheckLevel(LoggingSeverity sev) {
#define LOG_T(sev) LOG(sev) << this << ": " #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) \ #define LOG_ERRNO_EX(sev, err) \
LOG_E(sev, ERRNO, err) LOG_E(sev, ERRNO, err)
#define LOG_ERRNO(sev) \ #define LOG_ERRNO(sev) \

View File

@ -695,7 +695,10 @@ bool OpenSSLAdapter::VerifyServerName(SSL* ssl, const char* host,
} }
STACK_OF(CONF_VALUE)* value = meth->i2v(meth, ext_str, NULL); 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); CONF_VALUE* nval = sk_CONF_VALUE_value(value, j);
// The value for nval can contain wildcards // The value for nval can contain wildcards
if (!strcmp(nval->name, "DNS") && string_match(host, nval->value)) { if (!strcmp(nval->name, "DNS") && string_match(host, nval->value)) {

View File

@ -125,6 +125,16 @@ struct ThreadInit {
Runnable* runnable; 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) Thread::Thread(SocketServer* ss)
: MessageQueue(ss), : MessageQueue(ss),
priority_(PRIORITY_NORMAL), priority_(PRIORITY_NORMAL),
@ -133,7 +143,8 @@ Thread::Thread(SocketServer* ss)
thread_(NULL), thread_(NULL),
thread_id_(0), thread_id_(0),
#endif #endif
owned_(true) { owned_(true),
blocking_calls_allowed_(true) {
SetName("Thread", this); // default name SetName("Thread", this); // default name
} }
@ -143,6 +154,8 @@ Thread::~Thread() {
} }
bool Thread::SleepMs(int milliseconds) { bool Thread::SleepMs(int milliseconds) {
AssertBlockingIsAllowedOnCurrentThread();
#if defined(WEBRTC_WIN) #if defined(WEBRTC_WIN)
::Sleep(milliseconds); ::Sleep(milliseconds);
return true; return true;
@ -276,6 +289,8 @@ bool Thread::Start(Runnable* runnable) {
} }
void Thread::Join() { void Thread::Join() {
AssertBlockingIsAllowedOnCurrentThread();
if (running()) { if (running()) {
ASSERT(!IsCurrent()); ASSERT(!IsCurrent());
#if defined(WEBRTC_WIN) #if defined(WEBRTC_WIN)
@ -291,6 +306,21 @@ void Thread::Join() {
} }
} }
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) #if defined(WEBRTC_WIN)
// As seen on MSDN. // As seen on MSDN.
// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx // http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx
@ -357,6 +387,8 @@ void Thread::Stop() {
} }
void Thread::Send(MessageHandler *phandler, uint32 id, MessageData *pdata) { void Thread::Send(MessageHandler *phandler, uint32 id, MessageData *pdata) {
AssertBlockingIsAllowedOnCurrentThread();
if (fStop_) if (fStop_)
return; return;

View File

@ -108,6 +108,19 @@ class Thread : public MessageQueue {
static Thread* Current(); 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 { bool IsCurrent() const {
return Current() == this; return Current() == this;
} }
@ -148,8 +161,11 @@ class Thread : public MessageQueue {
// Uses Send() internally, which blocks the current thread until execution // Uses Send() internally, which blocks the current thread until execution
// is complete. // is complete.
// Ex: bool result = thread.Invoke<bool>(&MyFunctionReturningBool); // 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> template <class ReturnT, class FunctorT>
ReturnT Invoke(const FunctorT& functor) { ReturnT Invoke(const FunctorT& functor) {
AssertBlockingIsAllowedOnCurrentThread();
FunctorMessageHandler<ReturnT, FunctorT> handler(functor); FunctorMessageHandler<ReturnT, FunctorT> handler(functor);
Send(&handler); Send(&handler);
return handler.result(); return handler.result();
@ -212,6 +228,14 @@ class Thread : public MessageQueue {
// Blocks the calling thread until this thread has terminated. // Blocks the calling thread until this thread has terminated.
void Join(); 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: private:
static void *PreRun(void *pv); static void *PreRun(void *pv);
@ -238,6 +262,7 @@ class Thread : public MessageQueue {
#endif #endif
bool owned_; bool owned_;
bool blocking_calls_allowed_; // By default set to |true|.
friend class ThreadManager; friend class ThreadManager;