1 /*
2 * Copyright (c) 2021 Arm Limited.
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 SRC_COMMON_IQUEUE_H_
25 #define SRC_COMMON_IQUEUE_H_
26
27 #include "src/common/IContext.h"
28
29 struct AclQueue_
30 {
31 arm_compute::detail::Header header{ arm_compute::detail::ObjectType::Queue, nullptr };
32
33 protected:
34 AclQueue_() = default;
35 ~AclQueue_() = default;
36 };
37
38 namespace arm_compute
39 {
40 /** Base class specifying the queue interface */
41 class IQueue : public AclQueue_
42 {
43 public:
44 /** Explict Operator Constructor
45 *
46 * @param[in] ctx Context to be used by the operator
47 */
IQueue(IContext * ctx)48 explicit IQueue(IContext *ctx)
49 {
50 this->header.ctx = ctx;
51 this->header.ctx->inc_ref();
52 }
53 /** Destructor */
~IQueue()54 virtual ~IQueue()
55 {
56 this->header.ctx->dec_ref();
57 this->header.type = detail::ObjectType::Invalid;
58 };
59 /** Checks if a queue is valid
60 *
61 * @return True if successful otherwise false
62 */
is_valid()63 bool is_valid() const
64 {
65 return this->header.type == detail::ObjectType::Queue;
66 };
67 virtual StatusCode finish() = 0;
68 };
69
70 /** Extract internal representation of a Queue
71 *
72 * @param[in] queue Opaque queue pointer
73 *
74 * @return The internal representation as an IQueue
75 */
get_internal(AclQueue queue)76 inline IQueue *get_internal(AclQueue queue)
77 {
78 return static_cast<IQueue *>(queue);
79 }
80
81 namespace detail
82 {
83 /** Check if an internal queue is valid
84 *
85 * @param[in] queue Internal queue to check
86 *
87 * @return A status code
88 */
validate_internal_queue(const IQueue * queue)89 inline StatusCode validate_internal_queue(const IQueue *queue)
90 {
91 if(queue == nullptr || !queue->is_valid())
92 {
93 ARM_COMPUTE_LOG_ERROR_ACL("[IQueue]: Invalid queue object");
94 return StatusCode::InvalidArgument;
95 }
96 return StatusCode::Success;
97 }
98 } // namespace detail
99 } // namespace arm_compute
100 #endif /* SRC_COMMON_IQUEUE_H_ */
101