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