blob: 437ce0755d138a441cb47101de5e251b6cb8d3e7 [file] [log] [blame]
Tommi3c9bcc12020-04-15 16:45:47 +02001/*
2 * Copyright 2020 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Artem Titovc374d112022-06-16 21:27:45 +020011#include "api/task_queue/pending_task_safety_flag.h"
Tommi3c9bcc12020-04-15 16:45:47 +020012
Tommi3c9bcc12020-04-15 16:45:47 +020013namespace webrtc {
14
15// static
Niels Möller95129102022-01-13 11:00:05 +010016rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::CreateInternal(
17 bool alive) {
18 // Explicit new, to access private constructor.
19 return rtc::scoped_refptr<PendingTaskSafetyFlag>(
20 new PendingTaskSafetyFlag(alive));
21}
22
23// static
Tommia98cea82020-05-13 15:06:19 +020024rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::Create() {
Niels Möller95129102022-01-13 11:00:05 +010025 return CreateInternal(true);
Tommi3c9bcc12020-04-15 16:45:47 +020026}
27
Niels Möller2b250732021-03-19 09:45:43 +010028rtc::scoped_refptr<PendingTaskSafetyFlag>
29PendingTaskSafetyFlag::CreateDetached() {
Niels Möller95129102022-01-13 11:00:05 +010030 rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(true);
Tomas Gunnarsson25e73522021-04-19 10:14:10 +020031 safety_flag->main_sequence_.Detach();
32 return safety_flag;
33}
34
35rtc::scoped_refptr<PendingTaskSafetyFlag>
36PendingTaskSafetyFlag::CreateDetachedInactive() {
Niels Möller95129102022-01-13 11:00:05 +010037 rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(false);
Niels Möller2b250732021-03-19 09:45:43 +010038 safety_flag->main_sequence_.Detach();
39 return safety_flag;
40}
41
Tommi3c9bcc12020-04-15 16:45:47 +020042void PendingTaskSafetyFlag::SetNotAlive() {
43 RTC_DCHECK_RUN_ON(&main_sequence_);
44 alive_ = false;
45}
46
Niels Möllerbe140b42021-03-11 10:24:06 +010047void PendingTaskSafetyFlag::SetAlive() {
48 RTC_DCHECK_RUN_ON(&main_sequence_);
49 alive_ = true;
50}
51
Tommi3c9bcc12020-04-15 16:45:47 +020052bool PendingTaskSafetyFlag::alive() const {
53 RTC_DCHECK_RUN_ON(&main_sequence_);
54 return alive_;
55}
56
57} // namespace webrtc