Flutter Engine
The Flutter Engine
unique_fd.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FML_UNIQUE_FD_H_
6#define FLUTTER_FML_UNIQUE_FD_H_
7
8#include "flutter/fml/build_config.h"
9#include "flutter/fml/unique_object.h"
10
11#if FML_OS_WIN
12#include <windows.h>
13#include <map>
14#include <mutex>
15#include <optional>
16#else // FML_OS_WIN
17#include <dirent.h>
18#include <unistd.h>
19#endif // FML_OS_WIN
20
21namespace fml {
22namespace internal {
23
24#if FML_OS_WIN
25
26namespace os_win {
27
28struct DirCacheEntry {
29 std::wstring filename;
30 FILE_ID_128 id;
31};
32
33// The order of these is important. Must come before UniqueFDTraits struct
34// else linker error. Embedding in struct also causes linker error.
35
36struct UniqueFDTraits {
37 static std::mutex file_map_mutex;
38 static std::map<HANDLE, DirCacheEntry> file_map;
39
40 static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
41 static bool IsValid(HANDLE value) { return value != InvalidValue(); }
42 static void Free_Handle(HANDLE fd);
43
44 static void Free(HANDLE fd) {
45 RemoveCacheEntry(fd);
46
47 UniqueFDTraits::Free_Handle(fd);
48 }
49
50 static void RemoveCacheEntry(HANDLE fd) {
51 const std::lock_guard<std::mutex> lock(file_map_mutex);
52
53 file_map.erase(fd);
54 }
55
56 static void StoreCacheEntry(HANDLE fd, DirCacheEntry state) {
57 const std::lock_guard<std::mutex> lock(file_map_mutex);
58 file_map[fd] = state;
59 }
60
61 static std::optional<DirCacheEntry> GetCacheEntry(HANDLE fd) {
62 const std::lock_guard<std::mutex> lock(file_map_mutex);
63 auto found = file_map.find(fd);
64 return found == file_map.end()
65 ? std::nullopt
66 : std::optional<DirCacheEntry>{found->second};
67 }
68};
69
70} // namespace os_win
71
72#else // FML_OS_WIN
73
74namespace os_unix {
75
77 static int InvalidValue() { return -1; }
78 static bool IsValid(int value) { return value >= 0; }
79 static void Free(int fd);
80};
81
83 static DIR* InvalidValue() { return nullptr; }
84 static bool IsValid(DIR* value) { return value != nullptr; }
85 static void Free(DIR* dir);
86};
87
88} // namespace os_unix
89
90#endif // FML_OS_WIN
91
92} // namespace internal
93
94#if FML_OS_WIN
95
96using UniqueFD = UniqueObject<HANDLE, internal::os_win::UniqueFDTraits>;
97
98#else // FML_OS_WIN
99
102
103#endif // FML_OS_WIN
104
105} // namespace fml
106
107#endif // FLUTTER_FML_UNIQUE_FD_H_
AtkStateType state
uint8_t value
static void Free(FreeList *free_list, uword address, intptr_t size, bool is_protected)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
Definition: ascii_trie.cc:9
UniqueObject< int, internal::os_unix::UniqueFDTraits > UniqueFD
Definition: unique_fd.h:100
static bool IsValid(DIR *value)
Definition: unique_fd.h:84
static bool IsValid(int value)
Definition: unique_fd.h:78
const uintptr_t id
#define INVALID_HANDLE_VALUE
void * HANDLE
Definition: windows_types.h:36