• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 #ifndef PANDA_RUNTIME_INCLUDE_TOOLING_PT_THREAD_H
16 #define PANDA_RUNTIME_INCLUDE_TOOLING_PT_THREAD_H
17 
18 #include <cstdint>
19 #include "libpandabase/macros.h"
20 #include "runtime/include/managed_thread.h"
21 
22 namespace ark::tooling {
23 class PtThread {
24 public:
PtThread(ManagedThread * managedThread)25     explicit PtThread(ManagedThread *managedThread) : managedThread_(managedThread) {}
26 
27     // Deprecated API
PtThread(uint32_t)28     explicit PtThread(uint32_t /* unused */) {}
29 
30     bool operator==(const PtThread &other) const
31     {
32         return managedThread_ == other.managedThread_;
33     }
34 
35     bool operator!=(const PtThread &other) const
36     {
37         return !(*this == other);
38     }
39 
40     bool operator<(const PtThread &other) const
41     {
42         return managedThread_ < other.managedThread_;
43     }
44 
GetId()45     uint32_t GetId() const
46     {
47         constexpr uint32_t PT_THREAD_NONE_ID = 0xffffffff;
48         return managedThread_ == nullptr ? PT_THREAD_NONE_ID : managedThread_->GetId();
49     }
50 
GetManagedThread()51     ManagedThread *GetManagedThread() const
52     {
53         return managedThread_;
54     }
55 
56     PANDA_PUBLIC_API static const PtThread NONE;
57 
58     ~PtThread() = default;
59 
60     DEFAULT_COPY_SEMANTIC(PtThread);
61     DEFAULT_MOVE_SEMANTIC(PtThread);
62 
63 private:
64     ManagedThread *managedThread_ {nullptr};
65 };
66 }  // namespace ark::tooling
67 
68 #endif  // PANDA_RUNTIME_INCLUDE_TOOLING_PT_THREAD_H
69