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

Side by Side Diff: third_party/libjingle/overrides/talk/base/messagequeue.cc

Issue 9455070: Remove the dependency to ws2_32.dll from talk_base::ThreadManager and talk_base::Thread. (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 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 * libjingle 2 * libjingle
3 * Copyright 2004--2005, Google Inc. 3 * Copyright 2004--2005, Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 16 matching lines...) Expand all
27 27
28 #if defined(_MSC_VER) && _MSC_VER < 1300 28 #if defined(_MSC_VER) && _MSC_VER < 1300
29 #pragma warning(disable:4786) 29 #pragma warning(disable:4786)
30 #endif 30 #endif
31 31
32 #ifdef POSIX 32 #ifdef POSIX
33 #include <sys/time.h> 33 #include <sys/time.h>
34 #endif 34 #endif
35 35
36 #include "talk/base/common.h" 36 #include "talk/base/common.h"
37 #include "talk/base/event.h"
37 #include "talk/base/logging.h" 38 #include "talk/base/logging.h"
38 #include "talk/base/messagequeue.h" 39 #include "talk/base/messagequeue.h"
39 #include "talk/base/physicalsocketserver.h" 40 #include "talk/base/physicalsocketserver.h"
40 41
41 42
42 namespace talk_base { 43 namespace talk_base {
43 44
44 const uint32 kMaxMsgLatency = 150; // 150 ms 45 const uint32 kMaxMsgLatency = 150; // 150 ms
45 46
46 //------------------------------------------------------------------ 47 //------------------------------------------------------------------
48 // NullSocketServer
49
50 class NullSocketServer : public SocketServer {
Sergey Ulanov 2012/02/28 21:54:02 should this be in an anonymous namespace?
Ronghua Wu (Left Chromium) 2012/02/28 23:16:57 Done.
51 public:
52 NullSocketServer() : event_(false, false) { }
53
54 virtual bool Wait(int cms, bool process_io) {
55 return event_.Wait(kForever);
56 }
57
58 virtual void WakeUp() {
59 event_.Set();
60 }
61
62 virtual Socket* CreateSocket(int type) {
63 return NULL;
64 }
65
66 // Returns a new socket for nonblocking communication. The type can be
67 // SOCK_DGRAM and/or SOCK_STREAM.
68 virtual AsyncSocket* CreateAsyncSocket(int type) {
69 return NULL;
70 }
71 private:
Sergey Ulanov 2012/02/28 21:54:02 nit: empty line before this one.
Ronghua Wu (Left Chromium) 2012/02/28 23:16:57 Done.
72 Event event_;
73 };
74
75 //------------------------------------------------------------------
47 // MessageQueueManager 76 // MessageQueueManager
48 77
49 MessageQueueManager* MessageQueueManager::instance_; 78 MessageQueueManager* MessageQueueManager::instance_;
50 79
51 MessageQueueManager* MessageQueueManager::Instance() { 80 MessageQueueManager* MessageQueueManager::Instance() {
52 // Note: This is not thread safe, but it is first called before threads are 81 // Note: This is not thread safe, but it is first called before threads are
53 // spawned. 82 // spawned.
54 if (!instance_) 83 if (!instance_)
55 instance_ = new MessageQueueManager; 84 instance_ = new MessageQueueManager;
56 return instance_; 85 return instance_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above. 127 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above.
99 CritScope cs(&crit_); 128 CritScope cs(&crit_);
100 std::vector<MessageQueue *>::iterator iter; 129 std::vector<MessageQueue *>::iterator iter;
101 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++) 130 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++)
102 (*iter)->Clear(handler); 131 (*iter)->Clear(handler);
103 } 132 }
104 133
105 //------------------------------------------------------------------ 134 //------------------------------------------------------------------
106 // MessageQueue 135 // MessageQueue
107 136
108 MessageQueue::MessageQueue(SocketServer* ss) 137 MessageQueue::MessageQueue() {
109 : ss_(ss), fStop_(false), fPeekKeep_(false), active_(false), 138 // TODO(ronghuawu):
110 dmsgq_next_num_(0) { 139 // Currently, MessageQueue holds a socket server, and is the base class for
111 if (!ss_) { 140 // Thread. It seems like it makes more sense for Thread to hold the socket
112 // Currently, MessageQueue holds a socket server, and is the base class for 141 // server, and provide it to the MessageQueue, since the Thread controls
113 // Thread. It seems like it makes more sense for Thread to hold the socket 142 // the I/O model, and MQ is agnostic to those details. Anyway, this causes
114 // server, and provide it to the MessageQueue, since the Thread controls 143 // messagequeue_unittest to depend on network libraries... yuck.
115 // the I/O model, and MQ is agnostic to those details. Anyway, this causes 144 default_ss_.reset(new PhysicalSocketServer());
116 // messagequeue_unittest to depend on network libraries... yuck. 145 Construct();
117 default_ss_.reset(new PhysicalSocketServer()); 146 }
118 ss_ = default_ss_.get(); 147
148 MessageQueue::MessageQueue(SocketServer* ss) {
149 if (!ss) {
150 default_ss_.reset(new NullSocketServer());
Sergey Ulanov 2012/02/28 21:54:02 here we lose |ss| if it is set.
Ronghua Wu (Left Chromium) 2012/02/28 23:16:57 Done.
119 } 151 }
152 Construct();
153 }
154
155 void MessageQueue::Construct() {
156 fStop_ = false;
157 fPeekKeep_ = false;
158 active_ = false;
159 dmsgq_next_num_ = 0;
160 ss_ = default_ss_.get();
120 ss_->SetMessageQueue(this); 161 ss_->SetMessageQueue(this);
121 } 162 }
122 163
123 MessageQueue::~MessageQueue() { 164 MessageQueue::~MessageQueue() {
124 // The signal is done from here to ensure 165 // The signal is done from here to ensure
125 // that it always gets called when the queue 166 // that it always gets called when the queue
126 // is going away. 167 // is going away.
127 SignalQueueDestroyed(); 168 SignalQueueDestroyed();
128 if (active_) { 169 if (active_) {
129 MessageQueueManager::Instance()->Remove(this); 170 MessageQueueManager::Instance()->Remove(this);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 415
375 void MessageQueue::EnsureActive() { 416 void MessageQueue::EnsureActive() {
376 ASSERT(crit_.CurrentThreadIsOwner()); 417 ASSERT(crit_.CurrentThreadIsOwner());
377 if (!active_) { 418 if (!active_) {
378 active_ = true; 419 active_ = true;
379 MessageQueueManager::Instance()->Add(this); 420 MessageQueueManager::Instance()->Add(this);
380 } 421 }
381 } 422 }
382 423
383 } // namespace talk_base 424 } // namespace talk_base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698