| OLD | NEW |
| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Never call Stop on the current thread. Instead use the inherited Quit | 144 // Never call Stop on the current thread. Instead use the inherited Quit |
| 145 // function which will exit the base MessageQueue without terminating the | 145 // function which will exit the base MessageQueue without terminating the |
| 146 // underlying OS thread. | 146 // underlying OS thread. |
| 147 virtual void Stop(); | 147 virtual void Stop(); |
| 148 | 148 |
| 149 // By default, Thread::Run() calls ProcessMessages(kForever). To do other | 149 // By default, Thread::Run() calls ProcessMessages(kForever). To do other |
| 150 // work, override Run(). To receive and dispatch messages, call | 150 // work, override Run(). To receive and dispatch messages, call |
| 151 // ProcessMessages occasionally. | 151 // ProcessMessages occasionally. |
| 152 virtual void Run(); | 152 virtual void Run(); |
| 153 | 153 |
| 154 virtual void Send(MessageHandler* phandler, | 154 virtual void Send(const Location& posted_from, |
| 155 MessageHandler* phandler, |
| 155 uint32_t id = 0, | 156 uint32_t id = 0, |
| 156 MessageData* pdata = NULL); | 157 MessageData* pdata = NULL); |
| 157 | 158 |
| 158 // Convenience method to invoke a functor on another thread. Caller must | 159 // Convenience method to invoke a functor on another thread. Caller must |
| 159 // provide the |ReturnT| template argument, which cannot (easily) be deduced. | 160 // provide the |ReturnT| template argument, which cannot (easily) be deduced. |
| 160 // Uses Send() internally, which blocks the current thread until execution | 161 // Uses Send() internally, which blocks the current thread until execution |
| 161 // is complete. | 162 // is complete. |
| 162 // Ex: bool result = thread.Invoke<bool>(&MyFunctionReturningBool); | 163 // Ex: bool result = thread.Invoke<bool>(RTC_FROM_HERE, |
| 164 // &MyFunctionReturningBool); |
| 163 // NOTE: This function can only be called when synchronous calls are allowed. | 165 // NOTE: This function can only be called when synchronous calls are allowed. |
| 164 // See ScopedDisallowBlockingCalls for details. | 166 // See ScopedDisallowBlockingCalls for details. |
| 165 template <class ReturnT, class FunctorT> | 167 template <class ReturnT, class FunctorT> |
| 166 ReturnT Invoke(const FunctorT& functor) { | 168 ReturnT Invoke(const Location& posted_from, const FunctorT& functor) { |
| 167 InvokeBegin(); | |
| 168 FunctorMessageHandler<ReturnT, FunctorT> handler(functor); | 169 FunctorMessageHandler<ReturnT, FunctorT> handler(functor); |
| 169 Send(&handler); | 170 InvokeInternal(posted_from, &handler); |
| 170 InvokeEnd(); | |
| 171 return handler.result(); | 171 return handler.result(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // From MessageQueue | 174 // From MessageQueue |
| 175 void Clear(MessageHandler* phandler, | 175 void Clear(MessageHandler* phandler, |
| 176 uint32_t id = MQID_ANY, | 176 uint32_t id = MQID_ANY, |
| 177 MessageList* removed = NULL) override; | 177 MessageList* removed = NULL) override; |
| 178 void ReceiveSends() override; | 178 void ReceiveSends() override; |
| 179 | 179 |
| 180 // ProcessMessages will process I/O and dispatch messages until: | 180 // ProcessMessages will process I/O and dispatch messages until: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // Processes received "Send" requests. If |source| is not NULL, only requests | 254 // Processes received "Send" requests. If |source| is not NULL, only requests |
| 255 // from |source| are processed, otherwise, all requests are processed. | 255 // from |source| are processed, otherwise, all requests are processed. |
| 256 void ReceiveSendsFromThread(const Thread* source); | 256 void ReceiveSendsFromThread(const Thread* source); |
| 257 | 257 |
| 258 // If |source| is not NULL, pops the first "Send" message from |source| in | 258 // If |source| is not NULL, pops the first "Send" message from |source| in |
| 259 // |sendlist_|, otherwise, pops the first "Send" message of |sendlist_|. | 259 // |sendlist_|, otherwise, pops the first "Send" message of |sendlist_|. |
| 260 // The caller must lock |crit_| before calling. | 260 // The caller must lock |crit_| before calling. |
| 261 // Returns true if there is such a message. | 261 // Returns true if there is such a message. |
| 262 bool PopSendMessageFromThread(const Thread* source, _SendMessage* msg); | 262 bool PopSendMessageFromThread(const Thread* source, _SendMessage* msg); |
| 263 | 263 |
| 264 // Used for tracking performance of Invoke calls. | 264 void InvokeInternal(const Location& posted_from, MessageHandler* handler); |
| 265 void InvokeBegin(); | |
| 266 void InvokeEnd(); | |
| 267 | 265 |
| 268 std::list<_SendMessage> sendlist_; | 266 std::list<_SendMessage> sendlist_; |
| 269 std::string name_; | 267 std::string name_; |
| 270 Event running_; // Signalled means running. | 268 Event running_; // Signalled means running. |
| 271 | 269 |
| 272 #if defined(WEBRTC_POSIX) | 270 #if defined(WEBRTC_POSIX) |
| 273 pthread_t thread_; | 271 pthread_t thread_; |
| 274 #endif | 272 #endif |
| 275 | 273 |
| 276 #if defined(WEBRTC_WIN) | 274 #if defined(WEBRTC_WIN) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 325 |
| 328 private: | 326 private: |
| 329 SocketServer* old_ss_; | 327 SocketServer* old_ss_; |
| 330 | 328 |
| 331 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); | 329 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); |
| 332 }; | 330 }; |
| 333 | 331 |
| 334 } // namespace rtc | 332 } // namespace rtc |
| 335 | 333 |
| 336 #endif // WEBRTC_BASE_THREAD_H_ | 334 #endif // WEBRTC_BASE_THREAD_H_ |
| OLD | NEW |