Skip to content

Commit

Permalink
Prevent possible race condition in NotifyAppControl (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim authored Dec 26, 2023
1 parent f6da9cc commit c382987
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit c382987

Please sign in to comment.