1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
16 #include "pw_thread_backend/id_native.h"
18 namespace pw::thread {
20 // The class thread::id is a lightweight, trivially copyable class that serves
21 // as a unique identifier of Thread objects.
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.
27 // This class is designed for use as key in associative containers, both
28 // ordered and unordered.
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;
35 } // namespace pw::thread
37 namespace pw::this_thread {
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;
43 } // namespace pw::this_thread
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")