pw_thread: correct option setters to return a reference Corrects the backend specific thread Options setters to return a reference instead of a copy. Change-Id: Ifebcf742f0a0f65f5cc99d15df724e6acad10e49 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/46240 Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_thread_embos/public/pw_thread_embos/options.h b/pw_thread_embos/public/pw_thread_embos/options.h index fb33066..d024fde 100644 --- a/pw_thread_embos/public/pw_thread_embos/options.h +++ b/pw_thread_embos/public/pw_thread_embos/options.h
@@ -49,7 +49,7 @@ // Sets the name for the embOS task, this is optional. // Note that this will be deep copied into the context and may be truncated // based on PW_THREAD_EMBOS_CONFIG_MAX_THREAD_NAME_LEN. - constexpr Options set_name(const char* name) { + constexpr Options& set_name(const char* name) { name_ = name; return *this; } @@ -58,7 +58,7 @@ // see embOS OS_CreateTaskEx for more detail. // // Precondition: This must be >= PW_THREAD_EMBOS_CONFIG_MIN_PRIORITY. - constexpr Options set_priority(OS_PRIO priority) { + constexpr Options& set_priority(OS_PRIO priority) { PW_DASSERT(priority >= config::kMinimumPriority); priority_ = priority; return *this; @@ -70,7 +70,7 @@ // A value of 0 disables time-slicing of this thread. // // Precondition: This must be <= 255 ticks. - constexpr Options set_time_slice_interval(OS_UINT time_slice_interval) { + constexpr Options& set_time_slice_interval(OS_UINT time_slice_interval) { PW_DASSERT(time_slice_interval <= 255); time_slice_interval_ = time_slice_interval; return *this; @@ -78,7 +78,7 @@ // Set the pre-allocated context (all memory needed to run a thread), see the // pw::thread::embos::Context for more detail. - constexpr Options set_context(Context& context) { + constexpr Options& set_context(Context& context) { context_ = &context; return *this; }
diff --git a/pw_thread_freertos/public/pw_thread_freertos/options.h b/pw_thread_freertos/public/pw_thread_freertos/options.h index 7a70d12..f97c586 100644 --- a/pw_thread_freertos/public/pw_thread_freertos/options.h +++ b/pw_thread_freertos/public/pw_thread_freertos/options.h
@@ -49,7 +49,7 @@ // Sets the name for the FreeRTOS task, note that this will be truncated // based on configMAX_TASK_NAME_LEN. // This is deep copied by FreeRTOS into the task's task control block (TCB). - constexpr Options set_name(const char* name) { + constexpr Options& set_name(const char* name) { name_ = name; return *this; } @@ -57,7 +57,7 @@ // Sets the priority for the FreeRTOS task. This must be a value between // tskIDLE_PRIORITY or 0 to configMAX_PRIORITIES - 1. Higher priority values // have a higher priority. - constexpr Options set_priority(UBaseType_t priority) { + constexpr Options& set_priority(UBaseType_t priority) { priority_ = priority; return *this; } @@ -66,7 +66,7 @@ // Set the stack size of dynamic thread allocations. // // Precondition: size_words must be >= configMINIMAL_STACK_SIZE - constexpr Options set_stack_size(size_t size_words) { + constexpr Options& set_stack_size(size_t size_words) { PW_DASSERT(size_words >= config::kMinimumStackSizeWords); stack_size_words_ = size_words; return *this; @@ -75,7 +75,7 @@ // Set the pre-allocated context (all memory needed to run a thread), see the // pw::thread::freertos::StaticContext for more detail. - constexpr Options set_static_context(StaticContext& context) { + constexpr Options& set_static_context(StaticContext& context) { context_ = &context; return *this; }
diff --git a/pw_thread_threadx/public/pw_thread_threadx/options.h b/pw_thread_threadx/public/pw_thread_threadx/options.h index cdd3414..7c130a1 100644 --- a/pw_thread_threadx/public/pw_thread_threadx/options.h +++ b/pw_thread_threadx/public/pw_thread_threadx/options.h
@@ -53,7 +53,7 @@ // Sets the name for the ThreadX thread, note that this will be deep copied // into the context and may be truncated based on // PW_THREAD_THREADX_CONFIG_MAX_THREAD_NAME_LEN. - constexpr Options set_name(const char* name) { + constexpr Options& set_name(const char* name) { name_ = name; return *this; } @@ -61,7 +61,7 @@ // Sets the priority for the ThreadX thread from 0 through 31, where a value // of 0 represents the highest priority, see ThreadX tx_thread_create for // more detail. - constexpr Options set_priority(UINT priority) { + constexpr Options& set_priority(UINT priority) { PW_DASSERT(priority <= PW_THREAD_THREADX_CONFIG_MIN_PRIORITY); priority_ = priority; return *this; @@ -86,7 +86,7 @@ // initial threshold. // // Precondition: preemption_threshold <= priority - constexpr Options set_preemption_threshold(UINT preemption_threshold) { + constexpr Options& set_preemption_threshold(UINT preemption_threshold) { PW_DASSERT(preemption_threshold < PW_THREAD_THREADX_CONFIG_MIN_PRIORITY); possible_preemption_threshold_ = preemption_threshold; return *this; @@ -103,14 +103,14 @@ // // Using time slicing results in a slight amount of system overhead, threads // with a unique priority should consider TX_NO_TIME_SLICE. - constexpr Options set_time_slice_interval(ULONG time_slice_interval) { + constexpr Options& set_time_slice_interval(ULONG time_slice_interval) { time_slice_interval_ = time_slice_interval; return *this; } // Set the pre-allocated context (all memory needed to run a thread), see the // pw::thread::threadx::Context for more detail. - constexpr Options set_context(Context& context) { + constexpr Options& set_context(Context& context) { context_ = &context; return *this; }