1 // Copyright 2021 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 <algorithm> 17 18 #include "pw_assert/assert.h" 19 #include "pw_thread/thread.h" 20 #include "pw_thread_threadx/config.h" 21 #include "pw_thread_threadx/options.h" 22 23 namespace pw::thread { 24 Thread()25inline Thread::Thread() : native_type_(nullptr) {} 26 27 inline Thread& Thread::operator=(Thread&& other) { 28 native_type_ = other.native_type_; 29 other.native_type_ = nullptr; 30 return *this; 31 } 32 ~Thread()33inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); } 34 get_id()35inline Thread::id Thread::get_id() const { 36 if (native_type_ == nullptr) { 37 return Thread::id(nullptr); 38 } 39 return Thread::id(&native_type_->tcb()); 40 } 41 swap(Thread & other)42inline void Thread::swap(Thread& other) { 43 std::swap(native_type_, other.native_type_); 44 } 45 native_handle()46inline Thread::native_handle_type Thread::native_handle() { 47 return native_type_; 48 } 49 50 } // namespace pw::thread 51