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

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 }
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 default_ss_.reset(new PhysicalSocketServer());
Sergey Ulanov 2012/02/29 00:09:52 please rename default_ss_ to owned_ss_ and set ss_
Ronghua Wu (Left Chromium) 2012/02/29 04:31:22 Done.
116 // messagequeue_unittest to depend on network libraries... yuck. 148 Construct();
117 default_ss_.reset(new PhysicalSocketServer()); 149 }
118 ss_ = default_ss_.get(); 150
119 } 151 MessageQueue::MessageQueue(SocketServer* ss) {
152 default_ss_.reset(ss ? ss : (new NullSocketServer()));
Sergey Ulanov 2012/02/29 00:09:52 Does this mean we always own the socket server obj
Ronghua Wu (Left Chromium) 2012/02/29 04:31:22 Fixed, my mistake.
153 Construct();
154 }
155
156 void MessageQueue::Construct() {
157 fStop_ = false;
158 fPeekKeep_ = false;
159 active_ = false;
160 dmsgq_next_num_ = 0;
161 ss_ = default_ss_.get();
120 ss_->SetMessageQueue(this); 162 ss_->SetMessageQueue(this);
121 } 163 }
122 164
123 MessageQueue::~MessageQueue() { 165 MessageQueue::~MessageQueue() {
124 // The signal is done from here to ensure 166 // The signal is done from here to ensure
125 // that it always gets called when the queue 167 // that it always gets called when the queue
126 // is going away. 168 // is going away.
127 SignalQueueDestroyed(); 169 SignalQueueDestroyed();
128 if (active_) { 170 if (active_) {
129 MessageQueueManager::Instance()->Remove(this); 171 MessageQueueManager::Instance()->Remove(this);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 416
375 void MessageQueue::EnsureActive() { 417 void MessageQueue::EnsureActive() {
376 ASSERT(crit_.CurrentThreadIsOwner()); 418 ASSERT(crit_.CurrentThreadIsOwner());
377 if (!active_) { 419 if (!active_) {
378 active_ = true; 420 active_ = true;
379 MessageQueueManager::Instance()->Add(this); 421 MessageQueueManager::Instance()->Add(this);
380 } 422 }
381 } 423 }
382 424
383 } // namespace talk_base 425 } // namespace talk_base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698