From: Martin Willi Date: Fri, 26 Apr 2013 14:59:34 +0000 (+0200) Subject: thread: implicitly create thread_t if an external thread calls thread_current() X-Git-Tag: 5.1.0rc1~25^2~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01c0267778ff137e6d841cda1382091055cf276d;p=thirdparty%2Fstrongswan.git thread: implicitly create thread_t if an external thread calls thread_current() --- diff --git a/src/libstrongswan/threading/thread.c b/src/libstrongswan/threading/thread.c index d6d98d1ef3..eb167d6a49 100644 --- a/src/libstrongswan/threading/thread.c +++ b/src/libstrongswan/threading/thread.c @@ -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; } /**