forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_isolate_manager.h
56 lines (43 loc) · 1.93 KB
/
platform_isolate_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_RUNTIME_PLATFORM_ISOLATE_MANAGER_H_
#define FLUTTER_RUNTIME_PLATFORM_ISOLATE_MANAGER_H_
#include <atomic>
#include <mutex>
#include <unordered_set>
#include "third_party/dart/runtime/include/dart_api.h"
namespace flutter {
/// Maintains a list of registered platform isolates, so that they can be
/// proactively shutdown as a group during shell shutdown.
class PlatformIsolateManager {
public:
/// Returns whether the PlatformIsolateManager is shutdown. New isolates
/// cannot be registered after the manager is shutdown. Must be called on the
/// platform thread.
bool HasShutdown();
/// Returns whether the PlatformIsolateManager is shutdown. New isolates
/// cannot be registered after the manager is shutdown. Callable from any
/// thread. The result may be obsolete immediately after the call.
bool HasShutdownMaybeFalseNegative();
/// Register an isolate in the list of platform isolates. Callable from any
/// thread.
bool RegisterPlatformIsolate(Dart_Isolate isolate);
/// Remove an isolate from the list of platform isolates. Must be called from
/// the platform thread.
void RemovePlatformIsolate(Dart_Isolate isolate);
/// Shuts down all registered isolates, and the manager itself. Must be called
/// from the platform thread.
void ShutdownPlatformIsolates();
/// Returns whether an isolate is registered. For testing only. Callable from
/// any thread.
bool IsRegisteredForTestingOnly(Dart_Isolate isolate);
private:
// This lock must be recursive because ShutdownPlatformIsolates indirectly
// calls RemovePlatformIsolate.
std::recursive_mutex lock_;
std::unordered_set<Dart_Isolate> platform_isolates_;
bool is_shutdown_ = false;
};
} // namespace flutter
#endif // FLUTTER_RUNTIME_PLATFORM_ISOLATE_MANAGER_H_