跳转至

base/include/base/weak_ptr/private/weak_ptr_internals.h

Internal implementation details for WeakPtr system. More...

Namespaces

Name
cf
cf::internal

Classes

Name
class cf::internal::WeakReferenceFlag
Shared flag tracking WeakPtr liveness state.

Detailed Description

Internal implementation details for WeakPtr system.

Author: N/A

Version: N/A

Since: N/A

Date: N/A

This header contains the internal implementation details for the WeakPtr system. External code should not directly include or depend on this file. WeakPtr and WeakPtrFactory share the WeakReferenceFlag to track liveness.

Source code

#pragma once

#include <atomic>
#include <memory>

namespace cf {
namespace internal {

class WeakReferenceFlag {
  public:
    WeakReferenceFlag() = default;

    WeakReferenceFlag(const WeakReferenceFlag&) = delete;

    WeakReferenceFlag& operator=(const WeakReferenceFlag&) = delete;

    WeakReferenceFlag(WeakReferenceFlag&&) = delete;

    WeakReferenceFlag& operator=(WeakReferenceFlag&&) = delete;

    [[nodiscard]] bool IsAlive() const noexcept { return alive_.load(std::memory_order_acquire); }

    void Invalidate() noexcept { alive_.store(false, std::memory_order_release); }

  private:
    std::atomic<bool> alive_{true};
};

using WeakReferenceFlagPtr = std::shared_ptr<WeakReferenceFlag>;

} // namespace internal
} // namespace cf

Updated on 2026-03-09 at 10:14:01 +0000