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 Oct 2020 |
18 | * \brief |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "task.h" |
24 | |
25 | namespace proxima { |
26 | namespace be { |
27 | namespace query { |
28 | |
29 | //! Predefine class |
30 | class Scheduler; |
31 | //! Alias SchedulerPtr |
32 | using SchedulerPtr = std::shared_ptr<Scheduler>; |
33 | |
34 | /*! |
35 | * Schedule task to execution queue |
36 | */ |
37 | class Scheduler { |
38 | public: |
39 | //! Static helper function, get default scheduler |
40 | static SchedulerPtr Default(); |
41 | |
42 | //! Default system concurrency |
43 | static uint32_t HostConcurrency(); |
44 | |
45 | public: |
46 | //! Destructor |
47 | virtual ~Scheduler() = default; |
48 | |
49 | public: |
50 | //! Dispatch task to execution queue, return 0 for success, otherwise failed |
51 | virtual int schedule(TaskPtr task) = 0; |
52 | |
53 | //! Retrieve concurrency of scheduler |
54 | virtual uint32_t concurrency() const = 0; |
55 | |
56 | //! Set concurrency |
57 | virtual uint32_t concurrency(uint32_t concurrency) = 0; |
58 | }; |
59 | |
60 | |
61 | } // namespace query |
62 | } // namespace be |
63 | } // namespace proxima |
64 | |