From b0cc1d1094575318ba52db840d7e7a06974c851e Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 16 Mar 2016 14:07:05 -0400
Subject: [PATCH] P4 to Git Change 1248071 by skeely@HSA_Perforce on 2016/03/16
13:57:32
SWDEV-90207 - Initial Mesa implementation. Interop is disabled pending further testing.
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadefs.hpp#4 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.cpp#59 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.hpp#27 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsaglinterop.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsaglinterop.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsamemory.cpp#21 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsamemory.hpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsaregisters.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsasettings.cpp#12 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/mesa_glinterop.h#1 add
... //depot/stg/opencl/drivers/opencl/runtime/utils/util.hpp#11 edit
---
rocclr/runtime/utils/util.hpp | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/rocclr/runtime/utils/util.hpp b/rocclr/runtime/utils/util.hpp
index efe0d41288..297b922f5e 100644
--- a/rocclr/runtime/utils/util.hpp
+++ b/rocclr/runtime/utils/util.hpp
@@ -276,6 +276,37 @@ static inline bool Is32Bits() {
static inline bool Is64Bits() {
return LP64_SWITCH(false, true);
}
+
+template
+class ScopeGuard {
+ public:
+ explicit ALWAYSINLINE ScopeGuard(const lambda& release)
+ : release_(release), dismiss_(false) {}
+
+ ScopeGuard(ScopeGuard& rhs) { *this = rhs; }
+
+ ALWAYSINLINE ~ScopeGuard() {
+ if (!dismiss_) release_();
+ }
+ ALWAYSINLINE ScopeGuard& operator=(ScopeGuard& rhs) {
+ dismiss_ = rhs.dismiss_;
+ release_ = rhs.release_;
+ rhs.dismiss_ = true;
+ }
+ ALWAYSINLINE void Dismiss() { dismiss_ = true; }
+
+ private:
+ lambda release_;
+ bool dismiss_;
+};
+
+#define MAKE_SCOPE_GUARD_HELPER(lname, sname, ...) \
+ auto lname = __VA_ARGS__; \
+ amd::ScopeGuard sname(lname);
+#define MAKE_SCOPE_GUARD(name, ...) \
+ MAKE_SCOPE_GUARD_HELPER(XCONCAT(scopeGuardLambda, __COUNTER__), name, \
+ __VA_ARGS__)
+
/*@}*/} // namespace amd
#endif /*UTIL_HPP_*/