TaskQueueStdlib: initialize the thread last.

TaskQueueStdlib initialized it's thread too early which
permitted it to access uninitialized attributes.

Also remove the |stopped_| event which isn't needed because of
the platform thread being joinable.

Fixed: webrtc:12876
Change-Id: Ibd27ce915e0e3ac92ebafca535c5a3fd72f9165e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/223340
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34355}
This commit is contained in:
Markus Handell 2021-06-22 10:02:26 +02:00 committed by WebRTC LUCI CQ
parent 0fe60bd41a
commit 49cb459956

View file

@ -82,16 +82,9 @@ class TaskQueueStdlib final : public TaskQueueBase {
// Indicates if the thread has started.
rtc::Event started_;
// Indicates if the thread has stopped.
rtc::Event stopped_;
// Signaled whenever a new task is pending.
rtc::Event flag_notify_;
// Contains the active worker thread assigned to processing
// tasks (including delayed tasks).
rtc::PlatformThread thread_;
Mutex pending_lock_;
// Indicates if the worker thread needs to shutdown now.
@ -114,12 +107,17 @@ class TaskQueueStdlib final : public TaskQueueBase {
// std::unique_ptr out of the queue without the presence of a hack.
std::map<DelayedEntryTimeout, std::unique_ptr<QueuedTask>> delayed_queue_
RTC_GUARDED_BY(pending_lock_);
// Contains the active worker thread assigned to processing
// tasks (including delayed tasks).
// Placing this last ensures the thread doesn't touch uninitialized attributes
// throughout it's lifetime.
rtc::PlatformThread thread_;
};
TaskQueueStdlib::TaskQueueStdlib(absl::string_view queue_name,
rtc::ThreadPriority priority)
: started_(/*manual_reset=*/false, /*initially_signaled=*/false),
stopped_(/*manual_reset=*/false, /*initially_signaled=*/false),
flag_notify_(/*manual_reset=*/false, /*initially_signaled=*/false),
thread_(rtc::PlatformThread::SpawnJoinable(
[this] {
@ -141,8 +139,6 @@ void TaskQueueStdlib::Delete() {
NotifyWake();
stopped_.Wait(rtc::Event::kForever);
thread_.Finalize();
delete this;
}
@ -243,8 +239,6 @@ void TaskQueueStdlib::ProcessTasks() {
else
flag_notify_.Wait(task.sleep_time_ms_);
}
stopped_.Set();
}
void TaskQueueStdlib::NotifyWake() {