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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 int* value, | 43 int* value, |
44 bool* done) | 44 bool* done) |
45 : shared_exclusive_lock_(shared_exclusive_lock), | 45 : shared_exclusive_lock_(shared_exclusive_lock), |
46 waiting_time_in_ms_(0), | 46 waiting_time_in_ms_(0), |
47 value_(value), | 47 value_(value), |
48 done_(done) { | 48 done_(done) { |
49 worker_thread_.reset(new Thread()); | 49 worker_thread_.reset(new Thread()); |
50 worker_thread_->Start(); | 50 worker_thread_->Start(); |
51 } | 51 } |
52 | 52 |
53 int waiting_time_in_ms() const { return waiting_time_in_ms_; } | 53 int64_t waiting_time_in_ms() const { return waiting_time_in_ms_; } |
54 | 54 |
55 protected: | 55 protected: |
56 std::unique_ptr<Thread> worker_thread_; | 56 std::unique_ptr<Thread> worker_thread_; |
57 SharedExclusiveLock* shared_exclusive_lock_; | 57 SharedExclusiveLock* shared_exclusive_lock_; |
58 int waiting_time_in_ms_; | 58 int64_t waiting_time_in_ms_; |
59 int* value_; | 59 int* value_; |
60 bool* done_; | 60 bool* done_; |
61 }; | 61 }; |
62 | 62 |
63 class ReadTask : public SharedExclusiveTask { | 63 class ReadTask : public SharedExclusiveTask { |
64 public: | 64 public: |
65 ReadTask(SharedExclusiveLock* shared_exclusive_lock, int* value, bool* done) | 65 ReadTask(SharedExclusiveLock* shared_exclusive_lock, int* value, bool* done) |
66 : SharedExclusiveTask(shared_exclusive_lock, value, done) { | 66 : SharedExclusiveTask(shared_exclusive_lock, value, done) { |
67 } | 67 } |
68 | 68 |
69 void PostRead(int* value) { | 69 void PostRead(int* value) { |
70 worker_thread_->Post(this, kMsgRead, new TypedMessageData<int*>(value)); | 70 worker_thread_->Post(this, kMsgRead, new TypedMessageData<int*>(value)); |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 virtual void OnMessage(Message* message) { | 74 virtual void OnMessage(Message* message) { |
75 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 75 ASSERT(rtc::Thread::Current() == worker_thread_.get()); |
76 ASSERT(message != NULL); | 76 ASSERT(message != NULL); |
77 ASSERT(message->message_id == kMsgRead); | 77 ASSERT(message->message_id == kMsgRead); |
78 | 78 |
79 TypedMessageData<int*>* message_data = | 79 TypedMessageData<int*>* message_data = |
80 static_cast<TypedMessageData<int*>*>(message->pdata); | 80 static_cast<TypedMessageData<int*>*>(message->pdata); |
81 | 81 |
82 uint32_t start_time = Time(); | 82 int64_t start_time = TimeMillis(); |
83 { | 83 { |
84 SharedScope ss(shared_exclusive_lock_); | 84 SharedScope ss(shared_exclusive_lock_); |
85 waiting_time_in_ms_ = TimeDiff(Time(), start_time); | 85 waiting_time_in_ms_ = TimeDiff(TimeMillis(), start_time); |
86 | 86 |
87 Thread::SleepMs(kProcessTimeInMs); | 87 Thread::SleepMs(kProcessTimeInMs); |
88 *message_data->data() = *value_; | 88 *message_data->data() = *value_; |
89 *done_ = true; | 89 *done_ = true; |
90 } | 90 } |
91 delete message->pdata; | 91 delete message->pdata; |
92 message->pdata = NULL; | 92 message->pdata = NULL; |
93 } | 93 } |
94 }; | 94 }; |
95 | 95 |
96 class WriteTask : public SharedExclusiveTask { | 96 class WriteTask : public SharedExclusiveTask { |
97 public: | 97 public: |
98 WriteTask(SharedExclusiveLock* shared_exclusive_lock, int* value, bool* done) | 98 WriteTask(SharedExclusiveLock* shared_exclusive_lock, int* value, bool* done) |
99 : SharedExclusiveTask(shared_exclusive_lock, value, done) { | 99 : SharedExclusiveTask(shared_exclusive_lock, value, done) { |
100 } | 100 } |
101 | 101 |
102 void PostWrite(int value) { | 102 void PostWrite(int value) { |
103 worker_thread_->Post(this, kMsgWrite, new TypedMessageData<int>(value)); | 103 worker_thread_->Post(this, kMsgWrite, new TypedMessageData<int>(value)); |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 virtual void OnMessage(Message* message) { | 107 virtual void OnMessage(Message* message) { |
108 ASSERT(rtc::Thread::Current() == worker_thread_.get()); | 108 ASSERT(rtc::Thread::Current() == worker_thread_.get()); |
109 ASSERT(message != NULL); | 109 ASSERT(message != NULL); |
110 ASSERT(message->message_id == kMsgWrite); | 110 ASSERT(message->message_id == kMsgWrite); |
111 | 111 |
112 TypedMessageData<int>* message_data = | 112 TypedMessageData<int>* message_data = |
113 static_cast<TypedMessageData<int>*>(message->pdata); | 113 static_cast<TypedMessageData<int>*>(message->pdata); |
114 | 114 |
115 uint32_t start_time = Time(); | 115 int64_t start_time = TimeMillis(); |
116 { | 116 { |
117 ExclusiveScope es(shared_exclusive_lock_); | 117 ExclusiveScope es(shared_exclusive_lock_); |
118 waiting_time_in_ms_ = TimeDiff(Time(), start_time); | 118 waiting_time_in_ms_ = TimeDiff(TimeMillis(), start_time); |
119 | 119 |
120 Thread::SleepMs(kProcessTimeInMs); | 120 Thread::SleepMs(kProcessTimeInMs); |
121 *value_ = message_data->data(); | 121 *value_ = message_data->data(); |
122 *done_ = true; | 122 *done_ = true; |
123 } | 123 } |
124 delete message->pdata; | 124 delete message->pdata; |
125 message->pdata = NULL; | 125 message->pdata = NULL; |
126 } | 126 } |
127 }; | 127 }; |
128 | 128 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 Thread::SleepMs(kProcessTimeInMs); | 220 Thread::SleepMs(kProcessTimeInMs); |
221 EXPECT_EQ(1, value_); | 221 EXPECT_EQ(1, value_); |
222 } | 222 } |
223 | 223 |
224 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); | 224 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); |
225 EXPECT_EQ(2, value_); | 225 EXPECT_EQ(2, value_); |
226 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); | 226 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); |
227 } | 227 } |
228 | 228 |
229 } // namespace rtc | 229 } // namespace rtc |
OLD | NEW |