本文整理汇总了C++中mozilla::MakeScopeExit方法的典型用法代码示例。如果您正苦于以下问题:C++ mozilla::MakeScopeExit方法的具体用法?C++ mozilla::MakeScopeExit怎么用?C++ mozilla::MakeScopeExit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozilla
的用法示例。
在下文中一共展示了mozilla::MakeScopeExit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeScopeExit
bool
TraceLoggerGraph::init(uint64_t startTimestamp)
{
auto fail = MakeScopeExit([&] { failed = true; });
if (!tree.init())
return false;
if (!stack.init())
return false;
if (!EnsureTraceLoggerGraphState())
return false;
uint32_t loggerId = traceLoggerGraphState->nextLoggerId();
if (loggerId == uint32_t(-1))
return false;
uint32_t pid = traceLoggerGraphState->pid();
js::UniqueChars dictFilename = AllocTraceLogFilename("tl-dict.%u.%d.json", pid, loggerId);
dictFile = fopen(dictFilename.get(), "w");
if (!dictFile)
return false;
auto cleanupDict = MakeScopeExit([&] { fclose(dictFile); dictFile = nullptr; });
js::UniqueChars treeFilename = AllocTraceLogFilename("tl-tree.%u.%d.tl", pid, loggerId);
treeFile = fopen(treeFilename.get(), "w+b");
if (!treeFile)
return false;
auto cleanupTree = MakeScopeExit([&] { fclose(treeFile); treeFile = nullptr; });
js::UniqueChars eventFilename = AllocTraceLogFilename("tl-event.%u.%d.tl", pid, loggerId);
eventFile = fopen(eventFilename.get(), "wb");
if (!eventFile)
return false;
auto cleanupEvent = MakeScopeExit([&] { fclose(eventFile); eventFile = nullptr; });
// Create the top tree node and corresponding first stack item.
TreeEntry& treeEntry = tree.pushUninitialized();
treeEntry.setStart(startTimestamp);
treeEntry.setStop(0);
treeEntry.setTextId(0);
treeEntry.setHasChildren(false);
treeEntry.setNextId(0);
StackEntry& stackEntry = stack.pushUninitialized();
stackEntry.setTreeId(0);
stackEntry.setLastChildId(0);
stackEntry.setActive(true);
if (fprintf(dictFile, "[") < 0) {
fprintf(stderr, "TraceLogging: Error while writing.\n");
return false;
}
fail.release();
cleanupDict.release();
cleanupTree.release();
cleanupEvent.release();
return true;
}