From 350df6c8caa021f3237486ea6b5145ee559f4d00 Mon Sep 17 00:00:00 2001 From: Jonathan Yong <10walls@gmail.com> Date: Wed, 28 May 2014 22:11:01 +0800 Subject: [PATCH 02/21] boehm-gc for cygwin --- boehm-gc/win32_threads.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/boehm-gc/win32_threads.c b/boehm-gc/win32_threads.c index 2de1c69..07ecde0 100644 --- a/boehm-gc/win32_threads.c +++ b/boehm-gc/win32_threads.c @@ -711,6 +711,54 @@ void * GC_start_routine(void * arg) return(result); } +void GC_register_my_thread() +{ + GC_thread me; + pthread_t my_pthread; + + my_pthread = pthread_self(); +# if DEBUG_CYGWIN_THREADS + GC_printf1("Attaching thread 0x%lx\n", my_pthread); + GC_printf1("pid = %ld\n", (long) getpid()); +# endif + + /* Check to ensure this thread isn't attached already. */ + LOCK(); + me = GC_lookup_thread (my_pthread); + UNLOCK(); + if (me != 0) + { +# if DEBUG_CYGWIN_THREADS + GC_printf1("Attempt to re-attach known thread 0x%lx\n", my_pthread); +# endif + return; + } + + LOCK(); + me = GC_new_thread(); + me -> flags |= DETACHED; + me -> pthread_id = pthread_self(); + UNLOCK(); +} + +void GC_unregister_my_thread() +{ + pthread_t my_pthread; + GC_thread me; + + my_pthread = pthread_self(); + +# if DEBUG_CYGWIN_THREADS + GC_printf1("Detaching thread 0x%lx\n", my_pthread); +# endif + + LOCK(); + me = GC_lookup_thread(my_pthread); + UNLOCK(); + GC_thread_exit_proc ((void *)me); +} + + void GC_thread_exit_proc(void *arg) { GC_thread me = (GC_thread)arg; -- 2.4.5