Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
tonic::DartWeakPersistentValue Class Reference

#include <dart_weak_persistent_value.h>

Public Member Functions

 DartWeakPersistentValue ()
 
 ~DartWeakPersistentValue ()
 
Dart_WeakPersistentHandle value () const
 
bool is_empty () const
 
void Set (DartState *dart_state, Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
 
void Clear ()
 
Dart_Handle Get ()
 
const std::weak_ptr< DartState > & dart_state () const
 

Detailed Description

Definition at line 21 of file dart_weak_persistent_value.h.

Constructor & Destructor Documentation

◆ DartWeakPersistentValue()

tonic::DartWeakPersistentValue::DartWeakPersistentValue ( )

Definition at line 12 of file dart_weak_persistent_value.cc.

12: handle_(nullptr) {}

◆ ~DartWeakPersistentValue()

tonic::DartWeakPersistentValue::~DartWeakPersistentValue ( )

Definition at line 14 of file dart_weak_persistent_value.cc.

Member Function Documentation

◆ Clear()

void tonic::DartWeakPersistentValue::Clear ( )

Definition at line 29 of file dart_weak_persistent_value.cc.

29 {
30 if (!handle_) {
31 return;
32 }
33
34 auto dart_state = dart_state_.lock();
35 if (!dart_state) {
36 // The DartVM that the handle used to belong to has been shut down and that
37 // handle has already been deleted.
38 handle_ = nullptr;
39 return;
40 }
41
42 // The DartVM frees the handles during shutdown and calls the finalizers.
43 // Freeing handles during shutdown would fail.
44 if (!dart_state->IsShuttingDown()) {
47 } else {
48 // If we are not on the mutator thread, this will fail. The caller must
49 // ensure to be on the mutator thread.
50 DartIsolateScope scope(dart_state->isolate());
52 }
53 }
54 // If it's shutting down, the handle will be deleted already.
55
56 dart_state_.reset();
57 handle_ = nullptr;
58}
const std::weak_ptr< DartState > & dart_state() const
DART_EXPORT void Dart_DeleteWeakPersistentHandle(Dart_WeakPersistentHandle object)
DART_EXPORT Dart_IsolateGroup Dart_CurrentIsolateGroup(void)

◆ dart_state()

const std::weak_ptr< DartState > & tonic::DartWeakPersistentValue::dart_state ( ) const
inline

Definition at line 37 of file dart_weak_persistent_value.h.

37{ return dart_state_; }

◆ Get()

Dart_Handle tonic::DartWeakPersistentValue::Get ( )

Definition at line 60 of file dart_weak_persistent_value.cc.

60 {
61 auto dart_state = dart_state_.lock();
63 TONIC_DCHECK(!dart_state->IsShuttingDown());
64 if (!handle_) {
65 return nullptr;
66 }
67 return Dart_HandleFromWeakPersistent(handle_);
68}
DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object)
#define TONIC_DCHECK
Definition: macros.h:32

◆ is_empty()

bool tonic::DartWeakPersistentValue::is_empty ( ) const
inline

Definition at line 27 of file dart_weak_persistent_value.h.

27{ return handle_ == nullptr; }

◆ Set()

void tonic::DartWeakPersistentValue::Set ( DartState dart_state,
Dart_Handle  object,
void *  peer,
intptr_t  external_allocation_size,
Dart_HandleFinalizer  callback 
)

Definition at line 18 of file dart_weak_persistent_value.cc.

22 {
24 dart_state_ = dart_state->GetWeakPtr();
25 handle_ = Dart_NewWeakPersistentHandle(object, peer, external_allocation_size,
26 callback);
27}
DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ value()

Dart_WeakPersistentHandle tonic::DartWeakPersistentValue::value ( ) const
inline

Definition at line 26 of file dart_weak_persistent_value.h.

26{ return handle_; }

The documentation for this class was generated from the following files: