Flutter Engine
flutter::testing::AutoIsolateShutdown Class Reference

#include <dart_isolate_runner.h>

Public Member Functions

 AutoIsolateShutdown ()=default
 
 AutoIsolateShutdown (std::shared_ptr< DartIsolate > isolate, fml::RefPtr< fml::TaskRunner > runner)
 
 ~AutoIsolateShutdown ()
 
bool IsValid () const
 
bool RunInIsolateScope (std::function< bool(void)> closure)
 
void Shutdown ()
 
DartIsolateget ()
 

Detailed Description

Definition at line 20 of file dart_isolate_runner.h.

Constructor & Destructor Documentation

◆ AutoIsolateShutdown() [1/2]

flutter::testing::AutoIsolateShutdown::AutoIsolateShutdown ( )
default

◆ AutoIsolateShutdown() [2/2]

flutter::testing::AutoIsolateShutdown::AutoIsolateShutdown ( std::shared_ptr< DartIsolate isolate,
fml::RefPtr< fml::TaskRunner runner 
)

Definition at line 11 of file dart_isolate_runner.cc.

13  : isolate_(std::move(isolate)), runner_(std::move(runner)) {}

◆ ~AutoIsolateShutdown()

flutter::testing::AutoIsolateShutdown::~AutoIsolateShutdown ( )

Definition at line 15 of file dart_isolate_runner.cc.

References fml::TaskRunner::RunNowOrPostTask(), Shutdown(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

15  {
16  if (!isolate_->IsShuttingDown()) {
17  Shutdown();
18  }
20  fml::TaskRunner::RunNowOrPostTask(runner_, [this, &latch]() {
21  // Delete isolate on thread.
22  isolate_.reset();
23  latch.Signal();
24  });
25  latch.Wait();
26 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

Member Function Documentation

◆ get()

DartIsolate* flutter::testing::AutoIsolateShutdown::get ( )
inline

Definition at line 35 of file dart_isolate_runner.h.

References args, FML_CHECK, result, and flutter::testing::RunDartCodeInIsolate().

35  {
36  FML_CHECK(isolate_);
37  return isolate_.get();
38  }
#define FML_CHECK(condition)
Definition: logging.h:68

◆ IsValid()

bool flutter::testing::AutoIsolateShutdown::IsValid ( ) const
inline

Definition at line 29 of file dart_isolate_runner.h.

References function, RunInIsolateScope(), and Shutdown().

Referenced by RunInIsolateScope(), and Shutdown().

29 { return isolate_ != nullptr && runner_; }

◆ RunInIsolateScope()

bool flutter::testing::AutoIsolateShutdown::RunInIsolateScope ( std::function< bool(void)>  closure)

Definition at line 44 of file dart_isolate_runner.cc.

References IsValid(), result, fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by IsValid().

45  {
46  if (!IsValid()) {
47  return false;
48  }
49 
50  bool result = false;
53  runner_, [this, &result, &latch, closure]() {
54  tonic::DartIsolateScope scope(isolate_->isolate());
55  tonic::DartApiScope api_scope;
56  if (closure) {
57  result = closure();
58  }
59  latch.Signal();
60  });
61  latch.Wait();
62  return result;
63 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
GAsyncResult * result
std::function< void()> closure
Definition: closure.h:14

◆ Shutdown()

void flutter::testing::AutoIsolateShutdown::Shutdown ( )

Definition at line 28 of file dart_isolate_runner.cc.

References FML_CHECK, FML_LOG, IsValid(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by IsValid(), and ~AutoIsolateShutdown().

28  {
29  if (!IsValid()) {
30  return;
31  }
34  runner_, [isolate = isolate_.get(), &latch]() {
35  if (!isolate->Shutdown()) {
36  FML_LOG(ERROR) << "Could not shutdown isolate.";
37  FML_CHECK(false);
38  }
39  latch.Signal();
40  });
41  latch.Wait();
42 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
#define FML_LOG(severity)
Definition: logging.h:65
#define FML_CHECK(condition)
Definition: logging.h:68

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