diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2006-12-21 02:33:01 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2006-12-21 02:33:01 +0000 |
commit | d19ca324fcd8df0d62d1f7e8ee2b16c9bdbef0e8 (patch) | |
tree | 67c5394f5e63303ed3190607e4bb581958ce4681 /apps/plugins/battery_bench.c | |
parent | bb0358647d68e989d065ea70d95746fd2b6f4cad (diff) | |
download | rockbox-d19ca324fcd8df0d62d1f7e8ee2b16c9bdbef0e8.tar.gz rockbox-d19ca324fcd8df0d62d1f7e8ee2b16c9bdbef0e8.zip |
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
Diffstat (limited to 'apps/plugins/battery_bench.c')
-rw-r--r-- | apps/plugins/battery_bench.c | 18 |
1 files changed, 6 insertions, 12 deletions
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) | |||
111 | return main(); | 111 | return main(); |
112 | } | 112 | } |
113 | 113 | ||
114 | struct | 114 | bool thread_stopped = false; |
115 | { | ||
116 | struct thread_entry *id; | ||
117 | bool ended; | ||
118 | } s_thread; | ||
119 | 115 | ||
120 | /* Struct for battery information */ | 116 | /* Struct for battery information */ |
121 | struct batt_info | 117 | struct batt_info |
@@ -142,7 +138,7 @@ bool exit_tsr(bool reenter) | |||
142 | if (exit) | 138 | if (exit) |
143 | { | 139 | { |
144 | rb->queue_post(&thread_q, EV_EXIT, 0); | 140 | rb->queue_post(&thread_q, EV_EXIT, 0); |
145 | while (!s_thread.ended) | 141 | while (!thread_stopped) |
146 | rb->yield(); | 142 | rb->yield(); |
147 | /* remove the thread's queue from the broadcast list */ | 143 | /* remove the thread's queue from the broadcast list */ |
148 | rb->queue_delete(&thread_q); | 144 | rb->queue_delete(&thread_q); |
@@ -330,9 +326,8 @@ void thread(void) | |||
330 | #else | 326 | #else |
331 | "bench exit"); | 327 | "bench exit"); |
332 | #endif | 328 | #endif |
333 | s_thread.ended = true; | 329 | thread_stopped = true; |
334 | rb->remove_thread(s_thread.id); | 330 | rb->remove_thread(NULL); /* Suicide. Never returns. */ |
335 | rb->yield(); /* exit the thread, this yield() won't return */ | ||
336 | } | 331 | } |
337 | 332 | ||
338 | rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time); | 333 | rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time); |
@@ -482,10 +477,9 @@ int main(void) | |||
482 | } | 477 | } |
483 | 478 | ||
484 | rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */ | 479 | rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */ |
485 | rb->memset(&s_thread, 0, sizeof(s_thread)); /* zero the struct */ | 480 | if(rb->create_thread(thread, thread_stack, |
486 | if((s_thread.id = rb->create_thread(thread, thread_stack, | ||
487 | sizeof(thread_stack), "Battery Benchmark" | 481 | sizeof(thread_stack), "Battery Benchmark" |
488 | IF_PRIO(, PRIORITY_BACKGROUND))) == NULL) | 482 | IF_PRIO(, PRIORITY_BACKGROUND)) == NULL) |
489 | { | 483 | { |
490 | rb->splash(HZ,true,"Cannot create thread!"); | 484 | rb->splash(HZ,true,"Cannot create thread!"); |
491 | return PLUGIN_ERROR; | 485 | return PLUGIN_ERROR; |