diff options
-rw-r--r-- | winsup/cygwin/ChangeLog | 27 | ||||
-rw-r--r-- | winsup/cygwin/cygtls.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/cygtls.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/dtable.cc | 11 | ||||
-rw-r--r-- | winsup/cygwin/dtable.h | 10 | ||||
-rw-r--r-- | winsup/cygwin/exceptions.cc | 18 | ||||
-rw-r--r-- | winsup/cygwin/init.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/sync.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/sync.h | 11 |
10 files changed, 61 insertions, 33 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 2e91790190b..d97bd08e441 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,30 @@ +2004-01-13 Christopher Faylor <cgf@redhat.com> + + * cygtls.cc (_threadinfo::init_thread): Correct thinko which caused + thread list to be allocated every time. + * cygtls.h (CYGTLS_PADSIZE): Define as const int. + * sync.h: Make multiple inclusion safe. + (muto::next): Eliminate. + (muto::exiting_thread): New variable. + (muto::set_exiting_thread): New function. + (new_muto): Change to use different section for mutos since c++ give + inexplicable warning in some cases otherwise. + (new_muto1): Ditto. + * dcrt0.cc (do_exit): Call muto::set_exiting_thread here. + * sync.cc (muto_start): Eliminate. + (muto::acquire): Always give exiting thread a lock. Never give thread + a lock if exiting. + (muto::release): Ditto for releasing. + * dtable.cc (dtable::init_lock): Unline function and define here. + * dtable.h (lock_cs): Define as a muto since critical sections seem to + work oddly on Windows Me. + (lock): Accommodate switch to muto. + (unlock): Ditto. + * exceptions.cc (setup_handler): Don't worry about acquiring mutos + since that hasn't mattered for a long time. + (signal_exit): Ditto: muto stuff will be handled automatically on exit + now. + 2004-01-12 Christopher Faylor <cgf@redhat.com> * Makefile.in (DLL_IMPORTS): Link advapi32 to ensure proper DLL diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index 4514ba15dc8..5c9fa615f2e 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -120,7 +120,7 @@ _threadinfo::init_thread (void *x, DWORD (*func) (void *, void *)) return; sentry here (INFINITE); - if (nthreads < cygheap->sthreads) + if (nthreads >= cygheap->sthreads) { cygheap->threadlist = (_threadinfo **) crealloc (cygheap->threadlist, (cygheap->sthreads += THREADLIST_CHUNK) diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index f3fadfb4ea4..ff07fc69df2 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -142,5 +142,5 @@ extern _threadinfo *_main_tls; #define __getreent() (&_my_tls.local_clib) -enum {CYGTLS_PADSIZE = (((char *) _main_tls->padding) - ((char *) _main_tls))}; +const int CYGTLS_PADSIZE = (((char *) _main_tls->padding) - ((char *) _main_tls)); #endif /*_CYGTLS_H*/ diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 57a26aca2e0..438faaa5f36 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -991,6 +991,7 @@ do_exit (int status) } EnterCriticalSection (&exit_lock); + muto::set_exiting_thread (); if (exit_state < ES_EVENTS_TERMINATE) { exit_state = ES_EVENTS_TERMINATE; diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 46e91e6f895..ac9146cdcd5 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -33,13 +33,13 @@ details. */ #include "ntdll.h" #include "tty.h" +static const char NO_COPY unknown_file[] = "some disk file"; + static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE}; static const char *handle_to_fn (HANDLE, char *); -static const char NO_COPY unknown_file[] = "some disk file"; - /* Set aside space for the table of fds */ void dtable_init () @@ -59,6 +59,13 @@ set_std_handle (int fd) SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ()); } +void +dtable::init_lock () +{ + new_muto (lock_cs); + // InitializeCriticalSection (&lock_cs); +} + int dtable::extend (int howmuch) { diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index 2f10c2afaf4..45de441d081 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -12,6 +12,7 @@ details. */ #define NOFILE_INCR 32 #include "thread.h" +#include "sync.h" class suffix_info; class fhandler_fifo; @@ -19,7 +20,8 @@ class fhandler_fifo; #define BFH_OPTS (PC_NULLEMPTY | PC_FULL | PC_POSIX) class dtable { - CRITICAL_SECTION lock_cs; + muto *lock_cs; + //CRITICAL_SECTION lock_cs; fhandler_base **fds; fhandler_base **fds_on_hold; fhandler_base **archetypes; @@ -28,9 +30,9 @@ class dtable static const int initial_archetype_size = 8; int first_fd_for_open; int cnt_need_fixup_before; - void lock () {EnterCriticalSection (&lock_cs); spf ("%u locked, tid %u\n", GetCurrentProcessId (), GetCurrentThreadId ());} - void unlock () {LeaveCriticalSection (&lock_cs); spf ("%u ulocked, tid %u\n", GetCurrentProcessId (), GetCurrentThreadId ());} - void init_lock () {InitializeCriticalSection (&lock_cs); spf ("%u initialized, tid %u\n", GetCurrentProcessId (), GetCurrentThreadId ());} + void lock () {lock_cs->acquire ();} + void unlock () {lock_cs->release ();} + void init_lock (); public: size_t size; diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index e30d8fd261e..597c58e47d1 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -763,26 +763,16 @@ setup_handler (int sig, void *handler, struct sigaction& siga, _threadinfo *tls) // FIXME - add check for reentering of DLL here - muto *m; - /* FIXME: Make multi-thread aware */ - for (m = muto_start.next; m != NULL; m = m->next) - if (m->unstable () || m->owner () == cygthread::main_thread_id) - { - sigproc_printf ("suspended thread owns a muto (%s)", m->name); - goto resume_thread; - } - cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; if (!GetThreadContext (hth, &cx)) system_printf ("couldn't get context of main thread, %E"); else if (interruptible (cx.Eip)) interrupted = tls->interrupt_now (&cx, sig, handler, siga); - resume_thread: res = ResumeThread (hth); - if (interrupted) break; + sigproc_printf ("couldn't interrupt. trying again."); low_priority_sleep (0); } @@ -1033,12 +1023,6 @@ signal_exit (int rc) (void) SetThreadPriority (hMainThread, THREAD_PRIORITY_IDLE); (void) SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); - /* Unlock any main thread mutos since we're executing with prejudice. */ - muto *m; - for (m = muto_start.next; m != NULL; m = m->next) - if (m->unstable () || m->owner () == cygthread::main_thread_id) - m->reset (); - user_data->resourcelocks->Delete (); user_data->resourcelocks->Init (); diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index 6b3de8fa817..a85a8a27013 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -91,10 +91,10 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) switch (reason) { case DLL_PROCESS_ATTACH: + prime_threads (); dynamically_loaded = (static_load == NULL); // __cygwin_user_data.impure_ptr = &_my_tls.local_clib; dll_crt0_0 (); - prime_threads (); // small_printf ("%u, %p, %p\n", cygwin_pid (GetCurrentProcessId ()), _tlstop, _tlsbase); break; case DLL_PROCESS_DETACH: diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc index 77b9bf4e7b5..dbc26304b13 100644 --- a/winsup/cygwin/sync.cc +++ b/winsup/cygwin/sync.cc @@ -23,10 +23,10 @@ details. */ #include "sync.h" #include "security.h" -muto NO_COPY muto_start; - #undef WaitForSingleObject +DWORD NO_COPY muto::exiting_thread; + /* Constructor */ muto * muto::init (const char *s) @@ -40,8 +40,6 @@ muto::init (const char *s) return NULL; } name = s; - next = muto_start.next; - muto_start.next = this; return this; } @@ -71,6 +69,8 @@ int muto::acquire (DWORD ms) { DWORD this_tid = GetCurrentThreadId (); + if (exiting_thread) + return this_tid == exiting_thread; if (tid != this_tid) { @@ -113,6 +113,8 @@ int muto::release () { DWORD this_tid = GetCurrentThreadId (); + if (exiting_thread) + return this_tid == exiting_thread; if (tid != this_tid || !visits) { diff --git a/winsup/cygwin/sync.h b/winsup/cygwin/sync.h index dfc4ba7faa3..3ae09373f6d 100644 --- a/winsup/cygwin/sync.h +++ b/winsup/cygwin/sync.h @@ -10,17 +10,20 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#ifndef _SYNC_H +#define _SYNC_H /* FIXME: Note that currently this class cannot be allocated via `new' since there are issues with malloc and fork. */ class muto { + static DWORD exiting_thread; LONG sync; /* Used to serialize access to this class. */ LONG visits; /* Count of number of times a thread has called acquire. */ LONG waiters; /* Number of threads waiting for lock. */ HANDLE bruteforce; /* event handle used to control waiting for lock. */ DWORD tid; /* Thread Id of lock owner. */ public: - class muto *next; + // class muto *next; const char *name; /* The real constructor. */ @@ -38,6 +41,7 @@ public: int unstable () {return !tid && (sync || waiters >= 0);} void reset () __attribute__ ((regparm (1))); bool acquired (); + static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();} }; extern muto muto_start; @@ -45,13 +49,14 @@ extern muto muto_start; /* Use a statically allocated buffer as the storage for a muto */ #define new_muto(__name) \ ({ \ - static muto __name##_storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \ + static muto __name##_storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \ __name = __name##_storage.init (#__name); \ }) /* Use a statically allocated buffer as the storage for a muto */ #define new_muto1(__name, __storage) \ ({ \ - static muto __storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \ + static muto __storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \ __name = __storage.init (#__name); \ }) +#endif /*_SYNC_H*/ |