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 <atomic> |
21 | | #include <condition_variable> |
22 | | #include <memory> |
23 | | |
24 | | #include "runtime/runtime_state.h" |
25 | | |
26 | | namespace doris { |
27 | | |
28 | | class RuntimeState; |
29 | | |
30 | | // This class act as a super class of all context like things such as |
31 | | // plan fragment executor or pipelinefragmentcontext or pipelinexfragmentcontext |
32 | | class TaskExecutionContext : public std::enable_shared_from_this<TaskExecutionContext> { |
33 | | public: |
34 | 448k | TaskExecutionContext() = default; |
35 | 448k | virtual ~TaskExecutionContext() = default; |
36 | | |
37 | | void ref_task_execution_ctx(); |
38 | | |
39 | | void unref_task_execution_ctx(); |
40 | | |
41 | 0 | int has_task_execution_ctx_ref_count() const { return _has_task_execution_ctx_ref_count; } |
42 | | |
43 | | protected: |
44 | | std::atomic<int> _has_task_execution_ctx_ref_count = 0; |
45 | | std::condition_variable _notify_cv; |
46 | | }; |
47 | | |
48 | | using TaskExecutionContextSPtr = std::shared_ptr<TaskExecutionContext>; |
49 | | |
50 | | // Task Execution Context maybe plan fragment executor or pipelinefragmentcontext or pipelinexfragmentcontext |
51 | | // In multi thread scenario, the object is created in main thread (such as FragmentExecThread), but the object |
52 | | // maybe used in other thread(such as scanner thread, brpc->sender queue). If the main thread stopped and destroy |
53 | | // the object, then the other thread may core. So the other thread must lock the context to ensure the object exists. |
54 | | struct HasTaskExecutionCtx { |
55 | | using Weak = typename TaskExecutionContextSPtr::weak_type; |
56 | | |
57 | | HasTaskExecutionCtx(RuntimeState* state); |
58 | | |
59 | | virtual ~HasTaskExecutionCtx(); |
60 | | |
61 | | public: |
62 | 7.53M | inline TaskExecutionContextSPtr task_exec_ctx() const { return task_exec_ctx_.lock(); } |
63 | 4.78M | inline Weak weak_task_exec_ctx() const { return task_exec_ctx_; } |
64 | | |
65 | | private: |
66 | | Weak task_exec_ctx_; |
67 | | }; |
68 | | |
69 | | } // namespace doris |