@@ -260,17 +260,22 @@ class InProcessMemoryManager::IPInFlightAlloc
260
260
}
261
261
262
262
// Run finalization actions.
263
- auto DeallocActions = runFinalizeActions (G->allocActions ());
264
- if (!DeallocActions) {
265
- OnFinalized (DeallocActions.takeError ());
266
- return ;
267
- }
263
+ using WrapperFunctionCall = orc::shared::WrapperFunctionCall;
264
+ runFinalizeActions (
265
+ G->allocActions (),
266
+ [this , OnFinalized = std::move (OnFinalized)](
267
+ Expected<std::vector<WrapperFunctionCall>> DeallocActions) mutable {
268
+ completeFinalization (std::move (OnFinalized),
269
+ std::move (DeallocActions));
270
+ });
271
+ }
268
272
269
- // Release the finalize segments slab.
270
- if (auto EC = sys::Memory::releaseMappedMemory (FinalizationSegments)) {
271
- OnFinalized (errorCodeToError (EC));
272
- return ;
273
- }
273
+ void abandon (OnAbandonedFunction OnAbandoned) override {
274
+ Error Err = Error::success ();
275
+ if (auto EC = sys::Memory::releaseMappedMemory (FinalizationSegments))
276
+ Err = joinErrors (std::move (Err), errorCodeToError (EC));
277
+ if (auto EC = sys::Memory::releaseMappedMemory (StandardSegments))
278
+ Err = joinErrors (std::move (Err), errorCodeToError (EC));
274
279
275
280
#ifndef NDEBUG
276
281
// Set 'G' to null to flag that we've been successfully finalized.
@@ -279,17 +284,22 @@ class InProcessMemoryManager::IPInFlightAlloc
279
284
G = nullptr ;
280
285
#endif
281
286
282
- // Continue with finalized allocation.
283
- OnFinalized (MemMgr.createFinalizedAlloc (std::move (StandardSegments),
284
- std::move (*DeallocActions)));
287
+ OnAbandoned (std::move (Err));
285
288
}
286
289
287
- void abandon (OnAbandonedFunction OnAbandoned) override {
288
- Error Err = Error::success ();
289
- if (auto EC = sys::Memory::releaseMappedMemory (FinalizationSegments))
290
- Err = joinErrors (std::move (Err), errorCodeToError (EC));
291
- if (auto EC = sys::Memory::releaseMappedMemory (StandardSegments))
292
- Err = joinErrors (std::move (Err), errorCodeToError (EC));
290
+ private:
291
+ void completeFinalization (
292
+ OnFinalizedFunction OnFinalized,
293
+ Expected<std::vector<orc::shared::WrapperFunctionCall>> DeallocActions) {
294
+
295
+ if (!DeallocActions)
296
+ return OnFinalized (DeallocActions.takeError ());
297
+
298
+ // Release the finalize segments slab.
299
+ if (auto EC = sys::Memory::releaseMappedMemory (FinalizationSegments)) {
300
+ OnFinalized (errorCodeToError (EC));
301
+ return ;
302
+ }
293
303
294
304
#ifndef NDEBUG
295
305
// Set 'G' to null to flag that we've been successfully finalized.
@@ -298,10 +308,11 @@ class InProcessMemoryManager::IPInFlightAlloc
298
308
G = nullptr ;
299
309
#endif
300
310
301
- OnAbandoned (std::move (Err));
311
+ // Continue with finalized allocation.
312
+ OnFinalized (MemMgr.createFinalizedAlloc (std::move (StandardSegments),
313
+ std::move (*DeallocActions)));
302
314
}
303
315
304
- private:
305
316
Error applyProtections () {
306
317
for (auto &KV : BL.segments ()) {
307
318
const auto &AG = KV.first ;
0 commit comments