| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/base/common.h" | 11 #include "webrtc/base/common.h" |
| 12 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
| 13 #include "webrtc/base/messagehandler.h" | 13 #include "webrtc/base/messagehandler.h" |
| 14 #include "webrtc/base/messagequeue.h" | 14 #include "webrtc/base/messagequeue.h" |
| 15 #include "webrtc/base/scoped_ptr.h" | 15 #include "webrtc/base/scoped_ptr.h" |
| 16 #include "webrtc/base/sharedexclusivelock.h" | 16 #include "webrtc/base/sharedexclusivelock.h" |
| 17 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
| 18 #include "webrtc/base/timeutils.h" | 18 #include "webrtc/base/timeutils.h" |
| 19 #include "webrtc/test/testsupport/gtest_disable.h" | 19 #include "webrtc/test/testsupport/gtest_disable.h" |
| 20 | 20 |
| 21 namespace rtc { | 21 namespace rtc { |
| 22 | 22 |
| 23 static const uint32 kMsgRead = 0; | 23 static const uint32_t kMsgRead = 0; |
| 24 static const uint32 kMsgWrite = 0; | 24 static const uint32_t kMsgWrite = 0; |
| 25 static const int kNoWaitThresholdInMs = 10; | 25 static const int kNoWaitThresholdInMs = 10; |
| 26 static const int kWaitThresholdInMs = 80; | 26 static const int kWaitThresholdInMs = 80; |
| 27 static const int kProcessTimeInMs = 100; | 27 static const int kProcessTimeInMs = 100; |
| 28 static const int kProcessTimeoutInMs = 5000; | 28 static const int kProcessTimeoutInMs = 5000; |
| 29 | 29 |
| 30 class SharedExclusiveTask : public MessageHandler { | 30 class SharedExclusiveTask : public MessageHandler { |
| 31 public: | 31 public: |
| 32 SharedExclusiveTask(SharedExclusiveLock* shared_exclusive_lock, | 32 SharedExclusiveTask(SharedExclusiveLock* shared_exclusive_lock, |
| 33 int* value, | 33 int* value, |
| 34 bool* done) | 34 bool* done) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 virtual void OnMessage(Message* message) { | 64 virtual void OnMessage(Message* message) { |
| 65 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 65 ASSERT(rtc::Thread::Current() == worker_thread_.get()); |
| 66 ASSERT(message != NULL); | 66 ASSERT(message != NULL); |
| 67 ASSERT(message->message_id == kMsgRead); | 67 ASSERT(message->message_id == kMsgRead); |
| 68 | 68 |
| 69 TypedMessageData<int*>* message_data = | 69 TypedMessageData<int*>* message_data = |
| 70 static_cast<TypedMessageData<int*>*>(message->pdata); | 70 static_cast<TypedMessageData<int*>*>(message->pdata); |
| 71 | 71 |
| 72 uint32 start_time = Time(); | 72 uint32_t start_time = Time(); |
| 73 { | 73 { |
| 74 SharedScope ss(shared_exclusive_lock_); | 74 SharedScope ss(shared_exclusive_lock_); |
| 75 waiting_time_in_ms_ = TimeDiff(Time(), start_time); | 75 waiting_time_in_ms_ = TimeDiff(Time(), start_time); |
| 76 | 76 |
| 77 Thread::SleepMs(kProcessTimeInMs); | 77 Thread::SleepMs(kProcessTimeInMs); |
| 78 *message_data->data() = *value_; | 78 *message_data->data() = *value_; |
| 79 *done_ = true; | 79 *done_ = true; |
| 80 } | 80 } |
| 81 delete message->pdata; | 81 delete message->pdata; |
| 82 message->pdata = NULL; | 82 message->pdata = NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 virtual void OnMessage(Message* message) { | 97 virtual void OnMessage(Message* message) { |
| 98 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 98 ASSERT(rtc::Thread::Current() == worker_thread_.get()); |
| 99 ASSERT(message != NULL); | 99 ASSERT(message != NULL); |
| 100 ASSERT(message->message_id == kMsgWrite); | 100 ASSERT(message->message_id == kMsgWrite); |
| 101 | 101 |
| 102 TypedMessageData<int>* message_data = | 102 TypedMessageData<int>* message_data = |
| 103 static_cast<TypedMessageData<int>*>(message->pdata); | 103 static_cast<TypedMessageData<int>*>(message->pdata); |
| 104 | 104 |
| 105 uint32 start_time = Time(); | 105 uint32_t start_time = Time(); |
| 106 { | 106 { |
| 107 ExclusiveScope es(shared_exclusive_lock_); | 107 ExclusiveScope es(shared_exclusive_lock_); |
| 108 waiting_time_in_ms_ = TimeDiff(Time(), start_time); | 108 waiting_time_in_ms_ = TimeDiff(Time(), start_time); |
| 109 | 109 |
| 110 Thread::SleepMs(kProcessTimeInMs); | 110 Thread::SleepMs(kProcessTimeInMs); |
| 111 *value_ = message_data->data(); | 111 *value_ = message_data->data(); |
| 112 *done_ = true; | 112 *done_ = true; |
| 113 } | 113 } |
| 114 delete message->pdata; | 114 delete message->pdata; |
| 115 message->pdata = NULL; | 115 message->pdata = NULL; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 Thread::SleepMs(kProcessTimeInMs); | 210 Thread::SleepMs(kProcessTimeInMs); |
| 211 EXPECT_EQ(1, value_); | 211 EXPECT_EQ(1, value_); |
| 212 } | 212 } |
| 213 | 213 |
| 214 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); | 214 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); |
| 215 EXPECT_EQ(2, value_); | 215 EXPECT_EQ(2, value_); |
| 216 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); | 216 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); |
| 217 } | 217 } |
| 218 | 218 |
| 219 } // namespace rtc | 219 } // namespace rtc |
| OLD | NEW |