• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_TOOLING_PT_THREAD_INFO_H
17 #define PANDA_TOOLING_PT_THREAD_INFO_H
18 
19 #include <cstdint>
20 
21 #include "runtime/include/panda_vm.h"
22 #include "runtime/include/tooling/pt_object.h"
23 #include "runtime/mem/refstorage/global_object_storage.h"
24 #include "pt_hook_type_info.h"
25 
26 namespace panda::tooling {
27 class PtThreadInfo {
28 public:
29     PtThreadInfo() = default;
30 
~PtThreadInfo()31     ~PtThreadInfo()
32     {
33         ASSERT(managed_thread_ref_ == nullptr);
34     }
35 
GetHookTypeInfo()36     PtHookTypeInfo &GetHookTypeInfo()
37     {
38         return hook_type_info_;
39     }
40 
SetThreadObjectHeader(ObjectHeader * threadObjectHeader)41     void SetThreadObjectHeader(ObjectHeader *threadObjectHeader)
42     {
43         ASSERT(managed_thread_ref_ == nullptr);
44         managed_thread_ref_ = PandaVM::GetCurrent()->GetGlobalObjectStorage()->Add(threadObjectHeader,
45                                                                                    mem::Reference::ObjectType::GLOBAL);
46     }
47 
Destroy()48     void Destroy()
49     {
50         if (managed_thread_ref_ != nullptr) {
51             PandaVM::GetCurrent()->GetGlobalObjectStorage()->Remove(managed_thread_ref_);
52             managed_thread_ref_ = nullptr;
53         }
54     }
55 
GetThreadObjectHeader()56     ObjectHeader *GetThreadObjectHeader() const
57     {
58         ASSERT(managed_thread_ref_ != nullptr);
59         return PandaVM::GetCurrent()->GetGlobalObjectStorage()->Get(managed_thread_ref_);
60     }
61 
62 private:
63     PtHookTypeInfo hook_type_info_ {false};
64     mem::Reference *managed_thread_ref_ {nullptr};
65 
66     NO_COPY_SEMANTIC(PtThreadInfo);
67     NO_MOVE_SEMANTIC(PtThreadInfo);
68 };
69 }  // namespace panda::tooling
70 
71 #endif  // PANDA_TOOLING_PT_THREAD_INFO_H
72