xref: /aosp_15_r20/external/pigweed/pw_thread_threadx/public/pw_thread_threadx/thread_inline.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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()25 inline 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()33 inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); }
34 
get_id()35 inline 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)42 inline void Thread::swap(Thread& other) {
43   std::swap(native_type_, other.native_type_);
44 }
45 
native_handle()46 inline Thread::native_handle_type Thread::native_handle() {
47   return native_type_;
48 }
49 
50 }  // namespace pw::thread
51