brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · a4c7064 Raw
56 lines · cpp
1//===- AllocAction.cpp ----------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// AllocAction and related APIs.10//11//===----------------------------------------------------------------------===//12 13#include "orc-rt/AllocAction.h"14#include "orc-rt/ScopeExit.h"15 16namespace orc_rt {17 18Expected<std::vector<AllocAction>>19runFinalizeActions(std::vector<AllocActionPair> AAPs) {20  std::vector<AllocAction> DeallocActions;21  auto RunDeallocActions = make_scope_exit([&]() {22    while (!DeallocActions.empty()) {23      // TODO: Log errors from cleanup dealloc actions.24      {25        [[maybe_unused]] auto B = DeallocActions.back()();26      }27      DeallocActions.pop_back();28    }29  });30 31  for (auto &AAP : AAPs) {32    if (AAP.Finalize) {33      auto B = AAP.Finalize();34      if (const char *ErrMsg = B.getOutOfBandError())35        return make_error<StringError>(ErrMsg);36    }37    if (AAP.Dealloc)38      DeallocActions.push_back(std::move(AAP.Dealloc));39  }40 41  RunDeallocActions.release();42  return DeallocActions;43}44 45void runDeallocActions(std::vector<AllocAction> DAAs) {46  while (!DAAs.empty()) {47    // TODO: Log errors from cleanup dealloc actions.48    {49      [[maybe_unused]] auto B = DAAs.back()();50    }51    DAAs.pop_back();52  }53}54 55} // namespace orc_rt56