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

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
42 namespace {
43 //------------------------------------------------------------------
44 // NullSocketServer
45
46 class NullSocketServer : public talk_base::SocketServer {
47 public:
48 NullSocketServer() : event_(false, false) {}
49
50 virtual bool Wait(int cms, bool process_io) {
51 return event_.Wait(talk_base::kForever);
52 }
53
54 virtual void WakeUp() {
55 event_.Set();
56 }
57
58 virtual talk_base::Socket* CreateSocket(int type) {
59 return NULL;
60 }
61
62 // Returns a new socket for nonblocking communication. The type can be
63 // SOCK_DGRAM and/or SOCK_STREAM.
64 virtual talk_base::AsyncSocket* CreateAsyncSocket(int type) {
65 return NULL;
66 }
67
68 private:
69 talk_base::Event event_;
70 };
71
72 }
Sergey Ulanov 2012/02/29 05:30:31 nit: // namespace
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
41 73
42 namespace talk_base { 74 namespace talk_base {
43 75
44 const uint32 kMaxMsgLatency = 150; // 150 ms 76 const uint32 kMaxMsgLatency = 150; // 150 ms
45 77
46 //------------------------------------------------------------------ 78 //------------------------------------------------------------------
47 // MessageQueueManager 79 // MessageQueueManager
48 80
49 MessageQueueManager* MessageQueueManager::instance_; 81 MessageQueueManager* MessageQueueManager::instance_;
50 82
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above. 130 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above.
99 CritScope cs(&crit_); 131 CritScope cs(&crit_);
100 std::vector<MessageQueue *>::iterator iter; 132 std::vector<MessageQueue *>::iterator iter;
101 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++) 133 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++)
102 (*iter)->Clear(handler); 134 (*iter)->Clear(handler);
103 } 135 }
104 136
105 //------------------------------------------------------------------ 137 //------------------------------------------------------------------
106 // MessageQueue 138 // MessageQueue
107 139
108 MessageQueue::MessageQueue(SocketServer* ss) 140 MessageQueue::MessageQueue() {
109 : ss_(ss), fStop_(false), fPeekKeep_(false), active_(false), 141 // TODO(ronghuawu):
110 dmsgq_next_num_(0) { 142 // Currently, MessageQueue holds a socket server, and is the base class for
111 if (!ss_) { 143 // 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 144 // 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 145 // 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 146 // messagequeue_unittest to depend on network libraries... yuck.
115 // the I/O model, and MQ is agnostic to those details. Anyway, this causes 147 owned_ss_.reset(new PhysicalSocketServer());
116 // messagequeue_unittest to depend on network libraries... yuck. 148 ss_ = owned_ss_.get();
117 default_ss_.reset(new PhysicalSocketServer()); 149 Construct();
118 ss_ = default_ss_.get(); 150 }
151
152 MessageQueue::MessageQueue(SocketServer* ss) {
153 if (ss) {
154 ss_ = ss;
155 } else {
156 owned_ss_.reset(new NullSocketServer());
157 ss_ = owned_ss_.get();
119 } 158 }
159 Construct();
160 }
161
162 void MessageQueue::Construct() {
163 fStop_ = false;
164 fPeekKeep_ = false;
165 active_ = false;
166 dmsgq_next_num_ = 0;
120 ss_->SetMessageQueue(this); 167 ss_->SetMessageQueue(this);
121 } 168 }
122 169
123 MessageQueue::~MessageQueue() { 170 MessageQueue::~MessageQueue() {
124 // The signal is done from here to ensure 171 // The signal is done from here to ensure
125 // that it always gets called when the queue 172 // that it always gets called when the queue
126 // is going away. 173 // is going away.
127 SignalQueueDestroyed(); 174 SignalQueueDestroyed();
128 if (active_) { 175 if (active_) {
129 MessageQueueManager::Instance()->Remove(this); 176 MessageQueueManager::Instance()->Remove(this);
130 Clear(NULL); 177 Clear(NULL);
131 } 178 }
132 if (ss_) { 179 if (ss_) {
133 ss_->SetMessageQueue(NULL); 180 ss_->SetMessageQueue(NULL);
134 } 181 }
135 } 182 }
136 183
137 void MessageQueue::set_socketserver(SocketServer* ss) { 184 void MessageQueue::set_socketserver(SocketServer* ss) {
138 ss_ = ss ? ss : default_ss_.get(); 185 ss_ = ss ? ss : owned_ss_.get();
139 ss_->SetMessageQueue(this); 186 ss_->SetMessageQueue(this);
140 } 187 }
141 188
142 void MessageQueue::Quit() { 189 void MessageQueue::Quit() {
143 fStop_ = true; 190 fStop_ = true;
144 ss_->WakeUp(); 191 ss_->WakeUp();
145 } 192 }
146 193
147 bool MessageQueue::IsQuitting() { 194 bool MessageQueue::IsQuitting() {
148 return fStop_; 195 return fStop_;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 421
375 void MessageQueue::EnsureActive() { 422 void MessageQueue::EnsureActive() {
376 ASSERT(crit_.CurrentThreadIsOwner()); 423 ASSERT(crit_.CurrentThreadIsOwner());
377 if (!active_) { 424 if (!active_) {
378 active_ = true; 425 active_ = true;
379 MessageQueueManager::Instance()->Add(this); 426 MessageQueueManager::Instance()->Add(this);
380 } 427 }
381 } 428 }
382 429
383 } // namespace talk_base 430 } // namespace talk_base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698