Compute Library
 21.11
IQueue.h
Go to the documentation of this file.
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 {
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  */
48  explicit IQueue(IContext *ctx)
49  {
50  this->header.ctx = ctx;
51  this->header.ctx->inc_ref();
52  }
53  /** Destructor */
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  */
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  */
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  */
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_ */
bool is_valid() const
Checks if a queue is valid.
Definition: IQueue.h:63
Base class specifying the queue interface.
Definition: IQueue.h:41
arm_compute::detail::Header header
Definition: IQueue.h:31
virtual ~IQueue()
Destructor.
Definition: IQueue.h:54
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Log an error message to the logger.
Definition: Log.h:77
Context interface.
Definition: IContext.h:50
Copyright (c) 2017-2021 Arm Limited.
IQueue * get_internal(AclQueue queue)
Extract internal representation of a Queue.
Definition: IQueue.h:76
void dec_ref() const
Decrement context refcount.
Definition: IContext.h:76
StatusCode validate_internal_queue(const IQueue *queue)
Check if an internal queue is valid.
Definition: IQueue.h:89
StatusCode
Definition: Types.h:32
IQueue(IContext *ctx)
Explict Operator Constructor.
Definition: IQueue.h:48
void inc_ref() const
Increment context refcount.
Definition: IContext.h:71