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

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

Issue 2708723003: Introduce new constructor to PlatformThread. (Closed)
Patch Set: Update IncomingVideoStream again Created 3 years, 10 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 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 14 matching lines...) Expand all
25 25
26 // Compares two thread identifiers for equality. 26 // Compares two thread identifiers for equality.
27 bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b); 27 bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b);
28 28
29 // Sets the current thread name. 29 // Sets the current thread name.
30 void SetCurrentThreadName(const char* name); 30 void SetCurrentThreadName(const char* name);
31 31
32 // Callback function that the spawned thread will enter once spawned. 32 // Callback function that the spawned thread will enter once spawned.
33 // A return value of false is interpreted as that the function has no 33 // A return value of false is interpreted as that the function has no
34 // more work to do and that the thread can be released. 34 // more work to do and that the thread can be released.
35 typedef bool (*ThreadRunFunction)(void*); 35 typedef bool (*ThreadRunFunctionDeprecated)(void*);
36 typedef void (*ThreadRunFunction)(void*);
36 37
37 enum ThreadPriority { 38 enum ThreadPriority {
38 #ifdef WEBRTC_WIN 39 #ifdef WEBRTC_WIN
39 kLowPriority = THREAD_PRIORITY_BELOW_NORMAL, 40 kLowPriority = THREAD_PRIORITY_BELOW_NORMAL,
40 kNormalPriority = THREAD_PRIORITY_NORMAL, 41 kNormalPriority = THREAD_PRIORITY_NORMAL,
41 kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL, 42 kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL,
42 kHighestPriority = THREAD_PRIORITY_HIGHEST, 43 kHighestPriority = THREAD_PRIORITY_HIGHEST,
43 kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL 44 kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL
44 #else 45 #else
45 kLowPriority = 1, 46 kLowPriority = 1,
46 kNormalPriority = 2, 47 kNormalPriority = 2,
47 kHighPriority = 3, 48 kHighPriority = 3,
48 kHighestPriority = 4, 49 kHighestPriority = 4,
49 kRealtimePriority = 5 50 kRealtimePriority = 5
50 #endif 51 #endif
51 }; 52 };
52 53
53 // Represents a simple worker thread. The implementation must be assumed 54 // Represents a simple worker thread. The implementation must be assumed
54 // to be single threaded, meaning that all methods of the class, must be 55 // to be single threaded, meaning that all methods of the class, must be
55 // called from the same thread, including instantiation. 56 // called from the same thread, including instantiation.
56 class PlatformThread { 57 class PlatformThread {
57 public: 58 public:
58 PlatformThread(ThreadRunFunction func, void* obj, const char* thread_name); 59 PlatformThread(ThreadRunFunctionDeprecated func,
60 void* obj,
61 const char* thread_name);
62 PlatformThread(ThreadRunFunction func,
63 void* obj,
64 const char* thread_name,
65 ThreadPriority priority = kNormalPriority);
59 virtual ~PlatformThread(); 66 virtual ~PlatformThread();
60 67
61 const std::string& name() const { return name_; } 68 const std::string& name() const { return name_; }
62 69
63 // Spawns a thread and tries to set thread priority according to the priority 70 // Spawns a thread and tries to set thread priority according to the priority
64 // from when CreateThread was called. 71 // from when CreateThread was called.
65 void Start(); 72 void Start();
66 73
67 bool IsRunning() const; 74 bool IsRunning() const;
68 75
69 // Returns an identifier for the worker thread that can be used to do 76 // Returns an identifier for the worker thread that can be used to do
70 // thread checks. 77 // thread checks.
71 PlatformThreadRef GetThreadRef() const; 78 PlatformThreadRef GetThreadRef() const;
72 79
73 // Stops (joins) the spawned thread. 80 // Stops (joins) the spawned thread.
74 void Stop(); 81 void Stop();
75 82
76 // Set the priority of the thread. Must be called when thread is running. 83 // Set the priority of the thread. Must be called when thread is running.
84 // TODO(tommi): Make private and only allow public support via ctor.
77 bool SetPriority(ThreadPriority priority); 85 bool SetPriority(ThreadPriority priority);
78 86
79 protected: 87 protected:
80 #if defined(WEBRTC_WIN) 88 #if defined(WEBRTC_WIN)
81 // Exposed to derived classes to allow for special cases specific to Windows. 89 // Exposed to derived classes to allow for special cases specific to Windows.
82 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data); 90 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data);
83 #endif 91 #endif
84 92
85 private: 93 private:
86 void Run(); 94 void Run();
87 95
88 ThreadRunFunction const run_function_; 96 ThreadRunFunctionDeprecated const run_function_deprecated_ = nullptr;
97 ThreadRunFunction const run_function_ = nullptr;
98 const ThreadPriority priority_ = kNormalPriority;
89 void* const obj_; 99 void* const obj_;
90 // TODO(pbos): Make sure call sites use string literals and update to a const 100 // TODO(pbos): Make sure call sites use string literals and update to a const
91 // char* instead of a std::string. 101 // char* instead of a std::string.
92 const std::string name_; 102 const std::string name_;
93 rtc::ThreadChecker thread_checker_; 103 rtc::ThreadChecker thread_checker_;
104 rtc::ThreadChecker worker_thread_checker_;
the sun 2017/02/22 13:42:57 <bikeshed> "worker_thread..." makes me associate i
tommi 2017/02/22 15:04:00 Done. (went with spawned_thread_checker_)
94 #if defined(WEBRTC_WIN) 105 #if defined(WEBRTC_WIN)
95 static DWORD WINAPI StartThread(void* param); 106 static DWORD WINAPI StartThread(void* param);
96 107
97 bool stop_ = false; 108 bool stop_ = false;
98 HANDLE thread_ = nullptr; 109 HANDLE thread_ = nullptr;
99 DWORD thread_id_ = 0; 110 DWORD thread_id_ = 0;
100 #else 111 #else
101 static void* StartThread(void* param); 112 static void* StartThread(void* param);
102 113
103 // An atomic flag that we use to stop the thread. Only modified on the 114 // An atomic flag that we use to stop the thread. Only modified on the
104 // controlling thread and checked on the worker thread. 115 // controlling thread and checked on the worker thread.
105 volatile int stop_flag_ = 0; 116 volatile int stop_flag_ = 0;
106 pthread_t thread_ = 0; 117 pthread_t thread_ = 0;
107 #endif // defined(WEBRTC_WIN) 118 #endif // defined(WEBRTC_WIN)
108 RTC_DISALLOW_COPY_AND_ASSIGN(PlatformThread); 119 RTC_DISALLOW_COPY_AND_ASSIGN(PlatformThread);
109 }; 120 };
110 121
111 } // namespace rtc 122 } // namespace rtc
112 123
113 #endif // WEBRTC_BASE_PLATFORM_THREAD_H_ 124 #endif // WEBRTC_BASE_PLATFORM_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698