1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | * |
16 | * \author guonix |
17 | * \date Nov 2020 |
18 | * \brief |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include <bthread/execution_queue.h> |
24 | #include "task_queue.h" |
25 | |
26 | namespace proxima { |
27 | namespace be { |
28 | namespace query { |
29 | |
30 | /*! |
31 | * Implementation of TaskQueue interface, which based on Execution |
32 | * Queue in brpc |
33 | */ |
34 | class BThreadQueue : public TaskQueue { |
35 | public: |
36 | //! Disable copy and assigment operator on BThreadQueue instance |
37 | // DISALLOW_COPY_AND_ASSIGN(BThreadQueue); |
38 | |
39 | //! Constructor |
40 | BThreadQueue(); |
41 | |
42 | //! Destructor |
43 | ~BThreadQueue() override; |
44 | |
45 | public: |
46 | //! Retrieve id of queue |
47 | uint64_t id() const; |
48 | |
49 | //! Start task queue, return value 0 for success, otherwise failed |
50 | int start() override; |
51 | |
52 | //! Stop task queue, return value 0 for success, otherwise failed |
53 | int stop() override; |
54 | |
55 | //! Join task queue, return value 0 for success, otherwise failed |
56 | int join() override; |
57 | |
58 | //! Put the task in queue |
59 | //! @return, 0: succeed, mark status of task as Scheduled |
60 | //! other: failed |
61 | int put(const TaskPtr &task) override; |
62 | |
63 | //! Retrieve start flags |
64 | bool started() const override; |
65 | |
66 | private: |
67 | //! Release all resourced |
68 | void clear_context(); |
69 | |
70 | private: |
71 | //! Identifier of execution queue |
72 | bthread::ExecutionQueueId<TaskPtr> queue_id_ = {0}; |
73 | |
74 | //! Default options for execution queue |
75 | bthread::ExecutionQueueOptions options_{}; |
76 | |
77 | //! Queue status |
78 | TaskQueue::Status status_{TaskQueue::Status::INITIALIZED}; |
79 | }; |
80 | |
81 | |
82 | } // namespace query |
83 | } // namespace be |
84 | } // namespace proxima |
85 | |