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

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

Issue 2164333002: Use NullSocketServer instead of PhysicalSocketServer in SignalThread (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: useSocketServer -> use_socket_server Created 4 years, 4 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
« no previous file with comments | « webrtc/base/nethelpers.cc ('k') | webrtc/base/signalthread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_SIGNALTHREAD_H_ 11 #ifndef WEBRTC_BASE_SIGNALTHREAD_H_
12 #define WEBRTC_BASE_SIGNALTHREAD_H_ 12 #define WEBRTC_BASE_SIGNALTHREAD_H_
13 13
14 #include <string> 14 #include <string>
15 15
16 #include "webrtc/base/constructormagic.h" 16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/base/nullsocketserver.h"
17 #include "webrtc/base/sigslot.h" 18 #include "webrtc/base/sigslot.h"
18 #include "webrtc/base/thread.h" 19 #include "webrtc/base/thread.h"
19 20
20 namespace rtc { 21 namespace rtc {
21 22
22 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
23 // SignalThread - Base class for worker threads. The main thread should call 24 // SignalThread - Base class for worker threads. The main thread should call
24 // Start() to begin work, and then follow one of these models: 25 // Start() to begin work, and then follow one of these models:
25 // Normal: Wait for SignalWorkDone, and then call Release to destroy. 26 // Normal: Wait for SignalWorkDone, and then call Release to destroy.
26 // Cancellation: Call Release(true), to abort the worker thread. 27 // Cancellation: Call Release(true), to abort the worker thread.
27 // Fire-and-forget: Call Release(false), which allows the thread to run to 28 // Fire-and-forget: Call Release(false), which allows the thread to run to
28 // completion, and then self-destruct without further notification. 29 // completion, and then self-destruct without further notification.
29 // Periodic tasks: Wait for SignalWorkDone, then eventually call Start() 30 // Periodic tasks: Wait for SignalWorkDone, then eventually call Start()
30 // again to repeat the task. When the instance isn't needed anymore, 31 // again to repeat the task. When the instance isn't needed anymore,
31 // call Release. DoWork, OnWorkStart and OnWorkStop are called again, 32 // call Release. DoWork, OnWorkStart and OnWorkStop are called again,
32 // on a new thread. 33 // on a new thread.
33 // The subclass should override DoWork() to perform the background task. By 34 // The subclass should override DoWork() to perform the background task. By
34 // periodically calling ContinueWork(), it can check for cancellation. 35 // periodically calling ContinueWork(), it can check for cancellation.
35 // OnWorkStart and OnWorkDone can be overridden to do pre- or post-work 36 // OnWorkStart and OnWorkDone can be overridden to do pre- or post-work
36 // tasks in the context of the main thread. 37 // tasks in the context of the main thread.
37 /////////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////////
38 39
39 class SignalThread 40 class SignalThread
40 : public sigslot::has_slots<>, 41 : public sigslot::has_slots<>,
41 protected MessageHandler { 42 protected MessageHandler {
42 public: 43 public:
43 SignalThread(); 44 explicit SignalThread(bool use_socket_server = true);
44 45
45 // Context: Main Thread. Call before Start to change the worker's name. 46 // Context: Main Thread. Call before Start to change the worker's name.
46 bool SetName(const std::string& name, const void* obj); 47 bool SetName(const std::string& name, const void* obj);
47 48
48 // Context: Main Thread. Call to begin the worker thread. 49 // Context: Main Thread. Call to begin the worker thread.
49 void Start(); 50 void Start();
50 51
51 // Context: Main Thread. If the worker thread is not running, deletes the 52 // Context: Main Thread. If the worker thread is not running, deletes the
52 // object immediately. Otherwise, asks the worker thread to abort processing, 53 // object immediately. Otherwise, asks the worker thread to abort processing,
53 // and schedules the object to be deleted once the worker exits. 54 // and schedules the object to be deleted once the worker exits.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 enum State { 96 enum State {
96 kInit, // Initialized, but not started 97 kInit, // Initialized, but not started
97 kRunning, // Started and doing work 98 kRunning, // Started and doing work
98 kReleasing, // Same as running, but to be deleted when work is done 99 kReleasing, // Same as running, but to be deleted when work is done
99 kComplete, // Work is done 100 kComplete, // Work is done
100 kStopping, // Work is being interrupted 101 kStopping, // Work is being interrupted
101 }; 102 };
102 103
103 class Worker : public Thread { 104 class Worker : public Thread {
104 public: 105 public:
105 explicit Worker(SignalThread* parent) : parent_(parent) {} 106 explicit Worker(SignalThread* parent, bool use_socket_server)
107 : Thread(use_socket_server
108 ? SocketServer::CreateDefault()
109 : std::unique_ptr<SocketServer>(new NullSocketServer())),
110 parent_(parent) {}
106 ~Worker() override; 111 ~Worker() override;
107 void Run() override; 112 void Run() override;
108 113
109 private: 114 private:
110 SignalThread* parent_; 115 SignalThread* parent_;
111 116
112 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Worker); 117 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Worker);
113 }; 118 };
114 119
115 class SCOPED_LOCKABLE EnterExit { 120 class SCOPED_LOCKABLE EnterExit {
(...skipping 29 matching lines...) Expand all
145 int refcount_; 150 int refcount_;
146 151
147 RTC_DISALLOW_COPY_AND_ASSIGN(SignalThread); 152 RTC_DISALLOW_COPY_AND_ASSIGN(SignalThread);
148 }; 153 };
149 154
150 /////////////////////////////////////////////////////////////////////////////// 155 ///////////////////////////////////////////////////////////////////////////////
151 156
152 } // namespace rtc 157 } // namespace rtc
153 158
154 #endif // WEBRTC_BASE_SIGNALTHREAD_H_ 159 #endif // WEBRTC_BASE_SIGNALTHREAD_H_
OLDNEW
« no previous file with comments | « webrtc/base/nethelpers.cc ('k') | webrtc/base/signalthread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698