flutter_flutter/lib/ui/isolate_name_server/isolate_name_server.cc
Ben Konyi 8d8d91bfc3
IsolateNameServer reland (#5519)
* Reland "Added IsolateNameServer functionality (#5410)"

This reverts commit c3976b3c7183f479717bffed3f640fb92afbd3dc.

* Fixed issue with isolate_name_server_test which caused test to timeout

* Disabled thread_annotations on Android as they aren't supported in the
NDK headers for std::mutex. Readded thread annotations to
IsolateNameServer.
2018-06-13 11:57:10 -07:00

45 lines
1.3 KiB
C++

// Copyright 2018 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.
#include "flutter/lib/ui/isolate_name_server/isolate_name_server.h"
namespace blink {
Dart_Port IsolateNameServer::LookupIsolatePortByName(const std::string& name) {
std::unique_lock<std::mutex> lock(mutex_);
return LookupIsolatePortByNameUnprotected(name);
}
Dart_Port IsolateNameServer::LookupIsolatePortByNameUnprotected(
const std::string& name) {
auto port_iterator = port_mapping_.find(name);
if (port_iterator != port_mapping_.end()) {
return port_iterator->second;
}
return ILLEGAL_PORT;
}
bool IsolateNameServer::RegisterIsolatePortWithName(Dart_Port port,
const std::string& name) {
std::unique_lock<std::mutex> lock(mutex_);
if (LookupIsolatePortByNameUnprotected(name) != ILLEGAL_PORT) {
// Name is already registered.
return false;
}
port_mapping_[name] = port;
return true;
}
bool IsolateNameServer::RemoveIsolateNameMapping(const std::string& name) {
std::unique_lock<std::mutex> lock(mutex_);
auto port_iterator = port_mapping_.find(name);
if (port_iterator == port_mapping_.end()) {
return false;
}
port_mapping_.erase(port_iterator);
return true;
}
} // namespace blink