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 21 matching lines...) Expand all Loading... |
32 int* value, | 32 int* value, |
33 bool* done) | 33 bool* done) |
34 : shared_exclusive_lock_(shared_exclusive_lock), | 34 : shared_exclusive_lock_(shared_exclusive_lock), |
35 waiting_time_in_ms_(0), | 35 waiting_time_in_ms_(0), |
36 value_(value), | 36 value_(value), |
37 done_(done) { | 37 done_(done) { |
38 worker_thread_.reset(new Thread()); | 38 worker_thread_.reset(new Thread()); |
39 worker_thread_->Start(); | 39 worker_thread_->Start(); |
40 } | 40 } |
41 | 41 |
42 int waiting_time_in_ms() const { return waiting_time_in_ms_; } | 42 int64_t waiting_time_in_ms() const { return waiting_time_in_ms_; } |
43 | 43 |
44 protected: | 44 protected: |
45 scoped_ptr<Thread> worker_thread_; | 45 scoped_ptr<Thread> worker_thread_; |
46 SharedExclusiveLock* shared_exclusive_lock_; | 46 SharedExclusiveLock* shared_exclusive_lock_; |
47 int waiting_time_in_ms_; | 47 int64_t waiting_time_in_ms_; |
48 int* value_; | 48 int* value_; |
49 bool* done_; | 49 bool* done_; |
50 }; | 50 }; |
51 | 51 |
52 class ReadTask : public SharedExclusiveTask { | 52 class ReadTask : public SharedExclusiveTask { |
53 public: | 53 public: |
54 ReadTask(SharedExclusiveLock* shared_exclusive_lock, int* value, bool* done) | 54 ReadTask(SharedExclusiveLock* shared_exclusive_lock, int* value, bool* done) |
55 : SharedExclusiveTask(shared_exclusive_lock, value, done) { | 55 : SharedExclusiveTask(shared_exclusive_lock, value, done) { |
56 } | 56 } |
57 | 57 |
58 void PostRead(int* value) { | 58 void PostRead(int* value) { |
59 worker_thread_->Post(this, kMsgRead, new TypedMessageData<int*>(value)); | 59 worker_thread_->Post(this, kMsgRead, new TypedMessageData<int*>(value)); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 virtual void OnMessage(Message* message) { | 63 virtual void OnMessage(Message* message) { |
64 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 64 ASSERT(rtc::Thread::Current() == worker_thread_.get()); |
65 ASSERT(message != NULL); | 65 ASSERT(message != NULL); |
66 ASSERT(message->message_id == kMsgRead); | 66 ASSERT(message->message_id == kMsgRead); |
67 | 67 |
68 TypedMessageData<int*>* message_data = | 68 TypedMessageData<int*>* message_data = |
69 static_cast<TypedMessageData<int*>*>(message->pdata); | 69 static_cast<TypedMessageData<int*>*>(message->pdata); |
70 | 70 |
71 uint32_t start_time = Time(); | 71 int64_t start_time = Time(); |
72 { | 72 { |
73 SharedScope ss(shared_exclusive_lock_); | 73 SharedScope ss(shared_exclusive_lock_); |
74 waiting_time_in_ms_ = TimeDiff(Time(), start_time); | 74 waiting_time_in_ms_ = TimeDiff(Time(), start_time); |
75 | 75 |
76 Thread::SleepMs(kProcessTimeInMs); | 76 Thread::SleepMs(kProcessTimeInMs); |
77 *message_data->data() = *value_; | 77 *message_data->data() = *value_; |
78 *done_ = true; | 78 *done_ = true; |
79 } | 79 } |
80 delete message->pdata; | 80 delete message->pdata; |
81 message->pdata = NULL; | 81 message->pdata = NULL; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 Thread::SleepMs(kProcessTimeInMs); | 209 Thread::SleepMs(kProcessTimeInMs); |
210 EXPECT_EQ(1, value_); | 210 EXPECT_EQ(1, value_); |
211 } | 211 } |
212 | 212 |
213 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); | 213 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); |
214 EXPECT_EQ(2, value_); | 214 EXPECT_EQ(2, value_); |
215 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); | 215 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); |
216 } | 216 } |
217 | 217 |
218 } // namespace rtc | 218 } // namespace rtc |
OLD | NEW |