1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Michael Sevakis 2006-12-21 02:33:01 +00:00
parent bb0358647d
commit d19ca324fc
2 changed files with 9 additions and 17 deletions

View file

@ -202,7 +202,6 @@ struct
/* communication to the worker thread */ /* communication to the worker thread */
struct struct
{ {
struct thread_entry *id; /* Pointer of the thread */
bool foreground; /* set as long as we're owning the UI */ bool foreground; /* set as long as we're owning the UI */
bool exiting; /* signal to the thread that we want to exit */ bool exiting; /* signal to the thread that we want to exit */
bool ended; /* response from the thread, that is has exited */ bool ended; /* response from the thread, that is has exited */
@ -1117,8 +1116,7 @@ void thread(void)
} while (!gTread.exiting); } while (!gTread.exiting);
gTread.ended = true; /* acknowledge the exit */ gTread.ended = true; /* acknowledge the exit */
rb->remove_thread(gTread.id); /* commit suicide */ rb->remove_thread(NULL); /* commit suicide */
rb->yield(); /* pass control to other threads, we won't return */
} }
/* callback to end the TSR plugin, called before a new one gets loaded */ /* callback to end the TSR plugin, called before a new one gets loaded */
@ -1172,8 +1170,8 @@ int main(void* parameter)
rb->memset(&gTread, 0, sizeof(gTread)); rb->memset(&gTread, 0, sizeof(gTread));
gTread.foreground = true; gTread.foreground = true;
gTread.id = rb->create_thread(thread, stack, stacksize, "CDC" rb->create_thread(thread, stack, stacksize, "CDC"
IF_PRIO(, PRIORITY_BACKGROUND)); IF_PRIO(, PRIORITY_BACKGROUND));
#ifdef DEBUG #ifdef DEBUG
do do

View file

@ -111,11 +111,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
return main(); return main();
} }
struct bool thread_stopped = false;
{
struct thread_entry *id;
bool ended;
} s_thread;
/* Struct for battery information */ /* Struct for battery information */
struct batt_info struct batt_info
@ -142,7 +138,7 @@ bool exit_tsr(bool reenter)
if (exit) if (exit)
{ {
rb->queue_post(&thread_q, EV_EXIT, 0); rb->queue_post(&thread_q, EV_EXIT, 0);
while (!s_thread.ended) while (!thread_stopped)
rb->yield(); rb->yield();
/* remove the thread's queue from the broadcast list */ /* remove the thread's queue from the broadcast list */
rb->queue_delete(&thread_q); rb->queue_delete(&thread_q);
@ -330,9 +326,8 @@ void thread(void)
#else #else
"bench exit"); "bench exit");
#endif #endif
s_thread.ended = true; thread_stopped = true;
rb->remove_thread(s_thread.id); rb->remove_thread(NULL); /* Suicide. Never returns. */
rb->yield(); /* exit the thread, this yield() won't return */
} }
rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time); 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->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(rb->create_thread(thread, thread_stack,
if((s_thread.id = rb->create_thread(thread, thread_stack,
sizeof(thread_stack), "Battery Benchmark" sizeof(thread_stack), "Battery Benchmark"
IF_PRIO(, PRIORITY_BACKGROUND))) == NULL) IF_PRIO(, PRIORITY_BACKGROUND)) == NULL)
{ {
rb->splash(HZ,true,"Cannot create thread!"); rb->splash(HZ,true,"Cannot create thread!");
return PLUGIN_ERROR; return PLUGIN_ERROR;