1 // Copyright 2024 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 namespace pw::thread { 17 18 /// The Options contains the parameters needed for a thread to start. 19 /// 20 /// Options are backend specific and ergo the generic base class cannot be 21 /// directly instantiated. 22 /// 23 /// The attributes which can be set through the options are backend specific 24 /// but may contain things like the thread name, priority, scheduling policy, 25 /// core/processor affinity, and/or an optional reference to a pre-allocated 26 /// Context (the collection of memory allocations needed for a thread to run). 27 /// 28 /// Options shall NOT have an attribute to start threads as detached vs 29 /// joinable. All `pw::Thread` instances must be explicitly `join()`'d or 30 /// `detach()`'d through the run-time Thread API. 31 /// 32 /// Note that if backends set `PW_THREAD_JOINING_ENABLED` to false, backends may 33 /// use native OS specific APIs to create native detached threads because the 34 /// `join()` API would be compiled out. However, users must still explicitly 35 /// invoke `detach()`. 36 /// 37 /// Options must not contain any memory needed for a thread to run (TCB, 38 /// stack, etc.). The Options may be deleted or re-used immediately after 39 /// starting a thread. 40 class Options { 41 protected: 42 // Must be explicit to prevent direct instantiation in C++17 with 43 // `pw::thread::Options{}` syntax. 44 explicit constexpr Options() = default; 45 }; 46 47 } // namespace pw::thread 48