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_embos/context.h" 21 22 namespace pw::thread { 23 Thread()24inline Thread::Thread() : native_type_(nullptr) {} 25 26 inline Thread& Thread::operator=(Thread&& other) { 27 native_type_ = other.native_type_; 28 other.native_type_ = nullptr; 29 return *this; 30 } 31 ~Thread()32inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); } 33 get_id()34inline Thread::id Thread::get_id() const { 35 if (native_type_ == nullptr) { 36 return Thread::id(nullptr); 37 } 38 return Thread::id(&native_type_->tcb()); 39 } 40 swap(Thread & other)41inline void Thread::swap(Thread& other) { 42 std::swap(native_type_, other.native_type_); 43 } 44 native_handle()45inline Thread::native_handle_type Thread::native_handle() { 46 return native_type_; 47 } 48 49 } // namespace pw::thread 50