Skip to content

Prevent possible race condition in NotifyAppControl #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flutter/shell/platform/tizen/channels/app_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ class AppControlManager {
return instance;
}

void Insert(std::unique_ptr<AppControl> app_control) {
map_.insert({app_control->id(), std::move(app_control)});
// Returns a pointer to the inserted element if successful, otherwise nullptr.
AppControl* Insert(std::unique_ptr<AppControl> app_control) {
auto iter = map_.emplace(app_control->id(), std::move(app_control));
if (iter.second) {
return iter.first->second.get();
}
return nullptr;
}

void Remove(int32_t id) { map_.erase(id); }
Expand Down
11 changes: 8 additions & 3 deletions flutter/shell/platform/tizen/channels/app_control_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ void AppControlChannel::NotifyAppControl(void* handle) {
FT_LOG(Error) << "Could not create an instance of AppControl.";
return;
}
AppControl* app_control_ptr =
AppControlManager::GetInstance().Insert(std::move(app_control));
if (!app_control_ptr) {
FT_LOG(Error) << "The handle already exists.";
return;
}
if (event_sink_) {
SendAppControlEvent(app_control.get());
SendAppControlEvent(app_control_ptr);
} else {
FT_LOG(Info) << "No event channel has been set up.";
queue_.push(app_control.get());
queue_.push(app_control_ptr);
}
AppControlManager::GetInstance().Insert(std::move(app_control));
}

void AppControlChannel::HandleMethodCall(
Expand Down