This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Started handling messages from background isolates for iOS #35174
Merged
auto-submit
merged 19 commits into
flutter:main
from
gaaclarke:isolate-platform-channels
Sep 8, 2022
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8dac13c
Started handling messages from background isolates.
gaaclarke 359010b
- switched to `get rootIsolateId`
gaaclarke 41b710b
switched to storing a platform message handler on the isolate group data
gaaclarke 9bc7750
cleanup
gaaclarke e14b1d1
fixed build files
gaaclarke a4c9807
jasons feedback on communicating the platform message handler
gaaclarke a064bf2
added unit test for platform message response dart port
gaaclarke d156d0e
fixed analyzer error
gaaclarke a458d8d
added a root isolate token test
gaaclarke d2a4429
added todo
gaaclarke cf86d36
turned everything off for other platforms
gaaclarke c888035
linter
gaaclarke fa2be9d
jason feedback
gaaclarke ea07367
jason feedback (error send without registering)
gaaclarke 042114b
fixed new imports
gaaclarke 046fb08
dan feedback
gaaclarke 8b3d890
dan feedback - renamed GetRootIsolateId
gaaclarke 9cc8567
dan feedback
gaaclarke 9acbe3b
removed `isolate_id` from variable names
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Started handling messages from background isolates.
- Loading branch information
commit 8dac13cb192f609835f259ad23d5ff6c8fdbda0e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // 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_FML_THREADSAFE_UNIQUE_PTR_H_ | ||
| #define FLUTTER_FML_THREADSAFE_UNIQUE_PTR_H_ | ||
|
|
||
| #include <memory> | ||
| #include <mutex> | ||
|
|
||
| #include "flutter/fml/macros.h" | ||
|
|
||
| namespace fml { | ||
|
|
||
| /// A single-owner smart pointer that allows weak references that can be | ||
| /// accessed on different threads. | ||
| /// This smart-pointer makes the following guarantees: | ||
| /// * There is only ever one threadsafe_unique_ptr per object. | ||
| /// * The object is deleted when ~threadsafe_unique_ptr() is called. | ||
| /// * The object will not be deleted whilst another thread has a lock_ptr. | ||
| /// * The thread that owns the object can access it without a lock. | ||
| /// WARNING: weak_ptr's should only be used to invoke thread-safe methods. | ||
| template <typename T> | ||
| class threadsafe_unique_ptr { | ||
| private: | ||
| struct Data { | ||
| Data(std::unique_ptr<T>&& arg_ptr) : ptr(std::move(arg_ptr)) {} | ||
| std::unique_ptr<T> ptr; | ||
| std::mutex mutex; | ||
| }; | ||
|
|
||
| public: | ||
| threadsafe_unique_ptr() | ||
| : data_(new Data(std::unique_ptr<T>())), fast_ptr_(nullptr) {} | ||
|
|
||
| threadsafe_unique_ptr(std::unique_ptr<T>&& ptr) | ||
| : data_(new Data(std::move(ptr))) { | ||
| fast_ptr_ = data_->ptr.get(); | ||
| } | ||
|
|
||
| threadsafe_unique_ptr(threadsafe_unique_ptr<T>&& ptr) | ||
| : data_(std::move(ptr.data_)), fast_ptr_(std::move(ptr.fast_ptr_)) {} | ||
|
|
||
| threadsafe_unique_ptr& operator=(threadsafe_unique_ptr&& rvalue) { | ||
| data_ = std::move(rvalue.data_); | ||
| fast_ptr_ = std::move(rvalue.fast_ptr_); | ||
| return *this; | ||
| } | ||
|
|
||
| ~threadsafe_unique_ptr() { | ||
| if (data_) { | ||
| std::scoped_lock lock(data_->mutex); | ||
| data_->ptr.reset(); | ||
| } | ||
| } | ||
|
|
||
| T* operator->() const { return fast_ptr_; } | ||
|
|
||
| T* get() const { return fast_ptr_; } | ||
|
|
||
| operator bool() const { return fast_ptr_ != nullptr; } | ||
|
|
||
| class lock_ptr; | ||
|
|
||
| /// A non-owning smart pointer for a `threadsafe_unique_ptr`. | ||
| class weak_ptr { | ||
gaaclarke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| weak_ptr() {} | ||
|
|
||
| weak_ptr(std::weak_ptr<Data> weak_ptr) : weak_ptr_(weak_ptr) {} | ||
|
|
||
| private: | ||
| friend class lock_ptr; | ||
| std::weak_ptr<Data> weak_ptr_; | ||
| }; | ||
|
|
||
| /// A temporary owning smart pointer for a `threadsafe_unique_ptr`. This | ||
| /// guarantees that the object will not be deleted while in scope. | ||
| class lock_ptr { | ||
| public: | ||
| lock_ptr(const weak_ptr& weak) : strong_ptr_(weak.weak_ptr_.lock()) { | ||
| if (strong_ptr_) { | ||
| lock_ = std::unique_lock(strong_ptr_->mutex); | ||
| } | ||
| } | ||
|
|
||
| T* operator->() { return strong_ptr_ ? strong_ptr_->ptr.get() : nullptr; } | ||
|
|
||
| operator bool() const { | ||
| return strong_ptr_ ? static_cast<bool>(strong_ptr_->ptr) : false; | ||
| } | ||
|
|
||
| private: | ||
| FML_DISALLOW_COPY_AND_ASSIGN(lock_ptr); | ||
| std::shared_ptr<Data> strong_ptr_; | ||
| std::unique_lock<std::mutex> lock_; | ||
| }; | ||
|
|
||
| weak_ptr GetWeakPtr() const { return weak_ptr(data_); } | ||
|
|
||
| private: | ||
| FML_DISALLOW_COPY_AND_ASSIGN(threadsafe_unique_ptr); | ||
| std::shared_ptr<Data> data_; | ||
| // Clients that own the threadsafe_unique_ptr can access the pointer directly | ||
| // since there is no risk that it will be deleted whilst being accessed. | ||
| T* fast_ptr_; | ||
| }; | ||
|
|
||
| } // namespace fml | ||
|
|
||
| #endif // FLUTTER_FML_THREADSAFE_UNIQUE_PTR_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.