From d19ca324fcd8df0d62d1f7e8ee2b16c9bdbef0e8 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 21 Dec 2006 02:33:01 +0000 Subject: Lil' tweak to plugins using remove_thread. Just use remove_thread(NULL) to have a thread remove itself. No subsequent yield() is needed either. Small Note: in current scheduler implementation it safe to call remove_thread IFF 1) thread removes itself 2) its state is known to be running (1 implies 2) as any objects with the waiting removed thread will be corrupted (m->thread, q->thread no longer valid or no longer same object if recycled, etc.). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11826 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/battery_bench.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'apps/plugins/battery_bench.c') diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index bf0c2f32dd..4f1016b7eb 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c @@ -111,11 +111,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) return main(); } -struct -{ - struct thread_entry *id; - bool ended; -} s_thread; +bool thread_stopped = false; /* Struct for battery information */ struct batt_info @@ -142,7 +138,7 @@ bool exit_tsr(bool reenter) if (exit) { rb->queue_post(&thread_q, EV_EXIT, 0); - while (!s_thread.ended) + while (!thread_stopped) rb->yield(); /* remove the thread's queue from the broadcast list */ rb->queue_delete(&thread_q); @@ -330,9 +326,8 @@ void thread(void) #else "bench exit"); #endif - s_thread.ended = true; - rb->remove_thread(s_thread.id); - rb->yield(); /* exit the thread, this yield() won't return */ + thread_stopped = true; + rb->remove_thread(NULL); /* Suicide. Never returns. */ } rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time); @@ -482,10 +477,9 @@ int main(void) } rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */ - rb->memset(&s_thread, 0, sizeof(s_thread)); /* zero the struct */ - if((s_thread.id = rb->create_thread(thread, thread_stack, + if(rb->create_thread(thread, thread_stack, sizeof(thread_stack), "Battery Benchmark" - IF_PRIO(, PRIORITY_BACKGROUND))) == NULL) + IF_PRIO(, PRIORITY_BACKGROUND)) == NULL) { rb->splash(HZ,true,"Cannot create thread!"); return PLUGIN_ERROR; -- cgit v1.2.3