Flutter Engine
 
Loading...
Searching...
No Matches
fml Namespace Reference

Namespaces

namespace  benchmarking
 
namespace  icu
 
namespace  internal
 
namespace  jni
 
namespace  paths
 
namespace  state
 
namespace  testing
 
namespace  tracing
 

Classes

class  AsciiTrie
 A trie for looking for ASCII prefixes. More...
 
class  AtomicObject
 
class  AutoResetWaitableEvent
 
class  BasicTaskRunner
 An interface over the ability to schedule tasks on a TaskRunner. More...
 
class  BitConverter
 
class  CFRef
 
struct  CFRefTestState
 
struct  CFRefTraits
 Default retain and release implementations for CFRef. More...
 
struct  CFRefTraits< CFRefTestState * >
 
struct  CFRefTraits< CGImageRef >
 fml::CFRef retain and release implementations for CGImageRef. More...
 
class  ChronoTimestampProvider
 
class  CommandLine
 
class  ConcurrentMessageLoop
 
class  ConcurrentMessageLoopDarwin
 
class  ConcurrentTaskRunner
 
class  CountDownLatch
 
struct  CpuIndexAndSpeed
 
class  CPUSpeedTracker
 A class that computes the correct CPU indices for a requested CPU affinity. More...
 
class  DataMapping
 
struct  DebugTaskRunnerChecker
 
struct  DebugThreadChecker
 
class  DelayedTask
 
class  FileMapping
 
struct  IsByteSwappable
 
class  LogInterestListener
 
class  LogMessage
 
class  LogMessageVoidify
 
struct  LogSettings
 
class  LogState
 
class  MallocMapping
 A Mapping like NonOwnedMapping, but uses Free as its release proc. More...
 
class  ManualResetWaitableEvent
 
class  Mapping
 
class  MessageLoop
 
class  MessageLoopAndroid
 
class  MessageLoopDarwin
 
class  MessageLoopFuchsia
 
class  MessageLoopImpl
 
class  MessageLoopLinux
 
class  MessageLoopTaskQueues
 
class  MessageLoopWin
 
class  NativeLibrary
 
class  NonOwnedMapping
 
class  PlatformSemaphore
 
class  RasterThreadMerger
 
class  RefCountedThreadSafe
 
class  RefPtr
 
class  ScopedCleanupClosure
 Wraps a closure that is invoked in the destructor unless released by the caller. More...
 
class  ScopedNSAutoreleasePool
 
class  ScopedSetLogSettings
 
class  ScopedTemporaryDirectory
 
class  Semaphore
 A traditional counting semaphore. Waits decrement the counter and Signal increments it. More...
 
class  SharedThreadMerger
 
class  Status
 
class  StatusOr
 
class  SymbolMapping
 
class  SyncSwitch
 
class  TaskQueueEntry
 
class  TaskQueueId
 
class  TaskRunner
 
class  TaskRunnerAffineWeakPtr
 
class  TaskRunnerAffineWeakPtrFactory
 
class  TaskRunnerChecker
 
class  TaskSource
 
class  Thread
 
class  ThreadChecker
 
class  ThreadHandle
 
class  TimeDelta
 
class  TimePoint
 
class  TimestampProvider
 
struct  UniqueLooperTraits
 
class  UniqueObject
 
class  Wakeable
 
class  WeakPtr
 
class  WeakPtrFactory
 

Concepts

concept  UniqueObjectTraits
 

Typedefs

typedef AsciiTrie::TrieNode TrieNode
 
typedef AsciiTrie::TrieNodePtr TrieNodePtr
 
using Base32DecodeConverter = BitConverter< 5, 8, 16 >
 
using Base32EncodeConverter = BitConverter< 8, 5, 16 >
 
using closure = std::function< void()>
 
using DelayedTaskQueue = std::priority_queue< DelayedTask, std::deque< DelayedTask >, std::greater< DelayedTask > >
 
using FileVisitor = std::function< bool(const fml::UniqueFD &directory, const std::string &filename)>
 
typedef int LogSeverity
 
using WideStringConverter = std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t >
 
typedef void * RasterThreadMergerId
 
using Utf16StringConverter = std::wstring_convert< std::codecvt_utf8_utf16< char16_t >, char16_t >
 
typedef std::function< void()> ThreadFunction
 
using Milliseconds = std::chrono::duration< double, std::milli >
 
using UniqueFD = UniqueObject< int, internal::os_unix::UniqueFDTraits >
 
using UniqueDir = UniqueObject< DIR *, internal::os_unix::UniqueDirTraits >
 

Enumerations

enum class  CpuAffinity {
  kPerformance ,
  kEfficiency ,
  kNotPerformance ,
  kNotEfficiency
}
 
enum class  FilePermission {
  kRead ,
  kWrite ,
  kReadWrite
}
 
enum class  FlushType {
  kSingle ,
  kAll
}
 
enum class  RasterThreadStatus {
  kRemainsMerged ,
  kRemainsUnmerged ,
  kUnmergedNow
}
 
enum class  StatusCode {
  kOk ,
  kCancelled ,
  kUnknown ,
  kInvalidArgument ,
  kDeadlineExceeded ,
  kNotFound ,
  kAlreadyExists ,
  kPermissionDenied ,
  kResourceExhausted ,
  kFailedPrecondition ,
  kAborted ,
  kOutOfRange ,
  kUnimplemented ,
  kInternal ,
  kUnavailable ,
  kDataLoss ,
  kUnauthenticated
}
 
enum class  TaskSourceGrade {
  kUserInteraction ,
  kDartEventLoop ,
  kUnspecified
}
 

Functions

static std::string GetSymbolName (void *symbol)
 
static int Backtrace (void **symbols, int size)
 
std::string BacktraceHere (size_t offset)
 
static std::string SignalNameToString (int signal)
 
static void ToggleSignalHandlers (bool set)
 
static void SignalHandler (int signal)
 
void InstallCrashHandler ()
 
bool IsCrashHandlingSupported ()
 
std::pair< bool, std::string > Base32Encode (std::string_view input)
 
std::pair< bool, std::string > Base32Decode (const std::string &input)
 
std::vector< std::string > CommandLineToArgv (const CommandLine &command_line)
 
template<typename InputIterator >
CommandLine CommandLineFromIteratorsFindFirstPositionalArg (InputIterator first, InputIterator last, InputIterator *first_positional_arg)
 
template<typename InputIterator >
CommandLine CommandLineFromIterators (InputIterator first, InputIterator last)
 
template<typename InputIterator >
CommandLine CommandLineFromIteratorsWithArgv0 (const std::string &argv0, InputIterator first, InputIterator last)
 
std::optional< CommandLineCommandLineFromPlatform ()
 
CommandLine CommandLineFromArgcArgv (int argc, const char *const *argv)
 
CommandLine CommandLineFromPlatformOrArgcArgv (int argc, const char *const *argv)
 
template<typename StringType >
CommandLine CommandLineFromInitializerList (std::initializer_list< StringType > argv)
 
template<class Collection = std::unordered_map<class Key, class Value, class Hash, class Equal>>
void erase_if (Collection &container, const std::function< bool(typename Collection::iterator)> &predicate)
 
std::optional< size_t > EfficiencyCoreCount ()
 Request count of efficiency cores.
 
bool RequestAffinity (CpuAffinity affinity)
 Request the given affinity for the current thread.
 
std::optional< int64_t > ReadIntFromFile (const std::string &path)
 
template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T ByteSwap (T n)
 Flips the endianness of the given value. The given value must be an integral type of size 1, 2, 4, or 8.
 
template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T BigEndianToArch (T n)
 Convert a known big endian value to match the endianness of the current architecture. This is effectively a cross platform ntohl/ntohs (as network byte order is always Big Endian). The given value must be an integral type of size 1, 2, 4, or 8.
 
template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T LittleEndianToArch (T n)
 Convert a known little endian value to match the endianness of the current architecture. The given value must be an integral type of size 1, 2, 4, or 8.
 
static fml::UniqueFD CreateDirectory (const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
 
fml::UniqueFD CreateDirectory (const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission)
 
bool VisitFilesRecursively (const fml::UniqueFD &directory, const FileVisitor &visitor)
 
fml::UniqueFD OpenFileReadOnly (const fml::UniqueFD &base_directory, const char *path)
 
fml::UniqueFD OpenDirectoryReadOnly (const fml::UniqueFD &base_directory, const char *path)
 
bool RemoveFilesInDirectory (const fml::UniqueFD &directory)
 
bool RemoveDirectoryRecursively (const fml::UniqueFD &parent, const char *directory_name)
 
std::string CreateTemporaryDirectory ()
 
fml::UniqueFD OpenFile (const char *path, bool create_if_necessary, FilePermission permission)
 This can open a directory on POSIX, but not on Windows.
 
fml::UniqueFD OpenFile (const fml::UniqueFD &base_directory, const char *path, bool create_if_necessary, FilePermission permission)
 This can open a directory on POSIX, but not on Windows.
 
fml::UniqueFD OpenDirectory (const char *path, bool create_if_necessary, FilePermission permission)
 
fml::UniqueFD OpenDirectory (const fml::UniqueFD &base_directory, const char *path, bool create_if_necessary, FilePermission permission)
 
fml::UniqueFD Duplicate (fml::UniqueFD::element_type descriptor)
 
bool IsDirectory (const fml::UniqueFD &directory)
 
bool IsDirectory (const fml::UniqueFD &base_directory, const char *path)
 
bool IsFile (const std::string &path)
 
bool TruncateFile (const fml::UniqueFD &file, size_t size)
 
bool FileExists (const fml::UniqueFD &base_directory, const char *path)
 
bool UnlinkDirectory (const char *path)
 
bool UnlinkDirectory (const fml::UniqueFD &base_directory, const char *path)
 
bool UnlinkFile (const char *path)
 
bool UnlinkFile (const fml::UniqueFD &base_directory, const char *path)
 
bool WriteAtomically (const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
 
bool VisitFiles (const fml::UniqueFD &directory, const FileVisitor &visitor)
 
template<class Type >
constexpr void HashCombineSeed (std::size_t &seed, const Type &arg)
 
template<class Type , class... Rest>
constexpr void HashCombineSeed (std::size_t &seed, const Type &arg, const Rest &... other_args)
 
constexpr std::size_t HashCombine ()
 
template<class... Type>
constexpr std::size_t HashCombine (const Type &... args)
 
std::string HexEncode (std::string_view input)
 
void SetLogSettings (const LogSettings &settings)
 
LogSettings GetLogSettings ()
 
int GetMinLogLevel ()
 
int GetVlogVerbosity ()
 
bool ShouldCreateLogMessage (LogSeverity severity)
 
void KillProcess ()
 
constexpr bool ShouldCreateLogMessageConstexpr (LogSeverity severity, bool true_arg)
 
constexpr void KillProcessConstexpr (bool true_arg)
 
template<typename T >
internal::CopyableLambda< T > MakeCopyable (T lambda)
 
 TEST (MallocMapping, EmptyContructor)
 
 TEST (MallocMapping, NotEmptyContructor)
 
 TEST (MallocMapping, MoveConstructor)
 
 TEST (MallocMapping, Copy)
 
 TEST (MallocMapping, Release)
 
 TEST (MallocMapping, IsDontNeedSafe)
 
 TEST (MallocMapping, CopySizeZero)
 
template<typename T >
RefPtr< T > AdoptRef (T *ptr)
 
template<typename T >
RefPtr< T > Ref (T *ptr)
 
template<typename T , typename... Args>
RefPtr< T > MakeRefCounted (Args &&... args)
 
void InitCPUInfo (size_t cpu_count)
 
bool SetUpCPUTracker ()
 
std::optional< size_t > AndroidEfficiencyCoreCount ()
 Android specific implementation of EfficiencyCoreCount.
 
bool AndroidRequestAffinity (CpuAffinity affinity)
 Android specific implementation of RequestAffinity.
 
static ALooper * AcquireLooperForThread ()
 
bool IsPlatformVersionAtLeast (size_t major, size_t minor=0, size_t patch=0)
 
NSRange RangeForCharacterAtIndex (NSString *text, NSUInteger index)
 
NSRange RangeForCharactersInRange (NSString *text, NSRange range)
 
void ExecuteAfterTaskObservers ()
 
fml::TaskQueueId CurrentMessageLoopAddAfterTaskObserver (intptr_t key, fit::closure observer)
 
void CurrentMessageLoopRemoveAfterTaskObserver (fml::TaskQueueId queue_id, intptr_t key)
 
bool TimerRearm (int fd, fml::TimePoint time_point)
 Rearms the timer to expire at the given time point.
 
bool TimerDrain (int fd)
 
static int ToPosixAccessFlags (FilePermission permission)
 
static int ToPosixCreateModeFlags (FilePermission permission)
 
static int ToPosixProtectionFlags (std::initializer_list< FileMapping::Protection > protection_flags)
 
static bool IsWritable (std::initializer_list< FileMapping::Protection > protection_flags)
 
char * strdup (const char *str1)
 
int GetCurrentProcId ()
 
std::string GetLastErrorMessage ()
 
static std::string GetFullHandlePath (const fml::UniqueFD &handle)
 
static bool IsAbsolutePath (const char *path)
 
static std::string GetAbsolutePath (const fml::UniqueFD &base_directory, const char *subpath)
 
static std::wstring GetTemporaryDirectoryPath ()
 
static DWORD GetDesiredAccessFlags (FilePermission permission)
 
static DWORD GetShareFlags (FilePermission permission)
 
static DWORD GetFileAttributesForUtf8Path (const char *absolute_path)
 
static DWORD GetFileAttributesForUtf8Path (const fml::UniqueFD &base_directory, const char *path)
 
static bool IsWritable (std::initializer_list< FileMapping::Protection > protection_flags)
 
static bool IsExecutable (std::initializer_list< FileMapping::Protection > protection_flags)
 
std::string WideStringToUtf8 (const std::wstring_view str)
 
std::wstring Utf8ToWideString (const std::string_view str)
 
std::u16string WideStringToUtf16 (const std::wstring_view str)
 
std::wstring Utf16ToWideString (const std::u16string_view str)
 
std::string Join (const std::vector< std::string > &vec, const char *delim)
 
std::string Utf16ToUtf8 (const std::u16string_view string)
 
std::u16string Utf8ToUtf16 (const std::string_view string)
 
 TEST (CountDownLatchTest, CanWaitOnZero)
 
 TEST (CountDownLatchTest, CanWait)
 
template<typename ConditionFn >
bool WaitWithTimeoutImpl (std::unique_lock< std::mutex > *locker, std::condition_variable *cv, ConditionFn condition, TimeDelta timeout)
 
void SetThreadName (const std::string &name)
 
fml::TimePoint ChronoTicksSinceEpoch ()
 
template<typename T >
Milliseconds RefreshRateToFrameBudget (T refresh_rate)
 
template<typename Clock , typename Duration >
static int64_t NanosSinceEpoch (std::chrono::time_point< Clock, Duration > time_point)
 
template<class T , class Traits >
void swap (const UniqueObject< T, Traits > &a, const UniqueObject< T, Traits > &b)
 
template<class T , class Traits >
bool operator== (const T &value, const UniqueObject< T, Traits > &object)
 
template<class T , class Traits >
bool operator!= (const T &value, const UniqueObject< T, Traits > &object)
 

Variables

static std::string kKUnknownFrameName = "Unknown"
 
static size_t kKnownSignalHandlers []
 
static std::string kKUnknownFrameName = "Unknown"
 
static constexpr char kEncoding [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
 
static constexpr signed char kDecodeMap []
 
static constexpr int kDecodeMapSize
 
template<typename T >
constexpr bool kIsByteSwappableV = IsByteSwappable<T>::value
 
static constexpr char kEncoding [] = "0123456789abcdef"
 
constexpr LogSeverity kLogInfo = 0
 
constexpr LogSeverity kLogWarning = 1
 
constexpr LogSeverity kLogError = 2
 
constexpr LogSeverity kLogImportant = 3
 
constexpr LogSeverity kLogFatal = 4
 
constexpr LogSeverity kLogNumSeverities = 5
 
constexpr LogSeverity LOG_INFO = kLogInfo
 
constexpr LogSeverity LOG_WARNING = kLogWarning
 
constexpr LogSeverity LOG_ERROR = kLogError
 
constexpr LogSeverity LOG_IMPORTANT = kLogImportant
 
constexpr LogSeverity LOG_FATAL = kLogFatal
 
const LogSeverity kLogDFatal = kLogFatal
 
const LogSeverity LOG_DFATAL = kLogDFatal
 
static thread_local std::unique_ptr< MessageLooptls_message_loop
 
static thread_local std::unique_ptr< TaskSourceGradeHolder > tls_task_source_grade
 
static const TaskQueueId kUnmerged = TaskQueueId(TaskQueueId::kUnmerged)
 
std::once_flag gCPUTrackerFlag
 
static CPUSpeedTrackergCPUTracker
 
static constexpr int kClockType = CLOCK_MONOTONIC
 
static constexpr CFTimeInterval kDistantFuture = 1.0e10
 
thread_local std::map< intptr_t, fit::closure > tTaskObservers
 
static constexpr int kClockType = CLOCK_MONOTONIC
 
constexpr Milliseconds kDefaultFrameBudget = Milliseconds(1s) / 60
 

Typedef Documentation

◆ Base32DecodeConverter

using fml::Base32DecodeConverter = typedef BitConverter<5, 8, 16>

Definition at line 49 of file base32.h.

◆ Base32EncodeConverter

using fml::Base32EncodeConverter = typedef BitConverter<8, 5, 16>

Definition at line 50 of file base32.h.

◆ closure

using fml::closure = typedef std::function<void()>

Definition at line 14 of file closure.h.

◆ DelayedTaskQueue

using fml::DelayedTaskQueue = typedef std::priority_queue<DelayedTask, std::deque<DelayedTask>, std::greater<DelayedTask> >

Definition at line 42 of file delayed_task.h.

◆ FileVisitor

using fml::FileVisitor = typedef std::function<bool(const fml::UniqueFD& directory, const std::string& filename)>

Signature of a callback on a file in directory with filename (relative to directory). The returned bool should be false if and only if further traversal should be stopped. For example, a file-search visitor may return false when the file is found so no more visiting is needed.

Definition at line 97 of file file.h.

◆ LogSeverity

typedef int fml::LogSeverity

Definition at line 11 of file log_level.h.

◆ Milliseconds

using fml::Milliseconds = typedef std::chrono::duration<double, std::milli>

Definition at line 18 of file time_delta.h.

◆ RasterThreadMergerId

Definition at line 19 of file shared_thread_merger.h.

◆ ThreadFunction

typedef std::function<void()> fml::ThreadFunction

Definition at line 27 of file thread.cc.

◆ TrieNode

Definition at line 10 of file ascii_trie.cc.

◆ TrieNodePtr

Definition at line 11 of file ascii_trie.cc.

◆ UniqueDir

Definition at line 101 of file unique_fd.h.

◆ UniqueFD

Definition at line 100 of file unique_fd.h.

◆ Utf16StringConverter

using fml::Utf16StringConverter = typedef std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>

Definition at line 23 of file string_conversion.cc.

◆ WideStringConverter

using fml::WideStringConverter = typedef std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>

Definition at line 13 of file wstring_conversion.cc.

Enumeration Type Documentation

◆ CpuAffinity

enum class fml::CpuAffinity
strong

The CPU Affinity provides a hint to the operating system on which cores a particular thread should be scheduled on. The operating system may or may not honor these requests.

Enumerator
kPerformance 

Request CPU affinity for the performance cores.

     Generally speaking, only the UI and Raster thread should
     use this option. 
kEfficiency 

Request CPU affinity for the efficiency cores.

kNotPerformance 

Request affinity for all non-performance cores.

kNotEfficiency 

Request affinity for all non-efficiency cores.

Definition at line 18 of file cpu_affinity.h.

18 {
19 /// @brief Request CPU affinity for the performance cores.
20 ///
21 /// Generally speaking, only the UI and Raster thread should
22 /// use this option.
24
25 /// @brief Request CPU affinity for the efficiency cores.
27
28 /// @brief Request affinity for all non-performance cores.
30
31 /// @brief Request affinity for all non-efficiency cores.
33};
@ kNotEfficiency
Request affinity for all non-efficiency cores.
@ kPerformance
Request CPU affinity for the performance cores.
@ kEfficiency
Request CPU affinity for the efficiency cores.
@ kNotPerformance
Request affinity for all non-performance cores.

◆ FilePermission

enum class fml::FilePermission
strong
Enumerator
kRead 
kWrite 
kReadWrite 

Definition at line 24 of file file.h.

◆ FlushType

enum class fml::FlushType
strong
Enumerator
kSingle 
kAll 

Definition at line 54 of file message_loop_task_queues.h.

54 {
55 kSingle,
56 kAll,
57};

◆ RasterThreadStatus

enum class fml::RasterThreadStatus
strong
Enumerator
kRemainsMerged 
kRemainsUnmerged 
kUnmergedNow 

Definition at line 20 of file raster_thread_merger.h.

◆ StatusCode

enum class fml::StatusCode
strong
Enumerator
kOk 
kCancelled 
kUnknown 
kInvalidArgument 
kDeadlineExceeded 
kNotFound 
kAlreadyExists 
kPermissionDenied 
kResourceExhausted 
kFailedPrecondition 
kAborted 
kOutOfRange 
kUnimplemented 
kInternal 
kUnavailable 
kDataLoss 
kUnauthenticated 

Definition at line 12 of file status.h.

◆ TaskSourceGrade

enum class fml::TaskSourceGrade
strong

Categories of work dispatched to MessageLoopTaskQueues dispatcher. By specifying the TaskSourceGrade, you indicate the task's importance to the dispatcher.

Enumerator
kUserInteraction 

This TaskSourceGrade indicates that a task is critical to user interaction.

kDartEventLoop 

This TaskSourceGrade indicates that a task corresponds to servicing a dart event loop task. These aren't critical to user interaction.

kUnspecified 

The absence of a specialized TaskSourceGrade.

Definition at line 15 of file task_source_grade.h.

15 {
16 /// This `TaskSourceGrade` indicates that a task is critical to user
17 /// interaction.
19 /// This `TaskSourceGrade` indicates that a task corresponds to servicing a
20 /// dart event loop task. These aren't critical to user interaction.
22 /// The absence of a specialized `TaskSourceGrade`.
24};
@ kUnspecified
The absence of a specialized TaskSourceGrade.

Function Documentation

◆ AcquireLooperForThread()

static ALooper * fml::AcquireLooperForThread ( )
static

Definition at line 16 of file message_loop_android.cc.

16 {
17 ALooper* looper = ALooper_forThread();
18
19 if (looper == nullptr) {
20 // No looper has been configured for the current thread. Create one and
21 // return the same.
22 looper = ALooper_prepare(0);
23 }
24
25 // The thread already has a looper. Acquire a reference to the same and return
26 // it.
27 ALooper_acquire(looper);
28 return looper;
29}

◆ AdoptRef()

template<typename T >
RefPtr< T > fml::AdoptRef ( T *  ptr)
inline

◆ AndroidEfficiencyCoreCount()

std::optional< size_t > fml::AndroidEfficiencyCoreCount ( )

Android specific implementation of EfficiencyCoreCount.

Definition at line 50 of file cpu_affinity.cc.

50 {
51 if (!SetUpCPUTracker()) {
52 return true;
53 }
54 auto result = gCPUTracker->GetIndices(CpuAffinity::kEfficiency).size();
55 FML_DCHECK(result > 0);
56 return result;
57}
const std::vector< size_t > & GetIndices(CpuAffinity affinity) const
Return the set of CPU indices for the requested CPU affinity.
#define FML_DCHECK(condition)
Definition logging.h:122
bool SetUpCPUTracker()

References FML_DCHECK, gCPUTracker, fml::CPUSpeedTracker::GetIndices(), kEfficiency, and SetUpCPUTracker().

Referenced by EfficiencyCoreCount().

◆ AndroidRequestAffinity()

bool fml::AndroidRequestAffinity ( CpuAffinity  affinity)

Android specific implementation of RequestAffinity.

Definition at line 59 of file cpu_affinity.cc.

59 {
60 if (!SetUpCPUTracker()) {
61 return true;
62 }
63
64 cpu_set_t set;
65 CPU_ZERO(&set);
66 for (const auto index : gCPUTracker->GetIndices(affinity)) {
67 CPU_SET(index, &set);
68 }
69 return sched_setaffinity(gettid(), sizeof(set), &set) == 0;
70}

References gCPUTracker, fml::CPUSpeedTracker::GetIndices(), and SetUpCPUTracker().

Referenced by RequestAffinity().

◆ Backtrace()

static int fml::Backtrace ( void **  symbols,
int  size 
)
static

Definition at line 35 of file backtrace.cc.

35 {
36#if FML_OS_WIN
37 return CaptureStackBackTrace(0, size, symbols, NULL);
38#else
39 return ::backtrace(symbols, size);
40#endif // FML_OS_WIN
41}

Referenced by BacktraceHere().

◆ BacktraceHere()

std::string fml::BacktraceHere ( size_t  offset = 0)

Definition at line 43 of file backtrace.cc.

43 {
44 constexpr size_t kMaxFrames = 256;
45 void* symbols[kMaxFrames];
46 const auto available_frames = Backtrace(symbols, kMaxFrames);
47 if (available_frames <= 0) {
48 return "";
49 }
50
51 // Exclude here.
52 offset += 2;
53
54 std::stringstream stream;
55 for (int i = offset; i < available_frames; ++i) {
56 stream << "Frame " << i - offset << ": " << symbols[i] << " "
57 << GetSymbolName(symbols[i]) << std::endl;
58 }
59 return stream.str();
60}
static int Backtrace(void **symbols, int size)
Definition backtrace.cc:35

References Backtrace(), GetSymbolName(), and i.

Referenced by flutter::testing::ThreadCheckingAssetResolver::GetAsMapping(), SignalHandler(), and fml::testing::TEST().

◆ Base32Decode()

std::pair< bool, std::string > fml::Base32Decode ( const std::string &  input)

Definition at line 55 of file base32.cc.

55 {
56 std::string result;
57 Base32DecodeConverter converter;
58 for (char c : input) {
59 int map_index = c - '2';
60 if (map_index < 0 || map_index >= kDecodeMapSize ||
61 kDecodeMap[map_index] == -1) {
62 return {false, result};
63 }
64 converter.Append(kDecodeMap[map_index]);
65 if (converter.CanExtract()) {
66 result.push_back(converter.Extract());
67 }
68 }
69 if (converter.Peek() != 0) {
70 // The padding should always be zero. Return false if not.
71 return {false, result};
72 }
73 return {true, result};
74}
static int input(yyscan_t yyscanner)
BitConverter< 5, 8, 16 > Base32DecodeConverter
Definition base32.h:49

References input(), kDecodeMap, and kDecodeMapSize.

Referenced by flutter::ParseBase32(), TEST(), TEST(), and TEST().

◆ Base32Encode()

std::pair< bool, std::string > fml::Base32Encode ( std::string_view  input)

Definition at line 15 of file base32.cc.

15 {
16 if (input.empty()) {
17 return {true, ""};
18 }
19
20 if (input.size() > std::numeric_limits<size_t>::max() / 8) {
21 return {false, ""};
22 }
23
24 std::string output;
25 const size_t encoded_length = (input.size() * 8 + 4) / 5;
26 output.reserve(encoded_length);
27
28 Base32EncodeConverter converter;
29 converter.Append(static_cast<uint8_t>(input[0]));
30 size_t next_byte_index = 1;
31
32 while (converter.CanExtract()) {
33 output.push_back(kEncoding[converter.Extract()]);
34 if (converter.CanAppend() && next_byte_index < input.size()) {
35 converter.Append(static_cast<uint8_t>(input[next_byte_index++]));
36 }
37 }
38
39 if (converter.BitsAvailable() > 0) {
40 output.push_back(kEncoding[converter.Peek()]);
41 }
42
43 return {true, output};
44}
BitConverter< 8, 5, 16 > Base32EncodeConverter
Definition base32.h:50

References input(), and kEncoding.

Referenced by TEST(), TEST(), and TEST().

◆ BigEndianToArch()

template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T fml::BigEndianToArch ( n)
constexpr

Convert a known big endian value to match the endianness of the current architecture. This is effectively a cross platform ntohl/ntohs (as network byte order is always Big Endian). The given value must be an integral type of size 1, 2, 4, or 8.

Definition at line 59 of file endianness.h.

59 {
60#if FML_ARCH_CPU_LITTLE_ENDIAN
61 return ByteSwap<T>(n);
62#else
63 return n;
64#endif
65}

Referenced by fml::testing::TEST().

◆ ByteSwap()

template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T fml::ByteSwap ( n)
constexpr

Flips the endianness of the given value. The given value must be an integral type of size 1, 2, 4, or 8.

Definition at line 40 of file endianness.h.

40 {
41 if constexpr (sizeof(T) == 1) {
42 return n;
43 } else if constexpr (sizeof(T) == 2) {
44 return static_cast<T>(FML_BYTESWAP_16((uint16_t)n));
45 } else if constexpr (sizeof(T) == 4) {
46 return static_cast<T>(FML_BYTESWAP_32((uint32_t)n));
47 } else if constexpr (sizeof(T) == 8) {
48 return static_cast<T>(FML_BYTESWAP_64((uint64_t)n));
49 } else {
50 static_assert(!sizeof(T), "Unsupported size");
51 }
52}
#define FML_BYTESWAP_64(n)
Definition endianness.h:24
#define FML_BYTESWAP_16(n)
Definition endianness.h:22
#define FML_BYTESWAP_32(n)
Definition endianness.h:23

References FML_BYTESWAP_16, FML_BYTESWAP_32, and FML_BYTESWAP_64.

◆ ChronoTicksSinceEpoch()

◆ CommandLineFromArgcArgv()

CommandLine fml::CommandLineFromArgcArgv ( int  argc,
const char *const *  argv 
)
inline

Definition at line 231 of file command_line.h.

231 {
232 return CommandLineFromIterators(argv, argv + argc);
233}
char ** argv
Definition library.h:9
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)

References argv, and CommandLineFromIterators().

Referenced by CommandLineFromPlatformOrArgcArgv(), FlutterEngineInitialize(), main(), and flutter::testing::SetArgsForProcess().

◆ CommandLineFromInitializerList()

template<typename StringType >
CommandLine fml::CommandLineFromInitializerList ( std::initializer_list< StringType >  argv)
inline

◆ CommandLineFromIterators()

template<typename InputIterator >
CommandLine fml::CommandLineFromIterators ( InputIterator  first,
InputIterator  last 
)
inline

Definition at line 202 of file command_line.h.

203 {
204 return CommandLineFromIteratorsFindFirstPositionalArg<InputIterator>(
205 first, last, nullptr);
206}

Referenced by CommandLineFromArgcArgv(), CommandLineFromInitializerList(), flutter::CommandLineFromNSProcessInfo(), and dart_runner::IsTestProgram().

◆ CommandLineFromIteratorsFindFirstPositionalArg()

template<typename InputIterator >
CommandLine fml::CommandLineFromIteratorsFindFirstPositionalArg ( InputIterator  first,
InputIterator  last,
InputIterator *  first_positional_arg 
)
inline

Definition at line 180 of file command_line.h.

183 {
184 if (first_positional_arg) {
185 *first_positional_arg = last;
186 }
187 internal::CommandLineBuilder builder;
188 for (auto it = first; it < last; ++it) {
189 if (builder.ProcessArg(*it)) {
190 if (first_positional_arg) {
191 *first_positional_arg = it;
192 }
193 }
194 }
195 return builder.Build();
196}

References fml::internal::CommandLineBuilder::Build(), and fml::internal::CommandLineBuilder::ProcessArg().

◆ CommandLineFromIteratorsWithArgv0()

template<typename InputIterator >
CommandLine fml::CommandLineFromIteratorsWithArgv0 ( const std::string &  argv0,
InputIterator  first,
InputIterator  last 
)
inline

Definition at line 212 of file command_line.h.

214 {
216 builder.ProcessArg(argv0);
217 for (auto it = first; it < last; ++it) {
218 builder.ProcessArg(*it);
219 }
220 return builder.Build();
221}
bool ProcessArg(const std::string &arg)

References fml::internal::CommandLineBuilder::Build(), and fml::internal::CommandLineBuilder::ProcessArg().

Referenced by impeller::compiler::testing::TEST().

◆ CommandLineFromPlatform()

std::optional< CommandLine > fml::CommandLineFromPlatform ( )

Definition at line 9 of file command_line_posix.cc.

9 {
10 return std::nullopt;
11}

Referenced by CommandLineFromPlatformOrArgcArgv().

◆ CommandLineFromPlatformOrArgcArgv()

CommandLine fml::CommandLineFromPlatformOrArgcArgv ( int  argc,
const char *const *  argv 
)
inline

Definition at line 240 of file command_line.h.

241 {
242 auto command_line = CommandLineFromPlatform();
243 if (command_line.has_value()) {
244 return *command_line;
245 }
246 return CommandLineFromArgcArgv(argc, argv);
247}
std::optional< CommandLine > CommandLineFromPlatform()

References argv, CommandLineFromArgcArgv(), and CommandLineFromPlatform().

Referenced by benchmarking::Main(), main(), main(), and main().

◆ CommandLineToArgv()

std::vector< std::string > fml::CommandLineToArgv ( const CommandLine command_line)

Definition at line 141 of file command_line.cc.

141 {
142 if (!command_line.has_argv0()) {
143 return std::vector<std::string>();
144 }
145
146 std::vector<std::string> argv;
147 const std::vector<CommandLine::Option>& options = command_line.options();
148 const std::vector<std::string>& positional_args =
149 command_line.positional_args();
150 // Reserve space for argv[0], options, maybe a "--" (if needed), and the
151 // positional arguments.
152 argv.reserve(1u + options.size() + 1u + positional_args.size());
153
154 argv.push_back(command_line.argv0());
155 for (const auto& option : options) {
156 if (option.value.empty()) {
157 argv.push_back("--" + option.name);
158 } else {
159 argv.push_back("--" + option.name + "=" + option.value);
160 }
161 }
162
163 if (!positional_args.empty()) {
164 // Insert a "--" if necessary.
165 if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
166 positional_args[0][1] == '-') {
167 argv.push_back("--");
168 }
169
170 argv.insert(argv.end(), positional_args.begin(), positional_args.end());
171 }
172
173 return argv;
174}
const std::string & argv0() const
const std::vector< Option > & options() const
const std::vector< std::string > & positional_args() const
bool has_argv0() const
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size

References argv, fml::CommandLine::argv0(), fml::CommandLine::has_argv0(), fml::CommandLine::options(), and fml::CommandLine::positional_args().

◆ CreateDirectory() [1/2]

fml::UniqueFD fml::CreateDirectory ( const fml::UniqueFD base_directory,
const std::vector< std::string > &  components,
FilePermission  permission 
)

Definition at line 33 of file file.cc.

35 {
36 if (!IsDirectory(base_directory)) {
37 return {};
38 }
39
40 if (components.empty()) {
41 return {};
42 }
43
44 return CreateDirectory(base_directory, components, permission, 0);
45}
bool IsDirectory(const fml::UniqueFD &directory)
#define CreateDirectory

References CreateDirectory, and IsDirectory().

◆ CreateDirectory() [2/2]

static fml::UniqueFD fml::CreateDirectory ( const fml::UniqueFD base_directory,
const std::vector< std::string > &  components,
FilePermission  permission,
size_t  index 
)
static

Definition at line 12 of file file.cc.

15 {
16 FML_DCHECK(index <= components.size());
17
18 const char* file_path = components[index].c_str();
19
20 auto directory = OpenDirectory(base_directory, file_path, true, permission);
21
22 if (!directory.is_valid()) {
23 return {};
24 }
25
26 if (index == components.size() - 1) {
27 return directory;
28 }
29
30 return CreateDirectory(directory, components, permission, index + 1);
31}
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition file_posix.cc:97

References CreateDirectory, FML_DCHECK, and OpenDirectory().

Referenced by TEST(), TEST(), TEST(), impeller::compiler::testing::TEST(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().

◆ CreateTemporaryDirectory()

std::string fml::CreateTemporaryDirectory ( )

Definition at line 25 of file file_posix.cc.

25 {
26 char directory_name[] = "/tmp/flutter_XXXXXXXX";
27 auto* result = ::mkdtemp(directory_name);
28 if (result == nullptr) {
29 return "";
30 }
31 return {result};
32}

Referenced by TEST().

◆ CurrentMessageLoopAddAfterTaskObserver()

fml::TaskQueueId fml::CurrentMessageLoopAddAfterTaskObserver ( intptr_t  key,
fit::closure  observer 
)

Definition at line 19 of file task_observers.cc.

20 {
21 if (observer) {
22 tTaskObservers[key] = std::move(observer);
23 }
25}
static TaskQueueId Invalid()
thread_local std::map< intptr_t, fit::closure > tTaskObservers

References fml::TaskQueueId::Invalid(), key, and tTaskObservers.

◆ CurrentMessageLoopRemoveAfterTaskObserver()

void fml::CurrentMessageLoopRemoveAfterTaskObserver ( fml::TaskQueueId  queue_id,
intptr_t  key 
)

Definition at line 27 of file task_observers.cc.

28 {
29 tTaskObservers.erase(key);
30}

References key, and tTaskObservers.

◆ Duplicate()

fml::UniqueFD fml::Duplicate ( fml::UniqueFD::element_type  descriptor)

Definition at line 123 of file file_posix.cc.

123 {
124 return fml::UniqueFD{FML_HANDLE_EINTR(::dup(descriptor))};
125}
#define FML_HANDLE_EINTR(x)

References FML_HANDLE_EINTR.

Referenced by flutter::RunConfiguration::InferFromSettings(), and flutter::RunTester().

◆ EfficiencyCoreCount()

std::optional< size_t > fml::EfficiencyCoreCount ( )

Request count of efficiency cores.

   Efficiency cores are defined as those with the lowest reported
   cpu_max_freq. If the CPU speed could not be determined, or if all
   cores have the same reported speed then this returns std::nullopt.
   That is, the result will never be 0. 

Definition at line 19 of file cpu_affinity.cc.

19 {
20#ifdef FML_OS_ANDROID
22#else
23 return std::nullopt;
24#endif
25}
std::optional< size_t > AndroidEfficiencyCoreCount()
Android specific implementation of EfficiencyCoreCount.

References AndroidEfficiencyCoreCount().

Referenced by fml::testing::TEST().

◆ erase_if()

template<class Collection = std::unordered_map<class Key, class Value, class Hash, class Equal>>
void fml::erase_if ( Collection &  container,
const std::function< bool(typename Collection::iterator)> &  predicate 
)

Definition at line 16 of file container.h.

18 {
19 auto it = container.begin();
20 while (it != container.end()) {
21 if (predicate(it)) {
22 it = container.erase(it);
23 continue;
24 }
25 it++;
26 }
27}

◆ ExecuteAfterTaskObservers()

void fml::ExecuteAfterTaskObservers ( )

Definition at line 13 of file task_observers.cc.

13 {
14 for (const auto& callback : tTaskObservers) {
15 callback.second();
16 }
17}
FlutterDesktopBinaryReply callback

References callback, and tTaskObservers.

◆ FileExists()

bool fml::FileExists ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 183 of file file_posix.cc.

183 {
184 if (!base_directory.is_valid()) {
185 return false;
186 }
187
188 return ::faccessat(base_directory.get(), path, F_OK, 0) == 0;
189}
bool is_valid() const
const T & get() const

References fml::UniqueObject< T, Traits >::get(), and fml::UniqueObject< T, Traits >::is_valid().

Referenced by impeller::FindSwiftShaderICDAtKnownPaths(), OpenDirectory(), OpenFile(), TEST(), TEST(), TEST(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ GetAbsolutePath()

static std::string fml::GetAbsolutePath ( const fml::UniqueFD base_directory,
const char *  subpath 
)
static

Definition at line 50 of file file_win.cc.

51 {
52 std::string path;
53 if (IsAbsolutePath(subpath)) {
54 path = subpath;
55 } else {
56 std::stringstream stream;
57 stream << GetFullHandlePath(base_directory) << "\\" << subpath;
58 path = stream.str();
59 }
60 std::replace(path.begin(), path.end(), '/', '\\');
61 return path;
62}
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
Definition switch_defs.h:52
static bool IsAbsolutePath(const char *path)
Definition file_win.cc:37

References GetFullHandlePath(), and IsAbsolutePath().

Referenced by GetFileAttributesForUtf8Path().

◆ GetCurrentProcId()

int fml::GetCurrentProcId ( )

Definition at line 9 of file process_posix.cc.

9 {
10 return static_cast<int>(getpid());
11}

Referenced by impeller::compiler::testing::GetIntermediatesPath().

◆ GetDesiredAccessFlags()

static DWORD fml::GetDesiredAccessFlags ( FilePermission  permission)
static

Definition at line 73 of file file_win.cc.

73 {
74 switch (permission) {
75 case FilePermission::kRead:
76 return GENERIC_READ;
77 case FilePermission::kWrite:
78 return GENERIC_WRITE;
79 case FilePermission::kReadWrite:
80 return GENERIC_READ | GENERIC_WRITE;
81 }
82 return GENERIC_READ;
83}

References kRead, kReadWrite, and kWrite.

◆ GetFileAttributesForUtf8Path() [1/2]

static DWORD fml::GetFileAttributesForUtf8Path ( const char *  absolute_path)
static

Definition at line 97 of file file_win.cc.

97 {
98 return ::GetFileAttributes(Utf8ToWideString(absolute_path).c_str());
99}
std::wstring Utf8ToWideString(const std::string_view str)

References Utf8ToWideString().

Referenced by GetFileAttributesForUtf8Path().

◆ GetFileAttributesForUtf8Path() [2/2]

static DWORD fml::GetFileAttributesForUtf8Path ( const fml::UniqueFD base_directory,
const char *  path 
)
static

Definition at line 101 of file file_win.cc.

102 {
103 std::string full_path = GetAbsolutePath(base_directory, path);
104 return GetFileAttributesForUtf8Path(full_path.c_str());
105}
static std::string GetAbsolutePath(const fml::UniqueFD &base_directory, const char *subpath)
Definition file_win.cc:50
static DWORD GetFileAttributesForUtf8Path(const char *absolute_path)
Definition file_win.cc:97

References GetAbsolutePath(), and GetFileAttributesForUtf8Path().

◆ GetFullHandlePath()

static std::string fml::GetFullHandlePath ( const fml::UniqueFD handle)
static

Definition at line 27 of file file_win.cc.

27 {
28 wchar_t buffer[MAX_PATH] = {0};
29 const DWORD buffer_size = ::GetFinalPathNameByHandle(
30 handle.get(), buffer, MAX_PATH, FILE_NAME_NORMALIZED);
31 if (buffer_size == 0) {
32 return {};
33 }
34 return WideStringToUtf8({buffer, buffer_size});
35}
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 disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
std::string WideStringToUtf8(const std::wstring_view str)
#define MAX_PATH
unsigned long DWORD

References fml::UniqueObject< T, Traits >::get(), MAX_PATH, and WideStringToUtf8().

Referenced by GetAbsolutePath().

◆ GetLastErrorMessage()

std::string fml::GetLastErrorMessage ( )

Definition at line 15 of file errors_win.cc.

15 {
16 DWORD last_error = ::GetLastError();
17 if (last_error == 0) {
18 return {};
19 }
20
21 const DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
22 FORMAT_MESSAGE_FROM_SYSTEM |
23 FORMAT_MESSAGE_IGNORE_INSERTS;
24
25 wchar_t* buffer = nullptr;
26 size_t size = ::FormatMessage(
27 flags, // dwFlags
28 NULL, // lpSource
29 last_error, // dwMessageId
30 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // dwLanguageId
31 (LPWSTR)&buffer, // lpBuffer
32 0, // nSize
33 NULL // Arguments
34 );
35
36 std::wstring message(buffer, size);
37
38 ::LocalFree(buffer);
39
40 std::wstringstream stream;
41 stream << message << " (" << last_error << ").";
42
43 return WideStringToUtf8(stream.str());
44}
G_BEGIN_DECLS GBytes * message
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)

References GetLastError(), message, and WideStringToUtf8().

◆ GetLogSettings()

LogSettings fml::GetLogSettings ( )

Definition at line 32 of file log_settings.cc.

32 {
33 return state::g_log_settings;
34}

References fml::state::g_log_settings.

Referenced by fml::ScopedSetLogSettings::ScopedSetLogSettings().

◆ GetMinLogLevel()

int fml::GetMinLogLevel ( )

Definition at line 36 of file log_settings.cc.

36 {
37 return std::min(state::g_log_settings.min_log_level, kLogFatal);
38}

References fml::state::g_log_settings, and kLogFatal.

Referenced by GetVlogVerbosity(), ShouldCreateLogMessage(), fml::testing::TEST_F(), and fml::testing::TEST_F().

◆ GetShareFlags()

static DWORD fml::GetShareFlags ( FilePermission  permission)
static

Definition at line 85 of file file_win.cc.

85 {
86 switch (permission) {
87 case FilePermission::kRead:
88 return FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
89 case FilePermission::kWrite:
90 return 0;
91 case FilePermission::kReadWrite:
92 return 0;
93 }
94 return FILE_SHARE_READ;
95}

References kRead, kReadWrite, and kWrite.

◆ GetSymbolName()

static std::string fml::GetSymbolName ( void *  symbol)
static

Definition at line 27 of file backtrace.cc.

27 {
28 char name[1024];
29 if (!absl::Symbolize(symbol, name, sizeof(name))) {
30 return kKUnknownFrameName;
31 }
32 return name;
33}
const char * name
Definition fuchsia.cc:49
static std::string kKUnknownFrameName
Definition backtrace.cc:25

References kKUnknownFrameName, and name.

Referenced by BacktraceHere().

◆ GetTemporaryDirectoryPath()

static std::wstring fml::GetTemporaryDirectoryPath ( )
static

Definition at line 64 of file file_win.cc.

64 {
65 wchar_t wchar_path[MAX_PATH];
66 auto result_size = ::GetTempPath(MAX_PATH, wchar_path);
67 if (result_size > 0) {
68 return {wchar_path, result_size};
69 }
70 return {};
71}

References MAX_PATH.

◆ GetVlogVerbosity()

int fml::GetVlogVerbosity ( )

Definition at line 212 of file logging.cc.

212 {
213 return std::max(-1, kLogInfo - GetMinLogLevel());
214}
int GetMinLogLevel()

References GetMinLogLevel(), and kLogInfo.

◆ HashCombine() [1/2]

◆ HashCombine() [2/2]

template<class... Type>
constexpr std::size_t fml::HashCombine ( const Type &...  args)
constexpr

Definition at line 30 of file hash_combine.h.

30 {
31 std::size_t seed = HashCombine();
32 HashCombineSeed(seed, args...);
33 return seed;
34}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
constexpr std::size_t HashCombine()
constexpr void HashCombineSeed(std::size_t &seed, const Type &arg)

References args, HashCombine(), and HashCombineSeed().

◆ HashCombineSeed() [1/2]

template<class Type >
constexpr void fml::HashCombineSeed ( std::size_t &  seed,
const Type &  arg 
)
constexpr

◆ HashCombineSeed() [2/2]

template<class Type , class... Rest>
constexpr void fml::HashCombineSeed ( std::size_t &  seed,
const Type &  arg,
const Rest &...  other_args 
)
constexpr

Definition at line 18 of file hash_combine.h.

20 {
21 HashCombineSeed(seed, arg);
22 HashCombineSeed(seed, other_args...);
23}

References HashCombineSeed().

◆ HexEncode()

std::string fml::HexEncode ( std::string_view  input)

Definition at line 14 of file hex_codec.cc.

14 {
15 std::string result;
16 result.reserve(input.size() * 2);
17 for (char c : input) {
18 uint8_t b = static_cast<uint8_t>(c);
19 result.push_back(kEncoding[b >> 4]);
20 result.push_back(kEncoding[b & 0xF]);
21 }
22 return result;
23}

References input(), and kEncoding.

Referenced by flutter::PersistentCache::SkKeyToFilePath(), and TEST().

◆ InitCPUInfo()

void fml::InitCPUInfo ( size_t  cpu_count)

Definition at line 26 of file cpu_affinity.cc.

26 {
27 std::vector<CpuIndexAndSpeed> cpu_speeds;
28
29 for (auto i = 0u; i < cpu_count; i++) {
30 auto path = "/sys/devices/system/cpu/cpu" + std::to_string(i) +
31 "/cpufreq/cpuinfo_max_freq";
32 auto speed = ReadIntFromFile(path);
33 if (speed.has_value()) {
34 cpu_speeds.push_back({.index = i, .speed = speed.value()});
35 }
36 }
37 gCPUTracker = new CPUSpeedTracker(cpu_speeds);
38}
std::optional< int64_t > ReadIntFromFile(const std::string &path)
static CPUSpeedTracker * gCPUTracker

References gCPUTracker, i, and ReadIntFromFile().

Referenced by SetUpCPUTracker().

◆ InstallCrashHandler()

void fml::InstallCrashHandler ( )

Definition at line 126 of file backtrace.cc.

126 {
127#if FML_OS_WIN
128 if (!IsDebuggerPresent()) {
129 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
130 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
131 }
132#endif
133 auto exe_path = fml::paths::GetExecutablePath();
134 if (exe_path.first) {
135 absl::InitializeSymbolizer(exe_path.second.c_str());
136 }
138}
std::pair< bool, std::string > GetExecutablePath()
static void ToggleSignalHandlers(bool set)
Definition backtrace.cc:115

References fml::paths::GetExecutablePath(), and ToggleSignalHandlers().

Referenced by impeller::compiler::Main(), benchmarking::Main(), and main().

◆ IsAbsolutePath()

static bool fml::IsAbsolutePath ( const char *  path)
static

Definition at line 37 of file file_win.cc.

37 {
38 if (path == nullptr || strlen(path) == 0) {
39 return false;
40 }
41
42 auto wpath = Utf8ToWideString({path});
43 if (wpath.empty()) {
44 return false;
45 }
46
47 return ::PathIsRelative(wpath.c_str()) == FALSE;
48}

References Utf8ToWideString().

Referenced by GetAbsolutePath().

◆ IsCrashHandlingSupported()

bool fml::IsCrashHandlingSupported ( )

Definition at line 140 of file backtrace.cc.

140 {
141 return true;
142}

Referenced by fml::testing::TEST().

◆ IsDirectory() [1/2]

bool fml::IsDirectory ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 141 of file file_posix.cc.

141 {
142 UniqueFD file = OpenFileReadOnly(base_directory, path);
143 return (file.is_valid() && IsDirectory(file));
144}
fml::UniqueFD OpenFileReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition file.cc:92

References fml::UniqueObject< T, Traits >::is_valid(), IsDirectory(), and OpenFileReadOnly().

◆ IsDirectory() [2/2]

bool fml::IsDirectory ( const fml::UniqueFD directory)

Definition at line 127 of file file_posix.cc.

127 {
128 if (!directory.is_valid()) {
129 return false;
130 }
131
132 struct stat stat_result = {};
133
134 if (::fstat(directory.get(), &stat_result) != 0) {
135 return false;
136 }
137
138 return S_ISDIR(stat_result.st_mode);
139}

References fml::UniqueObject< T, Traits >::get(), and fml::UniqueObject< T, Traits >::is_valid().

Referenced by CreateDirectory(), flutter::DirectoryAssetBundle::DirectoryAssetBundle(), IsDirectory(), RemoveFilesInDirectory(), and VisitFilesRecursively().

◆ IsExecutable()

static bool fml::IsExecutable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 33 of file mapping_win.cc.

34 {
35 for (auto protection : protection_flags) {
36 if (protection == FileMapping::Protection::kExecute) {
37 return true;
38 }
39 }
40 return false;
41}

References fml::FileMapping::kExecute.

◆ IsFile()

bool fml::IsFile ( const std::string &  path)

Definition at line 146 of file file_posix.cc.

146 {
147 struct stat buf;
148 if (stat(path.c_str(), &buf) != 0) {
149 return false;
150 }
151
152 return S_ISREG(buf.st_mode);
153}

Referenced by FlutterEngineCreateAOTData(), FlutterEngineInitialize(), flutter::testing::LoadELFSplitSymbolFromFixturesIfNeccessary(), flutter::testing::LoadELFSymbolFromFixturesIfNeccessary(), impeller::MTLShaderLibraryFromFilePaths(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), TEST(), and TEST().

◆ IsPlatformVersionAtLeast()

bool fml::IsPlatformVersionAtLeast ( size_t  major,
size_t  minor = 0,
size_t  patch = 0 
)

Definition at line 11 of file platform_version.mm.

11 {
12 const NSOperatingSystemVersion version = {
13 .majorVersion = static_cast<NSInteger>(major),
14 .minorVersion = static_cast<NSInteger>(minor),
15 .patchVersion = static_cast<NSInteger>(patch),
16 };
17 return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version];
18}

◆ IsWritable() [1/2]

static bool fml::IsWritable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 39 of file mapping_posix.cc.

40 {
41 for (auto protection : protection_flags) {
42 if (protection == FileMapping::Protection::kWrite) {
43 return true;
44 }
45 }
46 return false;
47}

References fml::FileMapping::kWrite.

Referenced by fml::FileMapping::FileMapping().

◆ IsWritable() [2/2]

static bool fml::IsWritable ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 23 of file mapping_win.cc.

24 {
25 for (auto protection : protection_flags) {
26 if (protection == FileMapping::Protection::kWrite) {
27 return true;
28 }
29 }
30 return false;
31}

References fml::FileMapping::kWrite.

◆ Join()

std::string fml::Join ( const std::vector< std::string > &  vec,
const char *  delim 
)

Definition at line 26 of file string_conversion.cc.

26 {
27 std::stringstream res;
28 for (size_t i = 0; i < vec.size(); ++i) {
29 res << vec[i];
30 if (i < vec.size() - 1) {
31 res << delim;
32 }
33 }
34 return res.str();
35}

References i.

◆ KillProcess()

void fml::KillProcess ( )

◆ KillProcessConstexpr()

constexpr void fml::KillProcessConstexpr ( bool  true_arg)
constexpr

Definition at line 73 of file logging.h.

73 {
74 if (true_arg) {
76 }
77#if defined(_MSC_VER) && !defined(__clang__)
78 __assume(false);
79#else // defined(_MSC_VER) && !defined(__clang__)
80 __builtin_unreachable();
81#endif // defined(_MSC_VER) && !defined(__clang__)
82}
void KillProcess()
Definition logging.cc:220

References KillProcess().

◆ LittleEndianToArch()

template<typename T , class = std::enable_if_t<kIsByteSwappableV<T>>>
constexpr T fml::LittleEndianToArch ( n)
constexpr

Convert a known little endian value to match the endianness of the current architecture. The given value must be an integral type of size 1, 2, 4, or 8.

Definition at line 71 of file endianness.h.

71 {
72#if !FML_ARCH_CPU_LITTLE_ENDIAN
73 return ByteSwap<T>(n);
74#else
75 return n;
76#endif
77}

Referenced by fml::testing::TEST().

◆ MakeCopyable()

template<typename T >
internal::CopyableLambda< T > fml::MakeCopyable ( lambda)

Definition at line 57 of file make_copyable.h.

57 {
58 return internal::CopyableLambda<T>(std::move(lambda));
59}

Referenced by flutter::PlatformMessageResponseAndroid::Complete(), flutter::PlatformMessageResponseDarwin::Complete(), flutter::PlatformMessageResponseAndroid::CompleteEmpty(), flutter::PlatformMessageResponseDarwin::CompleteEmpty(), flutter::ImageDecoderSkia::Decode(), flutter::Picture::DoRasterizeToImage(), flutter::EncodeImage(), flutter::gpu::Context::GetDefaultContext(), flutter::MultiFrameCodec::getNextFrame(), flutter::testing::EmbedderTestContext::GetNextSceneImage(), flutter::PlatformViewEmbedder::EmbedderPlatformMessageHandler::HandlePlatformMessage(), flutter::ImageDecoderImpeller::ImageDecoderImpeller(), InferMetalPlatformViewCreationCallback(), InferOpenGLPlatformViewCreationCallback(), InferSoftwarePlatformViewCreationCallback(), InferVulkanPlatformViewCreationCallback(), flutter::ImmutableBuffer::initFromAsset(), flutter::ImmutableBuffer::initFromFile(), InternalFlutterGpu_CommandBuffer_Submit(), flutter::gpu::Texture::Overwrite(), flutter::PersistentCacheStore(), flutter::PrepareKernelMappings(), impeller::RuntimeStagePlayground::RegisterStage(), flutter::gpu::Shader::RegisterSync(), flutter::testing::RunDartCodeInIsolate(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), flutter::RunTester(), flutter::testing::ShellTest::SendEnginePlatformMessage(), flutter::Spawn(), flutter::gpu::CommandBuffer::Submit(), flutter::AndroidExternalViewEmbedder2::SubmitFlutterView(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), impeller::testing::TEST_P(), flutter_runner::VsyncWaiter::VsyncWaiter(), flutter_runner::Engine::~Engine(), flutter::PlatformMessageResponseDart::~PlatformMessageResponseDart(), and flutter_runner::VsyncWaiter::~VsyncWaiter().

◆ MakeRefCounted()

template<typename T , typename... Args>
RefPtr< T > fml::MakeRefCounted ( Args &&...  args)

◆ NanosSinceEpoch()

template<typename Clock , typename Duration >
static int64_t fml::NanosSinceEpoch ( std::chrono::time_point< Clock, Duration >  time_point)
static

Definition at line 39 of file time_point.cc.

40 {
41 const auto elapsed = time_point.time_since_epoch();
42 return std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
43}

Referenced by fml::TimePoint::CurrentWallTime(), and fml::TimePoint::Now().

◆ OpenDirectory() [1/2]

◆ OpenDirectory() [2/2]

fml::UniqueFD fml::OpenDirectory ( const fml::UniqueFD base_directory,
const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

Definition at line 104 of file file_posix.cc.

107 {
108 if (path == nullptr) {
109 return {};
110 }
111
112 if (create_if_necessary && !FileExists(base_directory, path)) {
113 if (::mkdirat(base_directory.get(), path,
114 ToPosixCreateModeFlags(permission) | S_IXUSR) != 0) {
115 return {};
116 }
117 }
118
120 ::openat(base_directory.get(), path, O_RDONLY | O_DIRECTORY))};
121}
static int ToPosixCreateModeFlags(FilePermission permission)
Definition file_posix.cc:50
bool FileExists(const fml::UniqueFD &base_directory, const char *path)

References FileExists(), FML_HANDLE_EINTR, fml::UniqueObject< T, Traits >::get(), and ToPosixCreateModeFlags().

◆ OpenDirectoryReadOnly()

fml::UniqueFD fml::OpenDirectoryReadOnly ( const fml::UniqueFD base_directory,
const char *  path 
)

Helper method that calls OpenDirectory with create_if_necessary = false and permission = kRead.

Definition at line 97 of file file.cc.

98 {
99 return OpenDirectory(base_directory, path, false, FilePermission::kRead);
100}

References kRead, and OpenDirectory().

Referenced by flutter::PersistentCache::LoadSkSLs(), RemoveFilesInDirectory(), impeller::compiler::Switches::Switches(), flutter::testing::TEST_F(), and VisitFilesRecursively().

◆ OpenFile() [1/2]

fml::UniqueFD fml::OpenFile ( const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

This can open a directory on POSIX, but not on Windows.

Definition at line 66 of file file_posix.cc.

68 {
69 return OpenFile(fml::UniqueFD{AT_FDCWD}, path, create_if_necessary,
70 permission);
71}
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition file_posix.cc:66

References OpenFile().

Referenced by fml::FileMapping::CreateReadExecute(), fml::FileMapping::CreateReadExecute(), fml::FileMapping::CreateReadOnly(), fml::FileMapping::CreateReadOnly(), flutter::ImmutableBuffer::initFromFile(), OpenFile(), OpenFileReadOnly(), flutter::testing::OpenFixture(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), flutter::RunTester(), fml::icu::ICUContext::SetupMapping(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and WriteAtomically().

◆ OpenFile() [2/2]

fml::UniqueFD fml::OpenFile ( const fml::UniqueFD base_directory,
const char *  path,
bool  create_if_necessary,
FilePermission  permission 
)

This can open a directory on POSIX, but not on Windows.

Definition at line 73 of file file_posix.cc.

76 {
77 TRACE_EVENT0("flutter", "fml::OpenFile");
78 if (path == nullptr) {
79 return {};
80 }
81
82 int flags = 0;
83 int mode = 0;
84
85 if (create_if_necessary && !FileExists(base_directory, path)) {
86 flags = ToPosixAccessFlags(permission) | O_CREAT | O_TRUNC;
87 mode = ToPosixCreateModeFlags(permission);
88 } else {
89 flags = ToPosixAccessFlags(permission);
90 mode = 0; // Not creating since it already exists.
91 }
92
93 return fml::UniqueFD{
94 FML_HANDLE_EINTR(::openat(base_directory.get(), path, flags, mode))};
95}
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
static int ToPosixAccessFlags(FilePermission permission)
Definition file_posix.cc:34
#define TRACE_EVENT0(category_group, name)

References FileExists(), FML_HANDLE_EINTR, fml::UniqueObject< T, Traits >::get(), ToPosixAccessFlags(), ToPosixCreateModeFlags(), and TRACE_EVENT0.

◆ OpenFileReadOnly()

fml::UniqueFD fml::OpenFileReadOnly ( const fml::UniqueFD base_directory,
const char *  path 
)

Helper method that calls OpenFile with create_if_necessary = false and permission = kRead.

This can open a directory on POSIX, but not on Windows.

Definition at line 92 of file file.cc.

93 {
94 return OpenFile(base_directory, path, false, FilePermission::kRead);
95}

References kRead, and OpenFile().

Referenced by impeller::compiler::testing::CompilerTest::GetReflectionJson(), impeller::compiler::testing::CompilerTest::GetShaderFile(), IsDirectory(), fml::testing::TEST(), fml::testing::TEST(), and flutter::testing::TEST_F().

◆ operator!=()

template<class T , class Traits >
bool fml::operator!= ( const T &  value,
const UniqueObject< T, Traits > &  object 
)

Definition at line 134 of file unique_object.h.

134 {
135 return !(value == object.get());
136}
int32_t value

References value.

◆ operator==()

template<class T , class Traits >
bool fml::operator== ( const T &  value,
const UniqueObject< T, Traits > &  object 
)

Definition at line 129 of file unique_object.h.

129 {
130 return value == object.get();
131}

References value.

◆ RangeForCharacterAtIndex()

NSRange fml::RangeForCharacterAtIndex ( NSString *  text,
NSUInteger  index 
)

Definition at line 9 of file string_range_sanitization.mm.

9 {
10 if (text == nil || index > text.length) {
11 return NSMakeRange(NSNotFound, 0);
12 }
13 if (index < text.length) {
14 return [text rangeOfComposedCharacterSequenceAtIndex:index];
15 }
16 return NSMakeRange(index, 0);
17}
std::u16string text

References text.

Referenced by TEST(), TEST(), and TEST().

◆ RangeForCharactersInRange()

NSRange fml::RangeForCharactersInRange ( NSString *  text,
NSRange  range 
)

Definition at line 19 of file string_range_sanitization.mm.

19 {
20 if (text == nil || range.location + range.length > text.length) {
21 return NSMakeRange(NSNotFound, 0);
22 }
23 NSRange sanitizedRange = [text rangeOfComposedCharacterSequencesForRange:range];
24 // We don't want to override the length, we just want to make sure we don't
25 // select into the middle of a multi-byte character. Taking the
26 // `sanitizedRange`'s length will end up altering the actual selection.
27 return NSMakeRange(sanitizedRange.location, range.length);
28}

References text.

Referenced by TEST(), and TEST().

◆ ReadIntFromFile()

std::optional< int64_t > fml::ReadIntFromFile ( const std::string &  path)
Note
Visible for testing.

Definition at line 91 of file cpu_affinity.cc.

91 {
92 std::ifstream file;
93 file.open(path.c_str());
94
95 // Dont use stoi because if this data isnt a parseable number then it
96 // will abort, as we compile with exceptions disabled.
97 int64_t speed = 0;
98 file >> speed;
99 if (speed > 0) {
100 return speed;
101 }
102 return std::nullopt;
103}

Referenced by InitCPUInfo(), fml::testing::TEST(), fml::testing::TEST(), and fml::testing::TEST().

◆ Ref()

template<typename T >
RefPtr< T > fml::Ref ( T *  ptr)
inline

◆ RefreshRateToFrameBudget()

template<typename T >
Milliseconds fml::RefreshRateToFrameBudget ( refresh_rate)

Definition at line 24 of file time_delta.h.

24 {
25 return Milliseconds(1s) / refresh_rate;
26}
std::chrono::duration< double, std::milli > Milliseconds
Definition time_delta.h:18

Referenced by flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ RemoveDirectoryRecursively()

bool fml::RemoveDirectoryRecursively ( const fml::UniqueFD parent,
const char *  directory_name 
)

Helper method to recursively remove files and subdirectories inside the directory. The directory itself will also be removed.

Return true if and only if all files have been successfully removed.

Definition at line 120 of file file.cc.

121 {
122 auto dir = fml::OpenDirectory(parent, directory_name, false,
124 return RemoveFilesInDirectory(dir) && UnlinkDirectory(parent, directory_name);
125}
bool RemoveFilesInDirectory(const fml::UniqueFD &directory)
Definition file.cc:102
bool UnlinkDirectory(const char *path)

References kReadWrite, OpenDirectory(), RemoveFilesInDirectory(), and UnlinkDirectory().

◆ RemoveFilesInDirectory()

bool fml::RemoveFilesInDirectory ( const fml::UniqueFD directory)

Helper method to recursively remove files and subdirectories inside the directory. The directory itself will not be removed.

Return true if and only if all files have been successfully removed.

Definition at line 102 of file file.cc.

102 {
103 fml::FileVisitor recursive_cleanup = [&recursive_cleanup](
104 const fml::UniqueFD& directory,
105 const std::string& filename) {
106 bool removed;
107 if (fml::IsDirectory(directory, filename.c_str())) {
108 fml::UniqueFD sub_dir =
109 OpenDirectoryReadOnly(directory, filename.c_str());
110 removed = VisitFiles(sub_dir, recursive_cleanup) &&
111 fml::UnlinkDirectory(directory, filename.c_str());
112 } else {
113 removed = fml::UnlinkFile(directory, filename.c_str());
114 }
115 return removed;
116 };
117 return VisitFiles(directory, recursive_cleanup);
118}
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
fml::UniqueFD OpenDirectoryReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition file.cc:97
bool UnlinkFile(const char *path)
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
Definition file.h:98

References IsDirectory(), OpenDirectoryReadOnly(), UnlinkDirectory(), UnlinkFile(), and VisitFiles().

Referenced by RemoveDirectoryRecursively(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), and fml::ScopedTemporaryDirectory::~ScopedTemporaryDirectory().

◆ RequestAffinity()

bool fml::RequestAffinity ( CpuAffinity  affinity)

Request the given affinity for the current thread.

   Returns true if successfull, or if it was a no-op. This function is
   only supported on Android devices.

   Affinity requests are based on documented CPU speed. This speed data
   is parsed from cpuinfo_max_freq files, see also:
   https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt 

Definition at line 27 of file cpu_affinity.cc.

27 {
28#ifdef FML_OS_ANDROID
29 return AndroidRequestAffinity(affinity);
30#else
31 return true;
32#endif
33}
bool AndroidRequestAffinity(CpuAffinity affinity)
Android specific implementation of RequestAffinity.

References AndroidRequestAffinity().

Referenced by flutter::AndroidPlatformThreadConfigSetter(), and fml::testing::TEST().

◆ SetLogSettings()

void fml::SetLogSettings ( const LogSettings settings)

Definition at line 26 of file log_settings.cc.

26 {
27 // Validate the new settings as we set them.
28 state::g_log_settings.min_log_level =
29 std::min(kLogFatal, settings.min_log_level);
30}
LogSeverity min_log_level

References fml::state::g_log_settings, kLogFatal, and fml::LogSettings::min_log_level.

Referenced by fml::LogInterestListener::HandleInterestChange(), fml::ScopedSetLogSettings::ScopedSetLogSettings(), and fml::ScopedSetLogSettings::~ScopedSetLogSettings().

◆ SetThreadName()

void fml::SetThreadName ( const std::string &  name)

Definition at line 104 of file thread.cc.

104 {
105 if (name == "") {
106 return;
107 }
108#if defined(FML_OS_MACOSX)
109 pthread_setname_np(name.c_str());
110#elif defined(FML_OS_LINUX) || defined(FML_OS_ANDROID)
111 // Linux thread names are limited to 16 characters including the terminating
112 // null.
113 constexpr std::string::size_type kLinuxMaxThreadNameLen = 15;
114 pthread_setname_np(pthread_self(),
115 name.substr(0, kLinuxMaxThreadNameLen).c_str());
116#elif defined(FML_OS_WIN)
117 THREADNAME_INFO info;
118 info.dwType = 0x1000;
119 info.szName = name.c_str();
120 info.dwThreadID = GetCurrentThreadId();
121 info.dwFlags = 0;
122 __try {
123 RaiseException(kVCThreadNameException, 0, sizeof(info) / sizeof(DWORD),
124 reinterpret_cast<DWORD_PTR*>(&info));
125 } __except (EXCEPTION_CONTINUE_EXECUTION) {
126 }
127#elif defined(OS_FUCHSIA)
128 zx::thread::self()->set_property(ZX_PROP_NAME, name.c_str(), name.size());
129#else
130 FML_DLOG(INFO) << "Could not set the thread name to '" << name
131 << "' on this platform.";
132#endif
133}
#define FML_DLOG(severity)
Definition logging.h:121

References FML_DLOG, and name.

Referenced by fml::Thread::SetCurrentThreadName().

◆ SetUpCPUTracker()

bool fml::SetUpCPUTracker ( )

Definition at line 40 of file cpu_affinity.cc.

40 {
41 // Populate CPU Info if uninitialized.
42 auto count = std::thread::hardware_concurrency();
43 std::call_once(gCPUTrackerFlag, [count]() { InitCPUInfo(count); });
44 if (gCPUTracker == nullptr || !gCPUTracker->IsValid()) {
45 return false;
46 }
47 return true;
48}
bool IsValid() const
The class is valid if it has more than one CPU index and a distinct set of efficiency or performance ...
void InitCPUInfo(size_t cpu_count)

References gCPUTracker, gCPUTrackerFlag, InitCPUInfo(), and fml::CPUSpeedTracker::IsValid().

Referenced by AndroidEfficiencyCoreCount(), and AndroidRequestAffinity().

◆ ShouldCreateLogMessage()

bool fml::ShouldCreateLogMessage ( LogSeverity  severity)

Definition at line 216 of file logging.cc.

216 {
217 return severity >= GetMinLogLevel();
218}

References GetMinLogLevel().

Referenced by ShouldCreateLogMessageConstexpr().

◆ ShouldCreateLogMessageConstexpr()

constexpr bool fml::ShouldCreateLogMessageConstexpr ( LogSeverity  severity,
bool  true_arg 
)
constexpr

Definition at line 63 of file logging.h.

64 {
65 if (true_arg) {
66 return ShouldCreateLogMessage(severity);
67 }
68 return false;
69}
bool ShouldCreateLogMessage(LogSeverity severity)
Definition logging.cc:216

References ShouldCreateLogMessage().

◆ SignalHandler()

static void fml::SignalHandler ( int  signal)
static

Definition at line 101 of file backtrace.cc.

101 {
102 // We are a crash signal handler. This can only happen once. Since we don't
103 // want to catch crashes while we are generating the crash reports, disable
104 // all set signal handlers to their default values before reporting the crash
105 // and re-raising the signal.
107
108 FML_LOG(ERROR) << "Caught signal " << SignalNameToString(signal)
109 << " during program execution." << std::endl
110 << BacktraceHere(3);
111
112 ::raise(signal);
113}
#define FML_LOG(severity)
Definition logging.h:101
std::string BacktraceHere(size_t offset)
Definition backtrace.cc:43
static std::string SignalNameToString(int signal)
Definition backtrace.cc:75

References BacktraceHere(), FML_LOG, SignalNameToString(), and ToggleSignalHandlers().

Referenced by ToggleSignalHandlers().

◆ SignalNameToString()

static std::string fml::SignalNameToString ( int  signal)
static

Definition at line 75 of file backtrace.cc.

75 {
76 switch (signal) {
77 case SIGABRT:
78 return "SIGABRT";
79 case SIGFPE:
80 return "SIGFPE";
81 case SIGSEGV:
82 return "SIGSEGV";
83 case SIGTERM:
84 return "SIGTERM";
85#if !FML_OS_WIN
86 case SIGBUS:
87 return "SIGBUS";
88 case SIGSYS:
89 return "SIGSYS";
90 case SIGPIPE:
91 return "SIGPIPE";
92 case SIGALRM:
93 return "SIGALRM";
94#endif // !FML_OS_WIN
95 };
96 return std::to_string(signal);
97}

Referenced by SignalHandler().

◆ strdup()

char * fml::strdup ( const char *  str1)

Definition at line 11 of file posix_wrappers_posix.cc.

11 {
12 return ::strdup(str1);
13}

Referenced by flutter::NativeAssetsAvailableAssets().

◆ swap()

template<class T , class Traits >
void fml::swap ( const UniqueObject< T, Traits > &  a,
const UniqueObject< T, Traits > &  b 
)

Definition at line 124 of file unique_object.h.

124 {
125 a.swap(b);
126}
void swap(UniqueObject &other)

References fml::UniqueObject< T, Traits >::swap().

◆ TEST() [1/9]

fml::TEST ( CountDownLatchTest  ,
CanWait   
)

Definition at line 21 of file count_down_latch_unittests.cc.

21 {
22 fml::Thread thread("test_thread");
23 const size_t count = 100;
24 size_t current_count = 0;
25 CountDownLatch latch(count);
26 auto decrement_latch_on_thread = [runner = thread.GetTaskRunner(), &latch,
27 &current_count]() {
28 runner->PostTask([&latch, &current_count]() {
29 std::this_thread::sleep_for(std::chrono::microseconds(100));
30 current_count++;
31 latch.CountDown();
32 });
33 };
34 for (size_t i = 0; i < count; ++i) {
35 decrement_latch_on_thread();
36 }
37 latch.Wait();
38 ASSERT_EQ(current_count, count);
39}

References fml::CountDownLatch::CountDown(), fml::Thread::GetTaskRunner(), i, and fml::CountDownLatch::Wait().

◆ TEST() [2/9]

fml::TEST ( CountDownLatchTest  ,
CanWaitOnZero   
)

Definition at line 16 of file count_down_latch_unittests.cc.

16 {
17 CountDownLatch latch(0);
18 latch.Wait();
19}

References fml::CountDownLatch::Wait().

◆ TEST() [3/9]

fml::TEST ( MallocMapping  ,
Copy   
)

Definition at line 36 of file mapping_unittests.cc.

36 {
37 size_t length = 10;
38 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
39 memset(const_cast<uint8_t*>(mapping.GetMapping()), 0xac, mapping.GetSize());
40 MallocMapping copied =
41 MallocMapping::Copy(mapping.GetMapping(), mapping.GetSize());
42
43 ASSERT_NE(mapping.GetMapping(), copied.GetMapping());
44 ASSERT_EQ(mapping.GetSize(), copied.GetSize());
45 ASSERT_EQ(
46 0, memcmp(mapping.GetMapping(), copied.GetMapping(), mapping.GetSize()));
47}
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
size_t GetSize() const override
Definition mapping.cc:143
const uint8_t * GetMapping() const override
Definition mapping.cc:147
size_t length

References fml::MallocMapping::Copy(), fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), and length.

◆ TEST() [4/9]

fml::TEST ( MallocMapping  ,
CopySizeZero   
)

Definition at line 64 of file mapping_unittests.cc.

64 {
65 char ch = 'a';
66 MallocMapping mapping = MallocMapping::Copy(&ch, &ch);
67 ASSERT_EQ(0u, mapping.GetSize());
68}

References fml::MallocMapping::Copy(), and fml::MallocMapping::GetSize().

◆ TEST() [5/9]

fml::TEST ( MallocMapping  ,
EmptyContructor   
)

Definition at line 10 of file mapping_unittests.cc.

10 {
11 MallocMapping mapping;
12 ASSERT_EQ(nullptr, mapping.GetMapping());
13 ASSERT_EQ(0u, mapping.GetSize());
14}

References fml::MallocMapping::GetMapping(), and fml::MallocMapping::GetSize().

◆ TEST() [6/9]

fml::TEST ( MallocMapping  ,
IsDontNeedSafe   
)

Definition at line 57 of file mapping_unittests.cc.

57 {
58 size_t length = 10;
59 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
60 ASSERT_NE(nullptr, mapping.GetMapping());
61 ASSERT_FALSE(mapping.IsDontNeedSafe());
62}

References fml::MallocMapping::GetMapping(), fml::MallocMapping::IsDontNeedSafe(), and length.

◆ TEST() [7/9]

fml::TEST ( MallocMapping  ,
MoveConstructor   
)

Definition at line 23 of file mapping_unittests.cc.

23 {
24 size_t length = 10;
25 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
26 MallocMapping moved = std::move(mapping);
27
28 ASSERT_EQ(nullptr,
29 mapping.GetMapping()); // NOLINT(clang-analyzer-cplusplus.Move,
30 // bugprone-use-after-move)
31 ASSERT_EQ(0u, mapping.GetSize());
32 ASSERT_NE(nullptr, moved.GetMapping());
33 ASSERT_EQ(length, moved.GetSize());
34}

References fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), and length.

◆ TEST() [8/9]

fml::TEST ( MallocMapping  ,
NotEmptyContructor   
)

Definition at line 16 of file mapping_unittests.cc.

16 {
17 size_t length = 10;
18 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
19 ASSERT_NE(nullptr, mapping.GetMapping());
20 ASSERT_EQ(length, mapping.GetSize());
21}

References fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), and length.

◆ TEST() [9/9]

fml::TEST ( MallocMapping  ,
Release   
)

Definition at line 49 of file mapping_unittests.cc.

49 {
50 size_t length = 10;
51 MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
52 free(const_cast<uint8_t*>(mapping.Release()));
53 ASSERT_EQ(nullptr, mapping.GetMapping());
54 ASSERT_EQ(0u, mapping.GetSize());
55}

References fml::MallocMapping::GetMapping(), fml::MallocMapping::GetSize(), length, and fml::MallocMapping::Release().

◆ TimerDrain()

bool fml::TimerDrain ( int  fd)

Drains the timer FD and returns true if it has expired. This may be false in case the timer read is non-blocking and this routine was called before the timer expiry.

Definition at line 59 of file timerfd.cc.

59 {
60 // 8 bytes must be read from a signaled timer file descriptor when signaled.
61 uint64_t fire_count = 0;
62 ssize_t size = FML_HANDLE_EINTR(::read(fd, &fire_count, sizeof(uint64_t)));
63 if (size != sizeof(uint64_t)) {
64 return false;
65 }
66 return fire_count > 0;
67}

References FML_HANDLE_EINTR.

◆ TimerRearm()

bool fml::TimerRearm ( int  fd,
fml::TimePoint  time_point 
)

Rearms the timer to expire at the given time point.

Definition at line 38 of file timerfd.cc.

38 {
39 uint64_t nano_secs = time_point.ToEpochDelta().ToNanoseconds();
40
41 // "0" will disarm the timer, desired behavior is to immediately
42 // trigger the timer.
43 if (nano_secs < 1) {
44 nano_secs = 1;
45 }
46
47 struct itimerspec spec = {};
48 spec.it_value.tv_sec = static_cast<time_t>(nano_secs / NSEC_PER_SEC);
49 spec.it_value.tv_nsec = nano_secs % NSEC_PER_SEC;
50 spec.it_interval = spec.it_value; // single expiry.
51
52 int result = ::timerfd_settime(fd, TFD_TIMER_ABSTIME, &spec, nullptr);
53 if (result != 0) {
54 FML_DLOG(ERROR) << "timerfd_settime err:" << strerror(errno);
55 }
56 return result == 0;
57}
constexpr int64_t ToNanoseconds() const
Definition time_delta.h:61
constexpr TimeDelta ToEpochDelta() const
Definition time_point.h:52
#define NSEC_PER_SEC
Definition timerfd.cc:35
int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
Definition timerfd.cc:23
#define TFD_TIMER_ABSTIME
Definition timerfd.h:29

References FML_DLOG, NSEC_PER_SEC, TFD_TIMER_ABSTIME, timerfd_settime(), fml::TimePoint::ToEpochDelta(), and fml::TimeDelta::ToNanoseconds().

◆ ToggleSignalHandlers()

static void fml::ToggleSignalHandlers ( bool  set)
static

Definition at line 115 of file backtrace.cc.

115 {
116 for (size_t i = 0; i < sizeof(kKnownSignalHandlers) / sizeof(size_t); ++i) {
117 auto signal_name = kKnownSignalHandlers[i];
118 auto handler = set ? &SignalHandler : SIG_DFL;
119
120 if (::signal(signal_name, handler) == SIG_ERR) {
121 FML_LOG(ERROR) << "Could not attach signal handler for " << signal_name;
122 }
123 }
124}
const gchar FlBinaryMessengerMessageHandler handler
static size_t kKnownSignalHandlers[]
Definition backtrace.cc:62
static void SignalHandler(int signal)
Definition backtrace.cc:101

References FML_LOG, handler, i, kKnownSignalHandlers, and SignalHandler().

Referenced by InstallCrashHandler(), and SignalHandler().

◆ ToPosixAccessFlags()

static int fml::ToPosixAccessFlags ( FilePermission  permission)
static

Definition at line 34 of file file_posix.cc.

34 {
35 int flags = 0;
36 switch (permission) {
37 case FilePermission::kRead:
38 flags |= O_RDONLY; // read only
39 break;
40 case FilePermission::kWrite:
41 flags |= O_WRONLY; // write only
42 break;
43 case FilePermission::kReadWrite:
44 flags |= O_RDWR; // read-write
45 break;
46 }
47 return flags;
48}

References kRead, kReadWrite, and kWrite.

Referenced by OpenFile().

◆ ToPosixCreateModeFlags()

static int fml::ToPosixCreateModeFlags ( FilePermission  permission)
static

Definition at line 50 of file file_posix.cc.

50 {
51 int mode = 0;
52 switch (permission) {
53 case FilePermission::kRead:
54 mode |= S_IRUSR;
55 break;
56 case FilePermission::kWrite:
57 mode |= S_IWUSR;
58 break;
59 case FilePermission::kReadWrite:
60 mode |= S_IRUSR | S_IWUSR;
61 break;
62 }
63 return mode;
64}

References kRead, kReadWrite, and kWrite.

Referenced by OpenDirectory(), and OpenFile().

◆ ToPosixProtectionFlags()

static int fml::ToPosixProtectionFlags ( std::initializer_list< FileMapping::Protection protection_flags)
static

Definition at line 20 of file mapping_posix.cc.

21 {
22 int flags = 0;
23 for (auto protection : protection_flags) {
24 switch (protection) {
25 case FileMapping::Protection::kRead:
26 flags |= PROT_READ;
27 break;
28 case FileMapping::Protection::kWrite:
29 flags |= PROT_WRITE;
30 break;
31 case FileMapping::Protection::kExecute:
32 // Do not combine write flags with execute flags.
33 return PROT_READ | PROT_EXEC;
34 }
35 }
36 return flags;
37}

References fml::FileMapping::kExecute, fml::FileMapping::kRead, and fml::FileMapping::kWrite.

Referenced by fml::FileMapping::FileMapping().

◆ TruncateFile()

bool fml::TruncateFile ( const fml::UniqueFD file,
size_t  size 
)

Definition at line 155 of file file_posix.cc.

155 {
156 if (!file.is_valid()) {
157 return false;
158 }
159
160 return ::ftruncate(file.get(), size) == 0;
161}

References fml::UniqueObject< T, Traits >::get(), and fml::UniqueObject< T, Traits >::is_valid().

Referenced by TEST(), WriteAtomically(), and WriteStringToFile().

◆ UnlinkDirectory() [1/2]

bool fml::UnlinkDirectory ( const char *  path)

◆ UnlinkDirectory() [2/2]

bool fml::UnlinkDirectory ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 167 of file file_posix.cc.

167 {
168 return ::unlinkat(base_directory.get(), path, AT_REMOVEDIR) == 0;
169}

References fml::UniqueObject< T, Traits >::get().

◆ UnlinkFile() [1/2]

bool fml::UnlinkFile ( const char *  path)

Definition at line 171 of file file_posix.cc.

171 {
172 return UnlinkFile(fml::UniqueFD{AT_FDCWD}, path);
173}

References UnlinkFile().

Referenced by RemoveFilesInDirectory(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), flutter::testing::TEST_F(), and UnlinkFile().

◆ UnlinkFile() [2/2]

bool fml::UnlinkFile ( const fml::UniqueFD base_directory,
const char *  path 
)

Definition at line 175 of file file_posix.cc.

175 {
176 int code = ::unlinkat(base_directory.get(), path, 0);
177 if (code != 0) {
178 FML_DLOG(ERROR) << strerror(errno);
179 }
180 return code == 0;
181}

References FML_DLOG, and fml::UniqueObject< T, Traits >::get().

◆ Utf16ToUtf8()

std::string fml::Utf16ToUtf8 ( const std::u16string_view  string)

Definition at line 37 of file string_conversion.cc.

37 {
38 Utf16StringConverter converter;
39 return converter.to_bytes(string.data());
40}
std::wstring_convert< std::codecvt_utf8_utf16< char16_t >, char16_t > Utf16StringConverter
std::shared_ptr< const fml::Mapping > data

References data.

Referenced by flutter::TextEditingDelta::delta_text(), flutter::TextInputModel::GetCursorOffset(), flutter::TextInputModel::GetText(), fml::jni::JavaStringToString(), flutter::TextEditingDelta::old_text(), fml::testing::TEST(), fml::testing::TEST(), fml::testing::TEST(), and base::UTF16ToUTF8().

◆ Utf16ToWideString()

std::wstring fml::Utf16ToWideString ( const std::u16string_view  str)

Definition at line 32 of file wstring_conversion.cc.

32 {
33 static_assert(sizeof(std::wstring::value_type) ==
34 sizeof(std::u16string::value_type));
35 return {begin(str), end(str)};
36}
const size_t end

References end.

Referenced by fml::testing::TEST(), fml::testing::TEST(), and fml::testing::TEST().

◆ Utf8ToUtf16()

◆ Utf8ToWideString()

std::wstring fml::Utf8ToWideString ( const std::string_view  str)

Definition at line 21 of file wstring_conversion.cc.

21 {
22 WideStringConverter converter;
23 return converter.from_bytes(str.data());
24}
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t > WideStringConverter

Referenced by flutter::AccessibilityPlugin::Announce(), GetFileAttributesForUtf8Path(), IsAbsolutePath(), flutter::PlatformHandler::SetPlainText(), fml::testing::TEST(), fml::testing::TEST(), fml::testing::TEST(), and fml::testing::TEST().

◆ VisitFiles()

bool fml::VisitFiles ( const fml::UniqueFD directory,
const FileVisitor visitor 
)

Call visitor on all files inside the directory non-recursively. The trivial file "." and ".." will not be visited.

Return false if and only if the visitor returns false during the traversal.

If recursive visiting is needed, call VisitFiles inside the visitor, or use our helper method VisitFilesRecursively.

See also
VisitFilesRecursively.
Note
Procedure doesn't copy all closures.

Definition at line 236 of file file_posix.cc.

236 {
237 fml::UniqueFD dup_fd(dup(directory.get()));
238 if (!dup_fd.is_valid()) {
239 FML_DLOG(ERROR) << "Can't dup the directory fd. Error: " << strerror(errno);
240 return true; // continue to visit other files
241 }
242
243 fml::UniqueDir dir(::fdopendir(dup_fd.get()));
244 if (!dir.is_valid()) {
245 FML_DLOG(ERROR) << "Can't open the directory. Error: " << strerror(errno);
246 return true; // continue to visit other files
247 }
248
249 // The directory fd will be closed by `closedir`.
250 (void)dup_fd.release();
251
252 // Without `rewinddir`, `readir` will directly return NULL (end of dir is
253 // reached) after a previuos `VisitFiles` call for the same `const
254 // fml::UniqueFd& directory`.
255 rewinddir(dir.get());
256 while (dirent* ent = readdir(dir.get())) {
257 std::string filename = ent->d_name;
258 if (filename != "." && filename != "..") {
259 if (!visitor(directory, filename)) {
260 return false;
261 }
262 }
263 }
264
265 return true;
266}
UniqueObject< DIR *, internal::os_unix::UniqueDirTraits > UniqueDir
Definition unique_fd.h:101

References FML_DLOG, fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), and fml::UniqueObject< T, Traits >::release().

Referenced by flutter::PersistentCache::LoadSkSLs(), RemoveFilesInDirectory(), TEST(), and VisitFilesRecursively().

◆ VisitFilesRecursively()

bool fml::VisitFilesRecursively ( const fml::UniqueFD directory,
const FileVisitor visitor 
)

Recursively call visitor on all files inside the directory. Return false if and only if the visitor returns false during the traversal.

This is a helper method that wraps the general VisitFiles method. The VisitFiles is strictly more powerful as it has the access of the recursion stack to the file. For example, VisitFiles may be able to maintain a vector of directory names that lead to a file. That could be useful to compute the relative path between the root directory and the visited file.

See also
VisitFiles.
Note
Procedure doesn't copy all closures.

Definition at line 71 of file file.cc.

72 {
73 FileVisitor recursive_visitor = [&recursive_visitor, &visitor](
74 const UniqueFD& directory,
75 const std::string& filename) {
76 if (!visitor(directory, filename)) {
77 return false;
78 }
79 if (IsDirectory(directory, filename.c_str())) {
80 UniqueFD sub_dir = OpenDirectoryReadOnly(directory, filename.c_str());
81 if (!sub_dir.is_valid()) {
82 FML_LOG(ERROR) << "Can't open sub-directory: " << filename;
83 return true;
84 }
85 return VisitFiles(sub_dir, recursive_visitor);
86 }
87 return true;
88 };
89 return VisitFiles(directory, recursive_visitor);
90}

References FML_LOG, fml::UniqueObject< T, Traits >::is_valid(), IsDirectory(), OpenDirectoryReadOnly(), and VisitFiles().

Referenced by TEST(), and TEST().

◆ WaitWithTimeoutImpl()

template<typename ConditionFn >
bool fml::WaitWithTimeoutImpl ( std::unique_lock< std::mutex > *  locker,
std::condition_variable *  cv,
ConditionFn  condition,
TimeDelta  timeout 
)

Definition at line 20 of file waitable_event.cc.

23 {
24 FML_DCHECK(locker->owns_lock());
25
26 if (condition()) {
27 return false;
28 }
29
30 // We may get spurious wakeups.
31 TimeDelta wait_remaining = timeout;
32 TimePoint start = TimePoint::Now();
33 while (true) {
34 if (std::cv_status::timeout ==
35 cv->wait_for(*locker, std::chrono::nanoseconds(
36 wait_remaining.ToNanoseconds()))) {
37 return true; // Definitely timed out.
38 }
39
40 // We may have been awoken.
41 if (condition()) {
42 return false;
43 }
44
45 // Or the wakeup may have been spurious.
46 TimePoint now = TimePoint::Now();
47 FML_DCHECK(now >= start);
48 TimeDelta elapsed = now - start;
49 // It's possible that we may have timed out anyway.
50 if (elapsed >= timeout) {
51 return true;
52 }
53
54 // Otherwise, recalculate the amount that we have left to wait.
55 wait_remaining = timeout - elapsed;
56 }
57}
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition timing.h:15
const size_t start

References FML_DCHECK, fml::TimePoint::Now(), start, and fml::TimeDelta::ToNanoseconds().

Referenced by fml::ManualResetWaitableEvent::WaitWithTimeout().

◆ WideStringToUtf16()

std::u16string fml::WideStringToUtf16 ( const std::wstring_view  str)

Definition at line 26 of file wstring_conversion.cc.

26 {
27 static_assert(sizeof(std::wstring::value_type) ==
28 sizeof(std::u16string::value_type));
29 return {begin(str), end(str)};
30}

References end.

Referenced by flutter::FlutterWindowsView::AnnounceAlert(), fml::testing::TEST(), fml::testing::TEST(), fml::testing::TEST(), and ui::TEST_F().

◆ WideStringToUtf8()

std::string fml::WideStringToUtf8 ( const std::wstring_view  str)

◆ WriteAtomically()

bool fml::WriteAtomically ( const fml::UniqueFD base_directory,
const char *  file_name,
const Mapping mapping 
)

Definition at line 191 of file file_posix.cc.

193 {
194 if (file_name == nullptr || data.GetMapping() == nullptr) {
195 return false;
196 }
197
198 std::stringstream stream;
199 stream << file_name << ".temp";
200 const auto temp_file_name = stream.str();
201
202 auto temp_file = OpenFile(base_directory, temp_file_name.c_str(), true,
203 FilePermission::kReadWrite);
204 if (!temp_file.is_valid()) {
205 return false;
206 }
207
208 if (!TruncateFile(temp_file, data.GetSize())) {
209 return false;
210 }
211
212 ssize_t remaining = data.GetSize();
213 ssize_t written = 0;
214 ssize_t offset = 0;
215
216 while (remaining > 0) {
217 written = FML_HANDLE_EINTR(
218 ::write(temp_file.get(), data.GetMapping() + offset, remaining));
219
220 if (written == -1) {
221 return false;
222 }
223
224 remaining -= written;
225 offset += written;
226 }
227
228 if (::fsync(temp_file.get()) != 0) {
229 return false;
230 }
231
232 return ::renameat(base_directory.get(), temp_file_name.c_str(),
233 base_directory.get(), file_name) == 0;
234}
bool TruncateFile(const fml::UniqueFD &file, size_t size)

References data, FML_HANDLE_EINTR, fml::UniqueObject< T, Traits >::get(), kReadWrite, OpenFile(), and TruncateFile().

Referenced by impeller::compiler::testing::CompilerTest::CanCompileAndReflect(), impeller::compiler::GenerateShaderBundle(), impeller::compiler::Main(), impeller::Main(), impeller::compiler::OutputDepfile(), impeller::compiler::OutputIPLR(), impeller::compiler::OutputReflectionData(), impeller::compiler::OutputSLFile(), flutter::PersistentCacheStore(), impeller::PipelineCacheDataPersist(), flutter::TemplaterMain(), fml::testing::TEST(), fml::testing::TEST(), TEST(), TEST(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().

Variable Documentation

◆ gCPUTracker

CPUSpeedTracker* fml::gCPUTracker
static

◆ gCPUTrackerFlag

std::once_flag fml::gCPUTrackerFlag

The CPUSpeedTracker is initialized once the first time a thread affinity is requested.

Definition at line 20 of file cpu_affinity.cc.

Referenced by SetUpCPUTracker().

◆ kClockType [1/2]

constexpr int fml::kClockType = CLOCK_MONOTONIC
staticconstexpr

Definition at line 14 of file message_loop_android.cc.

◆ kClockType [2/2]

constexpr int fml::kClockType = CLOCK_MONOTONIC
staticconstexpr

Definition at line 15 of file message_loop_linux.cc.

◆ kDecodeMap

constexpr signed char fml::kDecodeMap[]
staticconstexpr
Initial value:
= {
26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}

Definition at line 46 of file base32.cc.

46 {
47 // starting from ASCII 50 '2'
48 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1,
49 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
50 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};

Referenced by Base32Decode().

◆ kDecodeMapSize

constexpr int fml::kDecodeMapSize
staticconstexpr
Initial value:
=
sizeof(kDecodeMap) / sizeof(kDecodeMap[0])
static constexpr signed char kDecodeMap[]
Definition base32.cc:46

Definition at line 52 of file base32.cc.

Referenced by Base32Decode().

◆ kDefaultFrameBudget

constexpr Milliseconds fml::kDefaultFrameBudget = Milliseconds(1s) / 60
constexpr

Definition at line 21 of file time_delta.h.

◆ kDistantFuture

constexpr CFTimeInterval fml::kDistantFuture = 1.0e10
staticconstexpr

Definition at line 14 of file message_loop_darwin.mm.

◆ kEncoding [1/2]

constexpr char fml::kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
staticconstexpr

Definition at line 13 of file base32.cc.

Referenced by Base32Encode(), and HexEncode().

◆ kEncoding [2/2]

constexpr char fml::kEncoding[] = "0123456789abcdef"
staticconstexpr

Definition at line 12 of file hex_codec.cc.

◆ kIsByteSwappableV

template<typename T >
constexpr bool fml::kIsByteSwappableV = IsByteSwappable<T>::value
constexpr

Definition at line 35 of file endianness.h.

◆ kKnownSignalHandlers

size_t fml::kKnownSignalHandlers[]
static
Initial value:
= {
SIGABRT,
SIGFPE,
SIGTERM,
SIGSEGV,
SIGBUS,
SIGSYS,
SIGPIPE,
SIGALRM,
}

Definition at line 62 of file backtrace.cc.

62 {
63 SIGABRT, // abort program
64 SIGFPE, // floating-point exception
65 SIGTERM, // software termination signal
66 SIGSEGV, // segmentation violation
67#if !FML_OS_WIN
68 SIGBUS, // bus error
69 SIGSYS, // non-existent system call invoked
70 SIGPIPE, // write on a pipe with no reader
71 SIGALRM, // real-time timer expired
72#endif // !FML_OS_WIN
73};

Referenced by ToggleSignalHandlers().

◆ kKUnknownFrameName [1/2]

std::string fml::kKUnknownFrameName = "Unknown"
static

Definition at line 25 of file backtrace.cc.

Referenced by GetSymbolName().

◆ kKUnknownFrameName [2/2]

std::string fml::kKUnknownFrameName = "Unknown"
static

Definition at line 9 of file backtrace_stub.cc.

◆ kLogDFatal

const LogSeverity fml::kLogDFatal = kLogFatal

Definition at line 58 of file log_level.h.

◆ kLogError

constexpr LogSeverity fml::kLogError = 2
constexpr

◆ kLogFatal

◆ kLogImportant

constexpr LogSeverity fml::kLogImportant = 3
constexpr

Definition at line 18 of file log_level.h.

Referenced by fml::LogMessage::~LogMessage().

◆ kLogInfo

◆ kLogNumSeverities

constexpr LogSeverity fml::kLogNumSeverities = 5
constexpr

Definition at line 20 of file log_level.h.

◆ kLogWarning

◆ kUnmerged

◆ LOG_DFATAL

const LogSeverity fml::LOG_DFATAL = kLogDFatal

Definition at line 64 of file log_level.h.

◆ LOG_ERROR

constexpr LogSeverity fml::LOG_ERROR = kLogError
constexpr

Definition at line 35 of file log_level.h.

Referenced by impeller::ImpellerValidationBreak().

◆ LOG_FATAL

constexpr LogSeverity fml::LOG_FATAL = kLogFatal
constexpr

Definition at line 45 of file log_level.h.

Referenced by impeller::ImpellerValidationBreak().

◆ LOG_IMPORTANT

constexpr LogSeverity fml::LOG_IMPORTANT = kLogImportant
constexpr

Definition at line 40 of file log_level.h.

◆ LOG_INFO

constexpr LogSeverity fml::LOG_INFO = kLogInfo
constexpr

Definition at line 25 of file log_level.h.

◆ LOG_WARNING

constexpr LogSeverity fml::LOG_WARNING = kLogWarning
constexpr

Definition at line 30 of file log_level.h.

◆ tls_message_loop

◆ tls_task_source_grade

thread_local std::unique_ptr<TaskSourceGradeHolder> fml::tls_task_source_grade
static

◆ tTaskObservers

thread_local std::map<intptr_t, fit::closure> fml::tTaskObservers