thread: implicitly create thread_t if an external thread calls thread_current()

This commit is contained in:
Martin Willi
2013-07-18 12:17:53 +02:00
parent 07a9d5c91a
commit 01c0267778
+14 -1
View File
@@ -341,7 +341,20 @@ thread_t *thread_create(thread_main_t main, void *arg)
*/
thread_t *thread_current()
{
return current_thread->get(current_thread);
private_thread_t *this;
this = (private_thread_t*)current_thread->get(current_thread);
if (!this)
{
this = thread_create_internal();
id_mutex->lock(id_mutex);
this->id = next_id++;
id_mutex->unlock(id_mutex);
current_thread->set(current_thread, (void*)this);
}
return &this->public;
}
/**