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 <thread> 17 18 namespace pw::thread { 19 Thread()20inline Thread::Thread() : native_type_() {} 21 Thread(const Options &,ThreadRoutine entry,void * arg)22inline Thread::Thread(const Options&, ThreadRoutine entry, void* arg) { 23 native_type_ = std::thread(entry, arg); 24 } 25 26 inline Thread& Thread::operator=(Thread&& other) { 27 native_type_ = std::move(other.native_type_); 28 return *this; 29 } 30 31 inline Thread::~Thread() = default; 32 get_id()33inline Id Thread::get_id() const { return native_type_.get_id(); } 34 join()35inline void Thread::join() { native_type_.join(); } 36 detach()37inline void Thread::detach() { native_type_.detach(); } 38 swap(Thread & other)39inline void Thread::swap(Thread& other) { 40 native_type_.swap(other.native_handle()); 41 } 42 native_handle()43inline Thread::native_handle_type Thread::native_handle() { 44 return native_type_; 45 } 46 47 } // namespace pw::thread 48