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:
@ -125,6 +125,16 @@ struct ThreadInit {
|
||||
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::Thread(SocketServer* ss)
|
||||
thread_(NULL),
|
||||
thread_id_(0),
|
||||
#endif
|
||||
owned_(true) {
|
||||
owned_(true),
|
||||
blocking_calls_allowed_(true) {
|
||||
SetName("Thread", this); // default name
|
||||
}
|
||||
|
||||
@ -143,6 +154,8 @@ Thread::~Thread() {
|
||||
}
|
||||
|
||||
bool Thread::SleepMs(int milliseconds) {
|
||||
AssertBlockingIsAllowedOnCurrentThread();
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
::Sleep(milliseconds);
|
||||
return true;
|
||||
@ -276,6 +289,8 @@ bool Thread::Start(Runnable* runnable) {
|
||||
}
|
||||
|
||||
void Thread::Join() {
|
||||
AssertBlockingIsAllowedOnCurrentThread();
|
||||
|
||||
if (running()) {
|
||||
ASSERT(!IsCurrent());
|
||||
#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)
|
||||
// As seen on MSDN.
|
||||
// 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) {
|
||||
AssertBlockingIsAllowedOnCurrentThread();
|
||||
|
||||
if (fStop_)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user