flutter_flutter/lib/ui/isolate_name_server/isolate_name_server.cc
Petr Hosek c6baaaf75a
Replace acquire+release thread annotation with excludes (#5944)
The behavior of acquire+release annotation handling has changed in
https://reviews.llvm.org/D49355 which breaks the build with the new
Clang. However, as has been pointed out, the acquire+release isn't
the right way to prevent double locking as the annotations negate
each other; the correct way is to use excludes or negative requires.
Using excludes annotations also requires using std::lock_guard instead
of std::unique_lock because the latter doesn't have the thread
annotations due to deferred locking which is not needed in Flutter and
so std::lock_guard is a sufficient alternative.
2018-08-05 18:25:43 -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::lock_guard<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::lock_guard<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::lock_guard<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