Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: webrtc/base/messagequeue.h

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/messagedigest.cc ('k') | webrtc/base/messagequeue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 template<class T> 117 template<class T>
118 class DisposeData : public MessageData { 118 class DisposeData : public MessageData {
119 public: 119 public:
120 explicit DisposeData(T* data) : data_(data) { } 120 explicit DisposeData(T* data) : data_(data) { }
121 virtual ~DisposeData() { delete data_; } 121 virtual ~DisposeData() { delete data_; }
122 private: 122 private:
123 T* data_; 123 T* data_;
124 }; 124 };
125 125
126 const uint32 MQID_ANY = static_cast<uint32>(-1); 126 const uint32_t MQID_ANY = static_cast<uint32_t>(-1);
127 const uint32 MQID_DISPOSE = static_cast<uint32>(-2); 127 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2);
128 128
129 // No destructor 129 // No destructor
130 130
131 struct Message { 131 struct Message {
132 Message() { 132 Message() {
133 memset(this, 0, sizeof(*this)); 133 memset(this, 0, sizeof(*this));
134 } 134 }
135 inline bool Match(MessageHandler* handler, uint32 id) const { 135 inline bool Match(MessageHandler* handler, uint32_t id) const {
136 return (handler == NULL || handler == phandler) 136 return (handler == NULL || handler == phandler)
137 && (id == MQID_ANY || id == message_id); 137 && (id == MQID_ANY || id == message_id);
138 } 138 }
139 MessageHandler *phandler; 139 MessageHandler *phandler;
140 uint32 message_id; 140 uint32_t message_id;
141 MessageData *pdata; 141 MessageData *pdata;
142 uint32 ts_sensitive; 142 uint32_t ts_sensitive;
143 }; 143 };
144 144
145 typedef std::list<Message> MessageList; 145 typedef std::list<Message> MessageList;
146 146
147 // DelayedMessage goes into a priority queue, sorted by trigger time. Messages 147 // DelayedMessage goes into a priority queue, sorted by trigger time. Messages
148 // with the same trigger time are processed in num_ (FIFO) order. 148 // with the same trigger time are processed in num_ (FIFO) order.
149 149
150 class DelayedMessage { 150 class DelayedMessage {
151 public: 151 public:
152 DelayedMessage(int delay, uint32 trigger, uint32 num, const Message& msg) 152 DelayedMessage(int delay, uint32_t trigger, uint32_t num, const Message& msg)
153 : cmsDelay_(delay), msTrigger_(trigger), num_(num), msg_(msg) { } 153 : cmsDelay_(delay), msTrigger_(trigger), num_(num), msg_(msg) {}
154 154
155 bool operator< (const DelayedMessage& dmsg) const { 155 bool operator< (const DelayedMessage& dmsg) const {
156 return (dmsg.msTrigger_ < msTrigger_) 156 return (dmsg.msTrigger_ < msTrigger_)
157 || ((dmsg.msTrigger_ == msTrigger_) && (dmsg.num_ < num_)); 157 || ((dmsg.msTrigger_ == msTrigger_) && (dmsg.num_ < num_));
158 } 158 }
159 159
160 int cmsDelay_; // for debugging 160 int cmsDelay_; // for debugging
161 uint32 msTrigger_; 161 uint32_t msTrigger_;
162 uint32 num_; 162 uint32_t num_;
163 Message msg_; 163 Message msg_;
164 }; 164 };
165 165
166 class MessageQueue { 166 class MessageQueue {
167 public: 167 public:
168 static const int kForever = -1; 168 static const int kForever = -1;
169 169
170 explicit MessageQueue(SocketServer* ss = NULL); 170 explicit MessageQueue(SocketServer* ss = NULL);
171 virtual ~MessageQueue(); 171 virtual ~MessageQueue();
172 172
(...skipping 10 matching lines...) Expand all
183 virtual bool IsQuitting(); 183 virtual bool IsQuitting();
184 virtual void Restart(); 184 virtual void Restart();
185 185
186 // Get() will process I/O until: 186 // Get() will process I/O until:
187 // 1) A message is available (returns true) 187 // 1) A message is available (returns true)
188 // 2) cmsWait seconds have elapsed (returns false) 188 // 2) cmsWait seconds have elapsed (returns false)
189 // 3) Stop() is called (returns false) 189 // 3) Stop() is called (returns false)
190 virtual bool Get(Message *pmsg, int cmsWait = kForever, 190 virtual bool Get(Message *pmsg, int cmsWait = kForever,
191 bool process_io = true); 191 bool process_io = true);
192 virtual bool Peek(Message *pmsg, int cmsWait = 0); 192 virtual bool Peek(Message *pmsg, int cmsWait = 0);
193 virtual void Post(MessageHandler *phandler, uint32 id = 0, 193 virtual void Post(MessageHandler* phandler,
194 MessageData *pdata = NULL, bool time_sensitive = false); 194 uint32_t id = 0,
195 MessageData* pdata = NULL,
196 bool time_sensitive = false);
195 virtual void PostDelayed(int cmsDelay, 197 virtual void PostDelayed(int cmsDelay,
196 MessageHandler* phandler, 198 MessageHandler* phandler,
197 uint32 id = 0, 199 uint32_t id = 0,
198 MessageData* pdata = NULL); 200 MessageData* pdata = NULL);
199 virtual void PostAt(uint32 tstamp, 201 virtual void PostAt(uint32_t tstamp,
200 MessageHandler* phandler, 202 MessageHandler* phandler,
201 uint32 id = 0, 203 uint32_t id = 0,
202 MessageData* pdata = NULL); 204 MessageData* pdata = NULL);
203 virtual void Clear(MessageHandler *phandler, uint32 id = MQID_ANY, 205 virtual void Clear(MessageHandler* phandler,
206 uint32_t id = MQID_ANY,
204 MessageList* removed = NULL); 207 MessageList* removed = NULL);
205 virtual void Dispatch(Message *pmsg); 208 virtual void Dispatch(Message *pmsg);
206 virtual void ReceiveSends(); 209 virtual void ReceiveSends();
207 210
208 // Amount of time until the next message can be retrieved 211 // Amount of time until the next message can be retrieved
209 virtual int GetDelay(); 212 virtual int GetDelay();
210 213
211 bool empty() const { return size() == 0u; } 214 bool empty() const { return size() == 0u; }
212 size_t size() const { 215 size_t size() const {
213 CritScope cs(&crit_); // msgq_.size() is not thread safe. 216 CritScope cs(&crit_); // msgq_.size() is not thread safe.
(...skipping 11 matching lines...) Expand all
225 // no longer be used. 228 // no longer be used.
226 sigslot::signal0<> SignalQueueDestroyed; 229 sigslot::signal0<> SignalQueueDestroyed;
227 230
228 protected: 231 protected:
229 class PriorityQueue : public std::priority_queue<DelayedMessage> { 232 class PriorityQueue : public std::priority_queue<DelayedMessage> {
230 public: 233 public:
231 container_type& container() { return c; } 234 container_type& container() { return c; }
232 void reheap() { make_heap(c.begin(), c.end(), comp); } 235 void reheap() { make_heap(c.begin(), c.end(), comp); }
233 }; 236 };
234 237
235 void DoDelayPost(int cmsDelay, uint32 tstamp, MessageHandler *phandler, 238 void DoDelayPost(int cmsDelay,
236 uint32 id, MessageData* pdata); 239 uint32_t tstamp,
240 MessageHandler* phandler,
241 uint32_t id,
242 MessageData* pdata);
237 243
238 // The SocketServer is not owned by MessageQueue. 244 // The SocketServer is not owned by MessageQueue.
239 SocketServer* ss_; 245 SocketServer* ss_;
240 // If a server isn't supplied in the constructor, use this one. 246 // If a server isn't supplied in the constructor, use this one.
241 scoped_ptr<SocketServer> default_ss_; 247 scoped_ptr<SocketServer> default_ss_;
242 bool fStop_; 248 bool fStop_;
243 bool fPeekKeep_; 249 bool fPeekKeep_;
244 Message msgPeek_; 250 Message msgPeek_;
245 MessageList msgq_; 251 MessageList msgq_;
246 PriorityQueue dmsgq_; 252 PriorityQueue dmsgq_;
247 uint32 dmsgq_next_num_; 253 uint32_t dmsgq_next_num_;
248 mutable CriticalSection crit_; 254 mutable CriticalSection crit_;
249 255
250 private: 256 private:
251 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); 257 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue);
252 }; 258 };
253 259
254 } // namespace rtc 260 } // namespace rtc
255 261
256 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ 262 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_
OLDNEW
« no previous file with comments | « webrtc/base/messagedigest.cc ('k') | webrtc/base/messagequeue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698