Rebase webrtc/base 6163:6216 (svn diff -r 6163:6216 http://webrtc.googlecode.com/svn/trunk/talk/base, apply diff manually)
BUG=3379 TBR=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/17619004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6217 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
f9f1bfbdae
commit
99b4162ccf
@ -109,7 +109,7 @@ void MessageQueueManager::ClearInternal(MessageHandler *handler) {
|
||||
// MessageQueue
|
||||
|
||||
MessageQueue::MessageQueue(SocketServer* ss)
|
||||
: ss_(ss), fStop_(false), fPeekKeep_(false), active_(false),
|
||||
: ss_(ss), fStop_(false), fPeekKeep_(false),
|
||||
dmsgq_next_num_(0) {
|
||||
if (!ss_) {
|
||||
// Currently, MessageQueue holds a socket server, and is the base class for
|
||||
@ -121,6 +121,7 @@ MessageQueue::MessageQueue(SocketServer* ss)
|
||||
ss_ = default_ss_.get();
|
||||
}
|
||||
ss_->SetMessageQueue(this);
|
||||
MessageQueueManager::Add(this);
|
||||
}
|
||||
|
||||
MessageQueue::~MessageQueue() {
|
||||
@ -128,10 +129,8 @@ MessageQueue::~MessageQueue() {
|
||||
// that it always gets called when the queue
|
||||
// is going away.
|
||||
SignalQueueDestroyed();
|
||||
if (active_) {
|
||||
MessageQueueManager::Remove(this);
|
||||
Clear(NULL);
|
||||
}
|
||||
MessageQueueManager::Remove(this);
|
||||
Clear(NULL);
|
||||
if (ss_) {
|
||||
ss_->SetMessageQueue(NULL);
|
||||
}
|
||||
@ -279,7 +278,6 @@ void MessageQueue::Post(MessageHandler *phandler, uint32 id,
|
||||
// Signal for the multiplexer to return
|
||||
|
||||
CritScope cs(&crit_);
|
||||
EnsureActive();
|
||||
Message msg;
|
||||
msg.phandler = phandler;
|
||||
msg.message_id = id;
|
||||
@ -301,7 +299,6 @@ void MessageQueue::DoDelayPost(int cmsDelay, uint32 tstamp,
|
||||
// Signal for the multiplexer to return.
|
||||
|
||||
CritScope cs(&crit_);
|
||||
EnsureActive();
|
||||
Message msg;
|
||||
msg.phandler = phandler;
|
||||
msg.message_id = id;
|
||||
@ -384,12 +381,4 @@ void MessageQueue::Dispatch(Message *pmsg) {
|
||||
pmsg->phandler->OnMessage(pmsg);
|
||||
}
|
||||
|
||||
void MessageQueue::EnsureActive() {
|
||||
ASSERT(crit_.CurrentThreadIsOwner());
|
||||
if (!active_) {
|
||||
active_ = true;
|
||||
MessageQueueManager::Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
@ -58,7 +58,7 @@ class MessageQueueManager {
|
||||
void ClearInternal(MessageHandler *handler);
|
||||
|
||||
static MessageQueueManager* instance_;
|
||||
// This list contains 'active' MessageQueues.
|
||||
// This list contains all live MessageQueues.
|
||||
std::vector<MessageQueue *> message_queues_;
|
||||
CriticalSection crit_;
|
||||
};
|
||||
@ -230,7 +230,6 @@ class MessageQueue {
|
||||
void reheap() { make_heap(c.begin(), c.end(), comp); }
|
||||
};
|
||||
|
||||
void EnsureActive();
|
||||
void DoDelayPost(int cmsDelay, uint32 tstamp, MessageHandler *phandler,
|
||||
uint32 id, MessageData* pdata);
|
||||
|
||||
@ -241,9 +240,6 @@ class MessageQueue {
|
||||
bool fStop_;
|
||||
bool fPeekKeep_;
|
||||
Message msgPeek_;
|
||||
// A message queue is active if it has ever had a message posted to it.
|
||||
// This also corresponds to being in MessageQueueManager's global list.
|
||||
bool active_;
|
||||
MessageList msgq_;
|
||||
PriorityQueue dmsgq_;
|
||||
uint32 dmsgq_next_num_;
|
||||
|
@ -140,8 +140,7 @@ Thread::Thread(SocketServer* ss)
|
||||
|
||||
Thread::~Thread() {
|
||||
Stop();
|
||||
if (active_)
|
||||
Clear(NULL);
|
||||
Clear(NULL);
|
||||
}
|
||||
|
||||
bool Thread::SleepMs(int milliseconds) {
|
||||
@ -386,7 +385,6 @@ void Thread::Send(MessageHandler *phandler, uint32 id, MessageData *pdata) {
|
||||
bool ready = false;
|
||||
{
|
||||
CritScope cs(&crit_);
|
||||
EnsureActive();
|
||||
_SendMessage smsg;
|
||||
smsg.thread = current_thread;
|
||||
smsg.msg = msg;
|
||||
|
@ -186,4 +186,18 @@ int32 TimeDiff(uint32 later, uint32 earlier) {
|
||||
#endif
|
||||
}
|
||||
|
||||
TimestampWrapAroundHandler::TimestampWrapAroundHandler()
|
||||
: last_ts_(0), num_wrap_(0) {}
|
||||
|
||||
int64 TimestampWrapAroundHandler::Unwrap(uint32 ts) {
|
||||
if (ts < last_ts_) {
|
||||
if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) {
|
||||
++num_wrap_;
|
||||
}
|
||||
}
|
||||
last_ts_ = ts;
|
||||
int64_t unwrapped_ts = ts + (num_wrap_ << 32);
|
||||
return unwrapped_ts;
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
@ -80,6 +80,17 @@ inline int64 UnixTimestampNanosecsToNtpMillisecs(int64 unix_ts_ns) {
|
||||
return unix_ts_ns / kNumNanosecsPerMillisec + kJan1970AsNtpMillisecs;
|
||||
}
|
||||
|
||||
class TimestampWrapAroundHandler {
|
||||
public:
|
||||
TimestampWrapAroundHandler();
|
||||
|
||||
int64 Unwrap(uint32 ts);
|
||||
|
||||
private:
|
||||
uint32 last_ts_;
|
||||
int64 num_wrap_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // WEBRTC_BASE_TIMEUTILS_H_
|
||||
|
@ -143,4 +143,27 @@ TEST(TimeTest, DISABLED_CurrentTmTime) {
|
||||
EXPECT_TRUE(0 <= microseconds && microseconds < 1000000);
|
||||
}
|
||||
|
||||
class TimestampWrapAroundHandlerTest : public testing::Test {
|
||||
public:
|
||||
TimestampWrapAroundHandlerTest() {}
|
||||
|
||||
protected:
|
||||
TimestampWrapAroundHandler wraparound_handler_;
|
||||
};
|
||||
|
||||
TEST_F(TimestampWrapAroundHandlerTest, Unwrap) {
|
||||
uint32 ts = 0xfffffff2;
|
||||
int64 unwrapped_ts = ts;
|
||||
EXPECT_EQ(ts, wraparound_handler_.Unwrap(ts));
|
||||
ts = 2;
|
||||
unwrapped_ts += 0x10;
|
||||
EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts));
|
||||
ts = 0xfffffff2;
|
||||
unwrapped_ts += 0xfffffff0;
|
||||
EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts));
|
||||
ts = 0;
|
||||
unwrapped_ts += 0xe;
|
||||
EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts));
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
Loading…
Reference in New Issue
Block a user