1 // Copyright 2020 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 #pragma once 15 16 #include "tx_api.h" 17 18 namespace pw::thread::backend { 19 20 // Instead of using a pw::thread::threadx specific identifier, the ThreadX 21 // thread pointer is used as this means pw::this_thread::id works correctly on 22 // threads started with the native ThreadX APIs as well as those started 23 // using the pw::thread APIs. 24 class NativeId { 25 public: 26 constexpr NativeId(TX_THREAD* thread_ptr = nullptr) thread_ptr_(thread_ptr)27 : thread_ptr_(thread_ptr) {} 28 29 constexpr bool operator==(NativeId other) const { 30 return thread_ptr_ == other.thread_ptr_; 31 } 32 constexpr bool operator!=(NativeId other) const { 33 return thread_ptr_ != other.thread_ptr_; 34 } 35 constexpr bool operator<(NativeId other) const { 36 return thread_ptr_ < other.thread_ptr_; 37 } 38 constexpr bool operator<=(NativeId other) const { 39 return thread_ptr_ <= other.thread_ptr_; 40 } 41 constexpr bool operator>(NativeId other) const { 42 return thread_ptr_ > other.thread_ptr_; 43 } 44 constexpr bool operator>=(NativeId other) const { 45 return thread_ptr_ >= other.thread_ptr_; 46 } 47 48 private: 49 TX_THREAD* thread_ptr_; 50 }; 51 52 } // namespace pw::thread::backend 53