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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 void PostRead(int* value) { | 56 void PostRead(int* value) { |
57 worker_thread_->Post(RTC_FROM_HERE, this, kMsgRead, | 57 worker_thread_->Post(RTC_FROM_HERE, this, kMsgRead, |
58 new TypedMessageData<int*>(value)); | 58 new TypedMessageData<int*>(value)); |
59 } | 59 } |
60 | 60 |
61 private: | 61 private: |
62 virtual void OnMessage(Message* message) { | 62 virtual void OnMessage(Message* message) { |
63 RTC_CHECK(rtc::Thread::Current() == worker_thread_.get()); | 63 RTC_CHECK(rtc::Thread::Current() == worker_thread_.get()); |
64 RTC_CHECK(message != NULL); | 64 RTC_CHECK(message != nullptr); |
65 RTC_CHECK(message->message_id == kMsgRead); | 65 RTC_CHECK(message->message_id == kMsgRead); |
66 | 66 |
67 TypedMessageData<int*>* message_data = | 67 TypedMessageData<int*>* message_data = |
68 static_cast<TypedMessageData<int*>*>(message->pdata); | 68 static_cast<TypedMessageData<int*>*>(message->pdata); |
69 | 69 |
70 { | 70 { |
71 SharedScope ss(shared_exclusive_lock_); | 71 SharedScope ss(shared_exclusive_lock_); |
72 *message_data->data() = *value_; | 72 *message_data->data() = *value_; |
73 done_->Set(); | 73 done_->Set(); |
74 } | 74 } |
75 delete message->pdata; | 75 delete message->pdata; |
76 message->pdata = NULL; | 76 message->pdata = nullptr; |
77 } | 77 } |
78 }; | 78 }; |
79 | 79 |
80 class WriteTask : public SharedExclusiveTask { | 80 class WriteTask : public SharedExclusiveTask { |
81 public: | 81 public: |
82 WriteTask(SharedExclusiveLock* shared_exclusive_lock, int* value, Event* done) | 82 WriteTask(SharedExclusiveLock* shared_exclusive_lock, int* value, Event* done) |
83 : SharedExclusiveTask(shared_exclusive_lock, value, done) { | 83 : SharedExclusiveTask(shared_exclusive_lock, value, done) { |
84 } | 84 } |
85 | 85 |
86 void PostWrite(int value) { | 86 void PostWrite(int value) { |
87 worker_thread_->Post(RTC_FROM_HERE, this, kMsgWrite, | 87 worker_thread_->Post(RTC_FROM_HERE, this, kMsgWrite, |
88 new TypedMessageData<int>(value)); | 88 new TypedMessageData<int>(value)); |
89 } | 89 } |
90 | 90 |
91 private: | 91 private: |
92 virtual void OnMessage(Message* message) { | 92 virtual void OnMessage(Message* message) { |
93 RTC_CHECK(rtc::Thread::Current() == worker_thread_.get()); | 93 RTC_CHECK(rtc::Thread::Current() == worker_thread_.get()); |
94 RTC_CHECK(message != NULL); | 94 RTC_CHECK(message != nullptr); |
95 RTC_CHECK(message->message_id == kMsgWrite); | 95 RTC_CHECK(message->message_id == kMsgWrite); |
96 | 96 |
97 TypedMessageData<int>* message_data = | 97 TypedMessageData<int>* message_data = |
98 static_cast<TypedMessageData<int>*>(message->pdata); | 98 static_cast<TypedMessageData<int>*>(message->pdata); |
99 | 99 |
100 { | 100 { |
101 ExclusiveScope es(shared_exclusive_lock_); | 101 ExclusiveScope es(shared_exclusive_lock_); |
102 *value_ = message_data->data(); | 102 *value_ = message_data->data(); |
103 done_->Set(); | 103 done_->Set(); |
104 } | 104 } |
105 delete message->pdata; | 105 delete message->pdata; |
106 message->pdata = NULL; | 106 message->pdata = nullptr; |
107 } | 107 } |
108 }; | 108 }; |
109 | 109 |
110 // Unit test for SharedExclusiveLock. | 110 // Unit test for SharedExclusiveLock. |
111 class SharedExclusiveLockTest | 111 class SharedExclusiveLockTest |
112 : public testing::Test { | 112 : public testing::Test { |
113 public: | 113 public: |
114 SharedExclusiveLockTest() : value_(0) { | 114 SharedExclusiveLockTest() : value_(0) { |
115 } | 115 } |
116 | 116 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 writer.PostWrite(2); | 188 writer.PostWrite(2); |
189 EXPECT_FALSE(done.Wait(kProcessTimeInMs)); | 189 EXPECT_FALSE(done.Wait(kProcessTimeInMs)); |
190 EXPECT_EQ(1, value_); | 190 EXPECT_EQ(1, value_); |
191 } | 191 } |
192 | 192 |
193 EXPECT_TRUE(done.Wait(kProcessTimeoutInMs)); | 193 EXPECT_TRUE(done.Wait(kProcessTimeoutInMs)); |
194 EXPECT_EQ(2, value_); | 194 EXPECT_EQ(2, value_); |
195 } | 195 } |
196 | 196 |
197 } // namespace rtc | 197 } // namespace rtc |
OLD | NEW |