From da953f2e17b401ff595ac88008cd5e90440ebf74 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Tue, 2 Apr 2019 17:27:03 +0100 Subject: COMPMID-2098: Scope handling of memory group resources. Change-Id: Ie945526bd7845301458039edf3129253c1808505 Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/c/938 Comments-Addressed: Arm Jenkins Reviewed-by: Michele Di Giorgio Tested-by: Arm Jenkins --- arm_compute/runtime/IMemoryGroup.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'arm_compute') diff --git a/arm_compute/runtime/IMemoryGroup.h b/arm_compute/runtime/IMemoryGroup.h index be03ea4a01..159e99aeb1 100644 --- a/arm_compute/runtime/IMemoryGroup.h +++ b/arm_compute/runtime/IMemoryGroup.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -41,5 +41,36 @@ public: /** Gets the memory mapping of the group */ virtual MemoryMappings &mappings() = 0; }; + +/** Memory group resources scope handling class */ +class MemoryGroupResourceScope +{ +public: + /** Constructor + * + * @param[in] memory_group Memory group to handle + */ + explicit MemoryGroupResourceScope(IMemoryGroup &memory_group) + : _memory_group(memory_group) + { + _memory_group.acquire(); + } + /** Prevent instances of this class from being copied (As this class contains pointers) */ + MemoryGroupResourceScope(const MemoryGroupResourceScope &) = delete; + /** Default move constructor */ + MemoryGroupResourceScope(MemoryGroupResourceScope &&) = default; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + MemoryGroupResourceScope &operator=(const MemoryGroupResourceScope &) = delete; + /** Default move assignment operator */ + MemoryGroupResourceScope &operator=(MemoryGroupResourceScope &&) = default; + /** Destructor */ + ~MemoryGroupResourceScope() + { + _memory_group.release(); + } + +private: + IMemoryGroup &_memory_group; +}; } // arm_compute #endif /*__ARM_COMPUTE_IMEMORYGROUP_H__ */ -- cgit v1.2.1