webrtc/rtc_base/weak_ptr.cc
Philipp Hancke 213119e51e Apply clang-tidy readability-redundant-smartptr-get
https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-smartptr-get.html
and
https://clang.llvm.org/extra/clang-tidy/checks/readability/named-parameter.html (which resulted only in a single change)

Done using
  tools/clang/scripts/build_clang_tools_extra.py \
    --fetch out/Default clang-tidy clang-apply-replacements
  ninja -C out/Default
  gn gen out/Default --export-compile-commands
  cd out/Default
  tools/clang/third_party/llvm/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -p . \
    -clang-tidy-binary tools/clang/third_party/llvm/build/bin/clang-tidy \
    -clang-apply-replacements-binary \
        tools/clang/third_party/llvm/build/bin/clang-apply-replacements \
    -checks='-*,readability-redundant-smartptr-get,readability-named-parameter' \
    -fix
followed by
  git cl format

Bug: webrtc:424706384
Change-Id: Ie5a4077286d34c1363a1d341aca50a7047f6543b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/402584
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@meta.com>
Cr-Commit-Position: refs/heads/main@{#45247}
2025-07-31 01:37:54 -07:00

74 lines
1.8 KiB
C++

/*
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/weak_ptr.h"
#include "api/sequence_checker.h"
// The implementation is borrowed from chromium except that it does not
// implement SupportsWeakPtr.
namespace webrtc {
namespace internal {
void WeakReference::Flag::Invalidate() {
RTC_DCHECK_RUN_ON(&checker_);
is_valid_ = false;
}
bool WeakReference::Flag::IsValid() const {
RTC_DCHECK_RUN_ON(&checker_);
return is_valid_;
}
WeakReference::WeakReference() {}
WeakReference::WeakReference(const RefCountedFlag* flag) : flag_(flag) {}
WeakReference::~WeakReference() {}
WeakReference::WeakReference(WeakReference&& other) = default;
WeakReference::WeakReference(const WeakReference& other) = default;
bool WeakReference::is_valid() const {
return flag_.get() && flag_->IsValid();
}
WeakReferenceOwner::WeakReferenceOwner() {}
WeakReferenceOwner::~WeakReferenceOwner() {
Invalidate();
}
WeakReference WeakReferenceOwner::GetRef() const {
// If we hold the last reference to the Flag then create a new one.
if (!HasRefs())
flag_ = new WeakReference::RefCountedFlag();
return WeakReference(flag_.get());
}
void WeakReferenceOwner::Invalidate() {
if (flag_) {
flag_->Invalidate();
flag_ = nullptr;
}
}
WeakPtrBase::WeakPtrBase() {}
WeakPtrBase::~WeakPtrBase() {}
WeakPtrBase::WeakPtrBase(const WeakReference& ref) : ref_(ref) {}
} // namespace internal
} // namespace webrtc