Skip to content

Commit

Permalink
Stop all surfaces on SurfaceManager destruction (#48481)
Browse files Browse the repository at this point in the history
Summary:

[Changelog] [Internal] - Stop all surfaces on SurfaceManager destruction

Reviewed By: zeyap

Differential Revision: D67809574
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Jan 3, 2025
1 parent af000b7 commit 87ad704
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace facebook::react {
SurfaceManager::SurfaceManager(const Scheduler& scheduler) noexcept
: scheduler_(scheduler) {}

SurfaceManager::~SurfaceManager() noexcept {
stopAllSurfaces();
}

void SurfaceManager::startSurface(
SurfaceId surfaceId,
const std::string& moduleName,
Expand Down Expand Up @@ -58,6 +62,19 @@ void SurfaceManager::stopSurface(SurfaceId surfaceId) const noexcept {
}
}

void SurfaceManager::stopAllSurfaces() const noexcept {
std::unordered_set<SurfaceId> surfaceIds;
{
std::shared_lock lock(mutex_);
for (const auto& [surfaceId, _] : registry_) {
surfaceIds.insert(surfaceId);
}
}
for (const auto& surfaceId : surfaceIds) {
stopSurface(surfaceId);
}
}

Size SurfaceManager::measureSurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace facebook::react {
class SurfaceManager final {
public:
explicit SurfaceManager(const Scheduler& scheduler) noexcept;
~SurfaceManager() noexcept;

#pragma mark - Surface Management

Expand All @@ -44,6 +45,8 @@ class SurfaceManager final {

void stopSurface(SurfaceId surfaceId) const noexcept;

void stopAllSurfaces() const noexcept;

Size measureSurface(
SurfaceId surfaceId,
const LayoutConstraints& layoutConstraints,
Expand Down

0 comments on commit 87ad704

Please sign in to comment.