tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pending_task_safety_flag.cc (2328B)


      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 #include "absl/base/nullability.h"
     14 #include "api/scoped_refptr.h"
     15 #include "api/sequence_checker.h"
     16 #include "api/task_queue/task_queue_base.h"
     17 #include "rtc_base/checks.h"
     18 
     19 namespace webrtc {
     20 
     21 // static
     22 scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::CreateInternal(
     23    bool alive) {
     24  // Explicit new, to access private constructor.
     25  return scoped_refptr<PendingTaskSafetyFlag>(new PendingTaskSafetyFlag(alive));
     26 }
     27 
     28 // static
     29 scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::Create() {
     30  return CreateInternal(true);
     31 }
     32 
     33 scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::CreateDetached() {
     34  scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(true);
     35  safety_flag->main_sequence_.Detach();
     36  return safety_flag;
     37 }
     38 
     39 // Creates a flag, but with its SequenceChecker explicitly initialized for
     40 // a given task queue and the `alive()` flag specified.
     41 scoped_refptr<PendingTaskSafetyFlag>
     42 PendingTaskSafetyFlag::CreateAttachedToTaskQueue(bool alive,
     43                                                 TaskQueueBase* absl_nonnull
     44                                                     attached_queue) {
     45  RTC_DCHECK(attached_queue) << "Null TaskQueue provided";
     46  return scoped_refptr<PendingTaskSafetyFlag>(
     47      new PendingTaskSafetyFlag(alive, attached_queue));
     48 }
     49 
     50 scoped_refptr<PendingTaskSafetyFlag>
     51 PendingTaskSafetyFlag::CreateDetachedInactive() {
     52  scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(false);
     53  safety_flag->main_sequence_.Detach();
     54  return safety_flag;
     55 }
     56 
     57 void PendingTaskSafetyFlag::SetNotAlive() {
     58  RTC_DCHECK_RUN_ON(&main_sequence_);
     59  alive_ = false;
     60 }
     61 
     62 void PendingTaskSafetyFlag::SetAlive() {
     63  RTC_DCHECK_RUN_ON(&main_sequence_);
     64  alive_ = true;
     65 }
     66 
     67 bool PendingTaskSafetyFlag::alive() const {
     68  RTC_DCHECK_RUN_ON(&main_sequence_);
     69  return alive_;
     70 }
     71 
     72 }  // namespace webrtc