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 "pw_thread_backend/id_native.h" 17 18 namespace pw::thread { 19 20 // The class thread::id is a lightweight, trivially copyable class that serves 21 // as a unique identifier of Thread objects. 22 // 23 // Instances of this class may also hold the special distinct value that does 24 // not represent any thread. Once a thread has finished, the value of 25 // Thread::id may be reused by another thread. 26 // 27 // This class is designed for use as key in associative containers, both 28 // ordered and unordered. 29 // 30 // The backend must ensure that: 31 // 1) There is a default construct which does not represent a thread. 32 // 2) Compare operators (==,!=,<,<=,>,>=) are provided to compare and sort IDs. 33 using Id = backend::NativeId; 34 35 } // namespace pw::thread 36 37 namespace pw::this_thread { 38 39 // This is thread safe, not IRQ safe. It is implementation defined whether this 40 // is safe before the scheduler has started. 41 thread::Id get_id() noexcept; 42 43 } // namespace pw::this_thread 44 45 // The backend can opt to include an inline implementation. 46 #if __has_include("pw_thread_backend/id_inline.h") 47 #include "pw_thread_backend/id_inline.h" 48 #endif // __has_include("pw_thread_backend/id_inline.h") 49