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 11 #include "api/task_queue/pending_task_safety_flag.h" 12 13 namespace webrtc { 14 15 // static CreateInternal(bool alive)16rtc::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 Create()24rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::Create() { 25 return CreateInternal(true); 26 } 27 28 rtc::scoped_refptr<PendingTaskSafetyFlag> CreateDetached()29PendingTaskSafetyFlag::CreateDetached() { 30 rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(true); 31 safety_flag->main_sequence_.Detach(); 32 return safety_flag; 33 } 34 35 rtc::scoped_refptr<PendingTaskSafetyFlag> CreateDetachedInactive()36PendingTaskSafetyFlag::CreateDetachedInactive() { 37 rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(false); 38 safety_flag->main_sequence_.Detach(); 39 return safety_flag; 40 } 41 SetNotAlive()42void PendingTaskSafetyFlag::SetNotAlive() { 43 RTC_DCHECK_RUN_ON(&main_sequence_); 44 alive_ = false; 45 } 46 SetAlive()47void PendingTaskSafetyFlag::SetAlive() { 48 RTC_DCHECK_RUN_ON(&main_sequence_); 49 alive_ = true; 50 } 51 alive() const52bool PendingTaskSafetyFlag::alive() const { 53 RTC_DCHECK_RUN_ON(&main_sequence_); 54 return alive_; 55 } 56 57 } // namespace webrtc 58