be/src/runtime/task_execution_context.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <memory> |
21 | | |
22 | | #include "runtime/runtime_state.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | class RuntimeState; |
27 | | |
28 | | // Base class for execution contexts (e.g. PipelineFragmentContext). |
29 | | // |
30 | | // For recursive CTE, the PFC (which inherits from this class) is held by external threads |
31 | | // (scanner threads, brpc callbacks, etc.) via weak_ptr<TaskExecutionContext>. |
32 | | class TaskExecutionContext : public std::enable_shared_from_this<TaskExecutionContext> { |
33 | | public: |
34 | 469k | TaskExecutionContext(); |
35 | 468k | virtual ~TaskExecutionContext(); |
36 | | }; |
37 | | |
38 | | using TaskExecutionContextSPtr = std::shared_ptr<TaskExecutionContext>; |
39 | | |
40 | | // Task Execution Context maybe plan fragment executor or pipelinefragmentcontext or pipelinexfragmentcontext |
41 | 0 | // In multi thread scenario, the object is created in main thread (such as FragmentExecThread), but the object |
42 | | // maybe used in other thread(such as scanner thread, brpc->sender queue). If the main thread stopped and destroy |
43 | | // the object, then the other thread may core. So the other thread must lock the context to ensure the object exists. |
44 | | struct HasTaskExecutionCtx { |
45 | | using Weak = typename TaskExecutionContextSPtr::weak_type; |
46 | | |
47 | | HasTaskExecutionCtx(RuntimeState* state); |
48 | | |
49 | | virtual ~HasTaskExecutionCtx(); |
50 | | |
51 | | public: |
52 | | inline TaskExecutionContextSPtr task_exec_ctx() const { return task_exec_ctx_.lock(); } |
53 | | inline Weak weak_task_exec_ctx() const { return task_exec_ctx_; } |
54 | | |
55 | | private: |
56 | | Weak task_exec_ctx_; |
57 | | }; |
58 | | |
59 | | } // namespace doris |