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

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

Issue 1891293002: Adds clearer function to create rtc::Thread without Physical SocketServer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: year Created 4 years, 8 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
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
11 #ifndef WEBRTC_BASE_MESSAGEQUEUE_H_ 11 #ifndef WEBRTC_BASE_MESSAGEQUEUE_H_
12 #define WEBRTC_BASE_MESSAGEQUEUE_H_ 12 #define WEBRTC_BASE_MESSAGEQUEUE_H_
13 13
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <list> 17 #include <list>
18 #include <queue> 18 #include <queue>
19 #include <vector> 19 #include <vector>
20 20
21 #include "webrtc/base/basictypes.h" 21 #include "webrtc/base/basictypes.h"
22 #include "webrtc/base/constructormagic.h" 22 #include "webrtc/base/constructormagic.h"
23 #include "webrtc/base/criticalsection.h" 23 #include "webrtc/base/criticalsection.h"
24 #include "webrtc/base/messagehandler.h" 24 #include "webrtc/base/messagehandler.h"
25 #include "webrtc/base/scoped_ptr.h"
26 #include "webrtc/base/scoped_ref_ptr.h" 25 #include "webrtc/base/scoped_ref_ptr.h"
27 #include "webrtc/base/sharedexclusivelock.h" 26 #include "webrtc/base/sharedexclusivelock.h"
28 #include "webrtc/base/sigslot.h" 27 #include "webrtc/base/sigslot.h"
29 #include "webrtc/base/socketserver.h" 28 #include "webrtc/base/socketserver.h"
30 #include "webrtc/base/timeutils.h" 29 #include "webrtc/base/timeutils.h"
31 #include "webrtc/base/thread_annotations.h" 30 #include "webrtc/base/thread_annotations.h"
32 31
33 namespace rtc { 32 namespace rtc {
34 33
35 struct Message; 34 struct Message;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 T& data() { return data_; } 81 T& data() { return data_; }
83 private: 82 private:
84 T data_; 83 T data_;
85 }; 84 };
86 85
87 // Like TypedMessageData, but for pointers that require a delete. 86 // Like TypedMessageData, but for pointers that require a delete.
88 template <class T> 87 template <class T>
89 class ScopedMessageData : public MessageData { 88 class ScopedMessageData : public MessageData {
90 public: 89 public:
91 explicit ScopedMessageData(T* data) : data_(data) { } 90 explicit ScopedMessageData(T* data) : data_(data) { }
92 const scoped_ptr<T>& data() const { return data_; } 91 const std::unique_ptr<T>& data() const { return data_; }
93 scoped_ptr<T>& data() { return data_; } 92 std::unique_ptr<T>& data() { return data_; }
93
94 private: 94 private:
95 scoped_ptr<T> data_; 95 std::unique_ptr<T> data_;
96 }; 96 };
97 97
98 // Like ScopedMessageData, but for reference counted pointers. 98 // Like ScopedMessageData, but for reference counted pointers.
99 template <class T> 99 template <class T>
100 class ScopedRefMessageData : public MessageData { 100 class ScopedRefMessageData : public MessageData {
101 public: 101 public:
102 explicit ScopedRefMessageData(T* data) : data_(data) { } 102 explicit ScopedRefMessageData(T* data) : data_(data) { }
103 const scoped_refptr<T>& data() const { return data_; } 103 const scoped_refptr<T>& data() const { return data_; }
104 scoped_refptr<T>& data() { return data_; } 104 scoped_refptr<T>& data() { return data_; }
105 private: 105 private:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 class MessageQueue { 168 class MessageQueue {
169 public: 169 public:
170 static const int kForever = -1; 170 static const int kForever = -1;
171 171
172 // Create a new MessageQueue and optionally assign it to the passed 172 // Create a new MessageQueue and optionally assign it to the passed
173 // SocketServer. Subclasses that override Clear should pass false for 173 // SocketServer. Subclasses that override Clear should pass false for
174 // init_queue and call DoInit() from their constructor to prevent races 174 // init_queue and call DoInit() from their constructor to prevent races
175 // with the MessageQueueManager using the object while the vtable is still 175 // with the MessageQueueManager using the object while the vtable is still
176 // being created. 176 // being created.
177 explicit MessageQueue(SocketServer* ss = NULL, 177 MessageQueue(SocketServer* ss, bool init_queue);
178 bool init_queue = true); 178 MessageQueue(std::unique_ptr<SocketServer> ss, bool init_queue);
179 179
180 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL 180 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL
181 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race 181 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race
182 // between the destructor modifying the vtable, and the MessageQueueManager 182 // between the destructor modifying the vtable, and the MessageQueueManager
183 // calling Clear on the object from a different thread. 183 // calling Clear on the object from a different thread.
184 virtual ~MessageQueue(); 184 virtual ~MessageQueue();
185 185
186 SocketServer* socketserver(); 186 SocketServer* socketserver();
187 void set_socketserver(SocketServer* ss); 187 void set_socketserver(SocketServer* ss);
188 188
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 MessageList msgq_ GUARDED_BY(crit_); 270 MessageList msgq_ GUARDED_BY(crit_);
271 PriorityQueue dmsgq_ GUARDED_BY(crit_); 271 PriorityQueue dmsgq_ GUARDED_BY(crit_);
272 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); 272 uint32_t dmsgq_next_num_ GUARDED_BY(crit_);
273 CriticalSection crit_; 273 CriticalSection crit_;
274 bool fInitialized_; 274 bool fInitialized_;
275 bool fDestroyed_; 275 bool fDestroyed_;
276 276
277 private: 277 private:
278 // The SocketServer is not owned by MessageQueue. 278 // The SocketServer is not owned by MessageQueue.
279 SocketServer* ss_ GUARDED_BY(ss_lock_); 279 SocketServer* ss_ GUARDED_BY(ss_lock_);
280 // If a server isn't supplied in the constructor, use this one. 280 // If caller pass socketserver with ownship.
stefan-webrtc 2016/04/19 08:29:33 s/ownship/ownership
danilchap 2016/04/19 09:43:09 Done.
281 scoped_ptr<SocketServer> default_ss_; 281 std::unique_ptr<SocketServer> own_ss_;
282 SharedExclusiveLock ss_lock_; 282 SharedExclusiveLock ss_lock_;
283 283
284 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); 284 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue);
285 }; 285 };
286 286
287 } // namespace rtc 287 } // namespace rtc
288 288
289 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ 289 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_
OLDNEW
« no previous file with comments | « webrtc/base/base.gyp ('k') | webrtc/base/messagequeue.cc » ('j') | webrtc/base/messagequeue.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698