From 31c05d2fc7d356d96ae2127ecc85c00fc6bb2779 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Wed, 28 Feb 2018 05:20:07 -0600 Subject: [PATCH] Add exception safety to Runtime::Acquire. Change-Id: Ia2a9baf08bb56971412f1ac3914592612de5f134 --- runtime/hsa-runtime/core/runtime/runtime.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index fa53a4556f..835f39205d 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -108,16 +108,17 @@ hsa_status_t Runtime::Acquire() { } runtime_singleton_->ref_count_++; + MAKE_NAMED_SCOPE_GUARD(refGuard, [&]() { runtime_singleton_->ref_count_--; }); if (runtime_singleton_->ref_count_ == 1) { hsa_status_t status = runtime_singleton_->Load(); if (status != HSA_STATUS_SUCCESS) { - runtime_singleton_->ref_count_--; return HSA_STATUS_ERROR_OUT_OF_RESOURCES; } } + refGuard.Dismiss(); return HSA_STATUS_SUCCESS; }