From 2b6d15a90833dd2e3aa2aa758813e721fe94a0ca Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 6 Dec 2003 18:08:38 +0000 Subject: * cygtls.h: Add more "don't parse this" guards. (_threadinfo::init_thread): Rename from 'init'. (_threadinfo::init): Declare new function. (_threadinfo::protect_linked_list): Declare new critical section. * dcrt0.cc (dll_crt0_1): Call init_thread to initialize thread stuff. (_dll_crt0): Call _threadinfo::init prior to invoking dll_crt0_1. * exceptions.cc (_threadinfo::init_thread): Rename from 'init'. (_threadinfo::init): Define new function. Protect linked list manipulation with new critical section. (_threadinfo::call): Reflect function name change. (_threadinfo::remove): Protect linked list manipulation with new critical section * gentls_offsets: Rework to allow multi-line "don't parse this" protection. * init.cc (dll_entry): Don't remove threads info stuff here since the remove function uses a critical section which can't be used during thread creation or destruction. * thread.cc (pthread::exit): Call _threadinfo remove function here. --- winsup/cygwin/exceptions.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'winsup/cygwin/exceptions.cc') diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index bc6f6e6ed..cb2db165f 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -40,6 +40,8 @@ _threadinfo NO_COPY dummy_thread; _threadinfo NO_COPY *_last_thread = &dummy_thread; extern _threadinfo *_main_tls; +CRITICAL_SECTION NO_COPY _threadinfo::protect_linked_list; + extern DWORD sigtid; extern HANDLE hExeced; @@ -157,18 +159,28 @@ _threadinfo::call (void (*func) (void *, void *), void *arg) void _threadinfo::call2 (void (*func) (void *, void *), void *arg, void *buf) { - init (buf); + init_thread (buf); func (arg, buf); } void -_threadinfo::init (void *) +_threadinfo::init () +{ + InitializeCriticalSection (&protect_linked_list); +} + +void +_threadinfo::init_thread (void *) { memset (this, 0, sizeof (*this)); stackptr = stack; + + EnterCriticalSection (&protect_linked_list); prev = _last_thread; _last_thread->next = this; _last_thread = this; + LeaveCriticalSection (&protect_linked_list); + set_state (false); errno_addr = &errno; } @@ -177,6 +189,7 @@ void _threadinfo::remove () { _threadinfo *t; + EnterCriticalSection (&protect_linked_list); for (t = _last_thread; t && t != this; t = t->prev) continue; if (!t) @@ -186,6 +199,7 @@ _threadinfo::remove () t->next->prev = t->prev; if (t == _last_thread) _last_thread = t->prev; + LeaveCriticalSection (&protect_linked_list); } void -- cgit v1.2.3