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