Tommi | 3c9bcc1 | 2020-04-15 16:45:47 +0200 | [diff] [blame] | 1 | /* |
| 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 Titov | c374d11 | 2022-06-16 21:27:45 +0200 | [diff] [blame] | 11 | #include "api/task_queue/pending_task_safety_flag.h" |
Tommi | 3c9bcc1 | 2020-04-15 16:45:47 +0200 | [diff] [blame] | 12 | |
Tommi | 3c9bcc1 | 2020-04-15 16:45:47 +0200 | [diff] [blame] | 13 | namespace webrtc { |
| 14 | |
| 15 | // static |
Niels Möller | 9512910 | 2022-01-13 11:00:05 +0100 | [diff] [blame] | 16 | rtc::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 |
Tommi | a98cea8 | 2020-05-13 15:06:19 +0200 | [diff] [blame] | 24 | rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::Create() { |
Niels Möller | 9512910 | 2022-01-13 11:00:05 +0100 | [diff] [blame] | 25 | return CreateInternal(true); |
Tommi | 3c9bcc1 | 2020-04-15 16:45:47 +0200 | [diff] [blame] | 26 | } |
| 27 | |
Niels Möller | 2b25073 | 2021-03-19 09:45:43 +0100 | [diff] [blame] | 28 | rtc::scoped_refptr<PendingTaskSafetyFlag> |
| 29 | PendingTaskSafetyFlag::CreateDetached() { |
Niels Möller | 9512910 | 2022-01-13 11:00:05 +0100 | [diff] [blame] | 30 | rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(true); |
Tomas Gunnarsson | 25e7352 | 2021-04-19 10:14:10 +0200 | [diff] [blame] | 31 | safety_flag->main_sequence_.Detach(); |
| 32 | return safety_flag; |
| 33 | } |
| 34 | |
| 35 | rtc::scoped_refptr<PendingTaskSafetyFlag> |
| 36 | PendingTaskSafetyFlag::CreateDetachedInactive() { |
Niels Möller | 9512910 | 2022-01-13 11:00:05 +0100 | [diff] [blame] | 37 | rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(false); |
Niels Möller | 2b25073 | 2021-03-19 09:45:43 +0100 | [diff] [blame] | 38 | safety_flag->main_sequence_.Detach(); |
| 39 | return safety_flag; |
| 40 | } |
| 41 | |
Tommi | 3c9bcc1 | 2020-04-15 16:45:47 +0200 | [diff] [blame] | 42 | void PendingTaskSafetyFlag::SetNotAlive() { |
| 43 | RTC_DCHECK_RUN_ON(&main_sequence_); |
| 44 | alive_ = false; |
| 45 | } |
| 46 | |
Niels Möller | be140b4 | 2021-03-11 10:24:06 +0100 | [diff] [blame] | 47 | void PendingTaskSafetyFlag::SetAlive() { |
| 48 | RTC_DCHECK_RUN_ON(&main_sequence_); |
| 49 | alive_ = true; |
| 50 | } |
| 51 | |
Tommi | 3c9bcc1 | 2020-04-15 16:45:47 +0200 | [diff] [blame] | 52 | bool PendingTaskSafetyFlag::alive() const { |
| 53 | RTC_DCHECK_RUN_ON(&main_sequence_); |
| 54 | return alive_; |
| 55 | } |
| 56 | |
| 57 | } // namespace webrtc |