Flutter iOS Embedder
isolate_scope.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/fml/logging.h"
6 #include "third_party/dart/runtime/include/dart_api.h"
7 
8 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_ISOLATE_SCOPE_H_
9 #define FLUTTER_SHELL_PLATFORM_COMMON_ISOLATE_SCOPE_H_
10 
11 namespace flutter {
12 
13 /// This class is a thin wrapper around dart isolate. It can be used
14 /// as argument to IsolateScope constructor to enter and exit the isolate.
15 class Isolate {
16  public:
17  /// Retrieve the current Dart Isolate. If no isolate is current, this
18  /// results in a crash.
19  static Isolate Current();
20 
21  ~Isolate() = default;
22 
23  private:
24  explicit Isolate(Dart_Isolate isolate) : isolate_(isolate) {
25  FML_DCHECK(isolate_ != nullptr);
26  }
27 
28  friend class IsolateScope;
29  Dart_Isolate isolate_;
30 };
31 
32 // Enters provided isolate for as long as the scope is alive.
33 class IsolateScope {
34  public:
35  explicit IsolateScope(const Isolate& isolate);
36  ~IsolateScope();
37 
38  private:
39  Dart_Isolate isolate_;
40  Dart_Isolate previous_;
41 
42  FML_DISALLOW_COPY_AND_ASSIGN(IsolateScope);
43 };
44 
45 } // namespace flutter
46 
47 #endif // FLUTTER_SHELL_PLATFORM_COMMON_ISOLATE_SCOPE_H_
static Isolate Current()
Definition: isolate_scope.cc:9
~Isolate()=default
IsolateScope(const Isolate &isolate)