OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 Message() { | 135 Message() { |
136 memset(this, 0, sizeof(*this)); | 136 memset(this, 0, sizeof(*this)); |
137 } | 137 } |
138 inline bool Match(MessageHandler* handler, uint32_t id) const { | 138 inline bool Match(MessageHandler* handler, uint32_t id) const { |
139 return (handler == NULL || handler == phandler) | 139 return (handler == NULL || handler == phandler) |
140 && (id == MQID_ANY || id == message_id); | 140 && (id == MQID_ANY || id == message_id); |
141 } | 141 } |
142 MessageHandler *phandler; | 142 MessageHandler *phandler; |
143 uint32_t message_id; | 143 uint32_t message_id; |
144 MessageData *pdata; | 144 MessageData *pdata; |
145 uint32_t ts_sensitive; | 145 int64_t ts_sensitive; |
146 }; | 146 }; |
147 | 147 |
148 typedef std::list<Message> MessageList; | 148 typedef std::list<Message> MessageList; |
149 | 149 |
150 // DelayedMessage goes into a priority queue, sorted by trigger time. Messages | 150 // DelayedMessage goes into a priority queue, sorted by trigger time. Messages |
151 // with the same trigger time are processed in num_ (FIFO) order. | 151 // with the same trigger time are processed in num_ (FIFO) order. |
152 | 152 |
153 class DelayedMessage { | 153 class DelayedMessage { |
154 public: | 154 public: |
155 DelayedMessage(int delay, uint32_t trigger, uint32_t num, const Message& msg) | 155 DelayedMessage(int delay, int64_t trigger, uint32_t num, const Message& msg) |
156 : cmsDelay_(delay), msTrigger_(trigger), num_(num), msg_(msg) {} | 156 : cmsDelay_(delay), msTrigger_(trigger), num_(num), msg_(msg) {} |
157 | 157 |
158 bool operator< (const DelayedMessage& dmsg) const { | 158 bool operator< (const DelayedMessage& dmsg) const { |
159 return (dmsg.msTrigger_ < msTrigger_) | 159 return (dmsg.msTrigger_ < msTrigger_) |
160 || ((dmsg.msTrigger_ == msTrigger_) && (dmsg.num_ < num_)); | 160 || ((dmsg.msTrigger_ == msTrigger_) && (dmsg.num_ < num_)); |
161 } | 161 } |
162 | 162 |
163 int cmsDelay_; // for debugging | 163 int cmsDelay_; // for debugging |
164 uint32_t msTrigger_; | 164 int64_t msTrigger_; |
165 uint32_t num_; | 165 uint32_t num_; |
166 Message msg_; | 166 Message msg_; |
167 }; | 167 }; |
168 | 168 |
169 class MessageQueue { | 169 class MessageQueue { |
170 public: | 170 public: |
171 static const int kForever = -1; | 171 static const int kForever = -1; |
172 | 172 |
173 // Create a new MessageQueue and optionally assign it to the passed | 173 // Create a new MessageQueue and optionally assign it to the passed |
174 // SocketServer. Subclasses that override Clear should pass false for | 174 // SocketServer. Subclasses that override Clear should pass false for |
(...skipping 30 matching lines...) Expand all Loading... |
205 bool process_io = true); | 205 bool process_io = true); |
206 virtual bool Peek(Message *pmsg, int cmsWait = 0); | 206 virtual bool Peek(Message *pmsg, int cmsWait = 0); |
207 virtual void Post(MessageHandler* phandler, | 207 virtual void Post(MessageHandler* phandler, |
208 uint32_t id = 0, | 208 uint32_t id = 0, |
209 MessageData* pdata = NULL, | 209 MessageData* pdata = NULL, |
210 bool time_sensitive = false); | 210 bool time_sensitive = false); |
211 virtual void PostDelayed(int cmsDelay, | 211 virtual void PostDelayed(int cmsDelay, |
212 MessageHandler* phandler, | 212 MessageHandler* phandler, |
213 uint32_t id = 0, | 213 uint32_t id = 0, |
214 MessageData* pdata = NULL); | 214 MessageData* pdata = NULL); |
| 215 virtual void PostAt(int64_t tstamp, |
| 216 MessageHandler* phandler, |
| 217 uint32_t id = 0, |
| 218 MessageData* pdata = NULL); |
| 219 // TODO(honghaiz): Remove this when all the dependencies are removed. |
215 virtual void PostAt(uint32_t tstamp, | 220 virtual void PostAt(uint32_t tstamp, |
216 MessageHandler* phandler, | 221 MessageHandler* phandler, |
217 uint32_t id = 0, | 222 uint32_t id = 0, |
218 MessageData* pdata = NULL); | 223 MessageData* pdata = NULL); |
219 virtual void Clear(MessageHandler* phandler, | 224 virtual void Clear(MessageHandler* phandler, |
220 uint32_t id = MQID_ANY, | 225 uint32_t id = MQID_ANY, |
221 MessageList* removed = NULL); | 226 MessageList* removed = NULL); |
222 virtual void Dispatch(Message *pmsg); | 227 virtual void Dispatch(Message *pmsg); |
223 virtual void ReceiveSends(); | 228 virtual void ReceiveSends(); |
224 | 229 |
(...skipping 18 matching lines...) Expand all Loading... |
243 sigslot::signal0<> SignalQueueDestroyed; | 248 sigslot::signal0<> SignalQueueDestroyed; |
244 | 249 |
245 protected: | 250 protected: |
246 class PriorityQueue : public std::priority_queue<DelayedMessage> { | 251 class PriorityQueue : public std::priority_queue<DelayedMessage> { |
247 public: | 252 public: |
248 container_type& container() { return c; } | 253 container_type& container() { return c; } |
249 void reheap() { make_heap(c.begin(), c.end(), comp); } | 254 void reheap() { make_heap(c.begin(), c.end(), comp); } |
250 }; | 255 }; |
251 | 256 |
252 void DoDelayPost(int cmsDelay, | 257 void DoDelayPost(int cmsDelay, |
253 uint32_t tstamp, | 258 int64_t tstamp, |
254 MessageHandler* phandler, | 259 MessageHandler* phandler, |
255 uint32_t id, | 260 uint32_t id, |
256 MessageData* pdata); | 261 MessageData* pdata); |
257 | 262 |
258 // Perform initialization, subclasses must call this from their constructor | 263 // Perform initialization, subclasses must call this from their constructor |
259 // if false was passed as init_queue to the MessageQueue constructor. | 264 // if false was passed as init_queue to the MessageQueue constructor. |
260 void DoInit(); | 265 void DoInit(); |
261 | 266 |
262 // Perform cleanup, subclasses that override Clear must call this from the | 267 // Perform cleanup, subclasses that override Clear must call this from the |
263 // destructor. | 268 // destructor. |
(...skipping 17 matching lines...) Expand all Loading... |
281 // Used if SocketServer ownership lies with |this|. | 286 // Used if SocketServer ownership lies with |this|. |
282 std::unique_ptr<SocketServer> own_ss_; | 287 std::unique_ptr<SocketServer> own_ss_; |
283 SharedExclusiveLock ss_lock_; | 288 SharedExclusiveLock ss_lock_; |
284 | 289 |
285 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); | 290 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); |
286 }; | 291 }; |
287 | 292 |
288 } // namespace rtc | 293 } // namespace rtc |
289 | 294 |
290 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ | 295 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ |
OLD | NEW |