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

@@ -108,6 +108,19 @@ class Thread : public MessageQueue {
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 @@ class Thread : public MessageQueue {
// 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 @@ class Thread : public MessageQueue {
// 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 @@ class Thread : public MessageQueue {
#endif
bool owned_;
bool blocking_calls_allowed_; // By default set to |true|.
friend class ThreadManager;