| 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 <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" |
| 13 #include "webrtc/base/common.h" | 14 #include "webrtc/base/common.h" |
| 14 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/event.h" | 16 #include "webrtc/base/event.h" |
| 16 #include "webrtc/base/messagehandler.h" | 17 #include "webrtc/base/messagehandler.h" |
| 17 #include "webrtc/base/messagequeue.h" | 18 #include "webrtc/base/messagequeue.h" |
| 18 #include "webrtc/base/sharedexclusivelock.h" | 19 #include "webrtc/base/sharedexclusivelock.h" |
| 19 #include "webrtc/base/thread.h" | 20 #include "webrtc/base/thread.h" |
| 20 #include "webrtc/base/timeutils.h" | 21 #include "webrtc/base/timeutils.h" |
| 21 | 22 |
| 22 namespace rtc { | 23 namespace rtc { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 : SharedExclusiveTask(shared_exclusive_lock, value, done) { | 54 : SharedExclusiveTask(shared_exclusive_lock, value, done) { |
| 54 } | 55 } |
| 55 | 56 |
| 56 void PostRead(int* value) { | 57 void PostRead(int* value) { |
| 57 worker_thread_->Post(RTC_FROM_HERE, this, kMsgRead, | 58 worker_thread_->Post(RTC_FROM_HERE, this, kMsgRead, |
| 58 new TypedMessageData<int*>(value)); | 59 new TypedMessageData<int*>(value)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 virtual void OnMessage(Message* message) { | 63 virtual void OnMessage(Message* message) { |
| 63 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 64 RTC_CHECK(rtc::Thread::Current() == worker_thread_.get()); |
| 64 ASSERT(message != NULL); | 65 RTC_CHECK(message != NULL); |
| 65 ASSERT(message->message_id == kMsgRead); | 66 RTC_CHECK(message->message_id == kMsgRead); |
| 66 | 67 |
| 67 TypedMessageData<int*>* message_data = | 68 TypedMessageData<int*>* message_data = |
| 68 static_cast<TypedMessageData<int*>*>(message->pdata); | 69 static_cast<TypedMessageData<int*>*>(message->pdata); |
| 69 | 70 |
| 70 { | 71 { |
| 71 SharedScope ss(shared_exclusive_lock_); | 72 SharedScope ss(shared_exclusive_lock_); |
| 72 *message_data->data() = *value_; | 73 *message_data->data() = *value_; |
| 73 done_->Set(); | 74 done_->Set(); |
| 74 } | 75 } |
| 75 delete message->pdata; | 76 delete message->pdata; |
| 76 message->pdata = NULL; | 77 message->pdata = NULL; |
| 77 } | 78 } |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 class WriteTask : public SharedExclusiveTask { | 81 class WriteTask : public SharedExclusiveTask { |
| 81 public: | 82 public: |
| 82 WriteTask(SharedExclusiveLock* shared_exclusive_lock, int* value, Event* done) | 83 WriteTask(SharedExclusiveLock* shared_exclusive_lock, int* value, Event* done) |
| 83 : SharedExclusiveTask(shared_exclusive_lock, value, done) { | 84 : SharedExclusiveTask(shared_exclusive_lock, value, done) { |
| 84 } | 85 } |
| 85 | 86 |
| 86 void PostWrite(int value) { | 87 void PostWrite(int value) { |
| 87 worker_thread_->Post(RTC_FROM_HERE, this, kMsgWrite, | 88 worker_thread_->Post(RTC_FROM_HERE, this, kMsgWrite, |
| 88 new TypedMessageData<int>(value)); | 89 new TypedMessageData<int>(value)); |
| 89 } | 90 } |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 virtual void OnMessage(Message* message) { | 93 virtual void OnMessage(Message* message) { |
| 93 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 94 RTC_CHECK(rtc::Thread::Current() == worker_thread_.get()); |
| 94 ASSERT(message != NULL); | 95 RTC_CHECK(message != NULL); |
| 95 ASSERT(message->message_id == kMsgWrite); | 96 RTC_CHECK(message->message_id == kMsgWrite); |
| 96 | 97 |
| 97 TypedMessageData<int>* message_data = | 98 TypedMessageData<int>* message_data = |
| 98 static_cast<TypedMessageData<int>*>(message->pdata); | 99 static_cast<TypedMessageData<int>*>(message->pdata); |
| 99 | 100 |
| 100 { | 101 { |
| 101 ExclusiveScope es(shared_exclusive_lock_); | 102 ExclusiveScope es(shared_exclusive_lock_); |
| 102 *value_ = message_data->data(); | 103 *value_ = message_data->data(); |
| 103 done_->Set(); | 104 done_->Set(); |
| 104 } | 105 } |
| 105 delete message->pdata; | 106 delete message->pdata; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 writer.PostWrite(2); | 189 writer.PostWrite(2); |
| 189 EXPECT_FALSE(done.Wait(kProcessTimeInMs)); | 190 EXPECT_FALSE(done.Wait(kProcessTimeInMs)); |
| 190 EXPECT_EQ(1, value_); | 191 EXPECT_EQ(1, value_); |
| 191 } | 192 } |
| 192 | 193 |
| 193 EXPECT_TRUE(done.Wait(kProcessTimeoutInMs)); | 194 EXPECT_TRUE(done.Wait(kProcessTimeoutInMs)); |
| 194 EXPECT_EQ(2, value_); | 195 EXPECT_EQ(2, value_); |
| 195 } | 196 } |
| 196 | 197 |
| 197 } // namespace rtc | 198 } // namespace rtc |
| OLD | NEW |