mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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.
50 lines
1.6 KiB
C++
50 lines
1.6 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.
|
|
|
|
#ifndef FLUTTER_LIB_UI_ISOLATE_NAME_SERVER_H_
|
|
#define FLUTTER_LIB_UI_ISOLATE_NAME_SERVER_H_
|
|
|
|
#include <map>
|
|
#include <mutex>
|
|
#include <string>
|
|
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/fml/synchronization/thread_annotations.h"
|
|
#include "third_party/dart/runtime/include/dart_api.h"
|
|
|
|
namespace blink {
|
|
|
|
class IsolateNameServer {
|
|
public:
|
|
IsolateNameServer() {}
|
|
|
|
// Looks up the Dart_Port associated with a given name. Returns ILLEGAL_PORT
|
|
// if the name does not exist.
|
|
Dart_Port LookupIsolatePortByName(const std::string& name)
|
|
FML_LOCKS_EXCLUDED(mutex_);
|
|
|
|
// Registers a Dart_Port with a given name. Returns true if registration is
|
|
// successful, false if the name entry already exists.
|
|
bool RegisterIsolatePortWithName(Dart_Port port, const std::string& name)
|
|
FML_LOCKS_EXCLUDED(mutex_);
|
|
|
|
// Removes a name to Dart_Port mapping given a name. Returns true if the
|
|
// mapping was successfully removed, false if the mapping does not exist.
|
|
bool RemoveIsolateNameMapping(const std::string& name)
|
|
FML_LOCKS_EXCLUDED(mutex_);
|
|
|
|
private:
|
|
Dart_Port LookupIsolatePortByNameUnprotected(const std::string& name)
|
|
FML_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
|
|
|
mutable std::mutex mutex_;
|
|
std::map<std::string, Dart_Port> port_mapping_ FML_GUARDED_BY(mutex_);
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(IsolateNameServer);
|
|
};
|
|
|
|
} // namespace blink
|
|
|
|
#endif // FLUTTER_LIB_UI_ISOLATE_NAME_SERVER_H_
|