*: Remove remaining usages of legacy thread entry

Change-Id: If50cfed3d48efec6e2be0c1327a592f3acbd631c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/206856
Commit-Queue: Taylor Cramer <cramertj@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Aaron Green <aarongreen@google.com>
This commit is contained in:
Taylor Cramer 2024-04-26 23:49:43 +00:00 committed by CQ Bot Account
parent 74004ce595
commit 188bd4726e
2 changed files with 19 additions and 24 deletions

View File

@ -125,13 +125,7 @@ struct MpscTestContext {
using ThreadBody = Function<void(MpscTestContext* ctx)>;
void Spawn(ThreadBody func) {
body_ = std::move(func);
thread_ = thread::Thread(
context_.options(),
[](void* arg) {
auto* base = static_cast<MpscTestContext*>(arg);
base->body_(base);
},
this);
thread_ = thread::Thread(context_.options(), [this]() { body_(this); });
}
// Waits for the spawned thread to complete.

View File

@ -33,32 +33,33 @@
namespace pw::thread::freertos {
namespace {
sync::ThreadNotification lock_start;
sync::ThreadNotification lock_end;
void ForkedThreadEntry(void*) {
// Release start lock to allow test thread to continue execution.
lock_start.release();
while (true) {
// Return only when end lock released by test thread.
if (lock_end.try_acquire()) {
return;
}
}
}
// Tests thread iteration API by:
// - Forking a test thread.
// - Using iteration API to iterate over all running threads.
// - Compares name of forked thread and current thread.
// - Confirms thread exists and is iterated over.
TEST(ThreadIteration, ForkOneThread) {
struct {
sync::ThreadNotification start;
sync::ThreadNotification end;
} notify;
const auto& options = *static_cast<const pw::thread::freertos::Options*>(
&thread::test::TestOptionsThread0());
thread::Thread t(options, ForkedThreadEntry);
thread::Thread t(options, [&notify]() {
// Release start lock to allow test thread to continue execution.
notify.start.release();
while (true) {
// Return only when end lock released by test thread.
if (notify.end.try_acquire()) {
return;
}
}
});
// Blocked until thread t releases start lock.
lock_start.acquire();
notify.start.acquire();
struct {
bool thread_exists;
@ -92,7 +93,7 @@ TEST(ThreadIteration, ForkOneThread) {
thread::ForEachThread(cb);
// Signal to forked thread that execution is complete.
lock_end.release();
notify.end.release();
// Clean up the test thread context.
#if PW_THREAD_JOINING_ENABLED