pw_function: Pass by reference or rvalue reference

Pass pw::Function by rvalue reference instead of by value, which saves
unnecessary moves and reduces code size.

Requires: pigweed-internal:17601
Change-Id: Ib96da4c35e95e2f2c54595ae0e6b0a9e58298f09
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/67943
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_thread_threadx/util.cc b/pw_thread_threadx/util.cc
index 078a51a..eee57b7 100644
--- a/pw_thread_threadx/util.cc
+++ b/pw_thread_threadx/util.cc
@@ -24,7 +24,8 @@
 
 // Iterates through all threads that haven't been deleted, calling the provided
 // callback.
-Status ForEachThread(const TX_THREAD& starting_thread, ThreadCallback& cb) {
+Status ForEachThread(const TX_THREAD& starting_thread,
+                     const ThreadCallback& cb) {
   const TX_THREAD* thread = &starting_thread;
   do {
     if (!cb(*thread)) {
@@ -39,7 +40,7 @@
 
 }  // namespace internal
 
-Status ForEachThread(ThreadCallback& cb) {
+Status ForEachThread(const ThreadCallback& cb) {
   return internal::ForEachThread(*_tx_thread_created_ptr, cb);
 }