Georgios Pinitas | baf174e | 2017-09-08 19:47:30 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | da953f2 | 2019-04-02 17:27:03 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Georgios Pinitas | baf174e | 2017-09-08 19:47:30 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_IMEMORYGROUP_H__ |
| 25 | #define __ARM_COMPUTE_IMEMORYGROUP_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/Types.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | /** Memory group interface */ |
| 32 | class IMemoryGroup |
| 33 | { |
| 34 | public: |
| 35 | /** Default virtual destructor */ |
| 36 | virtual ~IMemoryGroup() = default; |
| 37 | /** Acquires backing memory for the whole group */ |
| 38 | virtual void acquire() = 0; |
| 39 | /** Releases backing memory of the whole group */ |
| 40 | virtual void release() = 0; |
| 41 | /** Gets the memory mapping of the group */ |
| 42 | virtual MemoryMappings &mappings() = 0; |
| 43 | }; |
Georgios Pinitas | da953f2 | 2019-04-02 17:27:03 +0100 | [diff] [blame] | 44 | |
| 45 | /** Memory group resources scope handling class */ |
| 46 | class MemoryGroupResourceScope |
| 47 | { |
| 48 | public: |
| 49 | /** Constructor |
| 50 | * |
| 51 | * @param[in] memory_group Memory group to handle |
| 52 | */ |
| 53 | explicit MemoryGroupResourceScope(IMemoryGroup &memory_group) |
| 54 | : _memory_group(memory_group) |
| 55 | { |
| 56 | _memory_group.acquire(); |
| 57 | } |
| 58 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 59 | MemoryGroupResourceScope(const MemoryGroupResourceScope &) = delete; |
| 60 | /** Default move constructor */ |
| 61 | MemoryGroupResourceScope(MemoryGroupResourceScope &&) = default; |
| 62 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 63 | MemoryGroupResourceScope &operator=(const MemoryGroupResourceScope &) = delete; |
| 64 | /** Default move assignment operator */ |
| 65 | MemoryGroupResourceScope &operator=(MemoryGroupResourceScope &&) = default; |
| 66 | /** Destructor */ |
| 67 | ~MemoryGroupResourceScope() |
| 68 | { |
| 69 | _memory_group.release(); |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | IMemoryGroup &_memory_group; |
| 74 | }; |
Georgios Pinitas | baf174e | 2017-09-08 19:47:30 +0100 | [diff] [blame] | 75 | } // arm_compute |
| 76 | #endif /*__ARM_COMPUTE_IMEMORYGROUP_H__ */ |