Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:42:25

0001 // Copyright 2020 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
0004 
0005 #ifndef INCLUDE_CPPGC_EPHEMERON_PAIR_H_
0006 #define INCLUDE_CPPGC_EPHEMERON_PAIR_H_
0007 
0008 #include "cppgc/liveness-broker.h"
0009 #include "cppgc/member.h"
0010 
0011 namespace cppgc {
0012 
0013 /**
0014  * An ephemeron pair is used to conditionally retain an object.
0015  * The `value` will be kept alive only if the `key` is alive.
0016  */
0017 template <typename K, typename V>
0018 struct EphemeronPair {
0019   EphemeronPair(K* k, V* v) : key(k), value(v) {}
0020   WeakMember<K> key;
0021   Member<V> value;
0022 
0023   void ClearValueIfKeyIsDead(const LivenessBroker& broker) {
0024     if (!broker.IsHeapObjectAlive(key)) value = nullptr;
0025   }
0026 };
0027 
0028 }  // namespace cppgc
0029 
0030 #endif  // INCLUDE_CPPGC_EPHEMERON_PAIR_H_