+2011-05-10 Ivan Maidanski <ivmai@mail.ru>
+
+ * pthread_support.c (GC_unregister_my_thread): Call pthread_self
+ only once.
+ * win32_threads.c (GC_pthread_start_inner): Ditto.
+ * pthread_support.c (GC_unregister_my_thread): Add debug output.
+ * win32_threads.c (GC_unregister_my_thread): Ditto.
+ * pthread_support.c (GC_register_my_thread,
+ GC_start_rtn_prepare_thread): Rename "my_pthread" local variable
+ to "self".
+
2011-05-10 Ivan Maidanski <ivmai@mail.ru>
* include/gc.h (GC_HIDE_POINTER, GC_REVEAL_POINTER): Define
GC_API int GC_CALL GC_unregister_my_thread(void)
{
+ pthread_t self = pthread_self();
GC_thread me;
IF_CANCEL(int cancel_state;)
DCL_LOCK_STATE;
+# ifdef DEBUG_THREADS
+ GC_log_printf("Unregistering thread 0x%x\n", (unsigned)self);
+# endif
LOCK();
DISABLE_CANCEL(cancel_state);
/* Wait for any GC that may be marking from our stack to */
/* complete before we remove this thread. */
GC_wait_for_gc_completion(FALSE);
- me = GC_lookup_thread(pthread_self());
+ me = GC_lookup_thread(self);
GC_ASSERT(!(me -> flags & FINISHED));
# if defined(THREAD_LOCAL_ALLOC)
GC_destroy_thread_local(&(me->tlfs));
}
# endif
if (me -> flags & DETACHED) {
- GC_delete_thread(pthread_self());
+ GC_delete_thread(self);
} else {
me -> flags |= FINISHED;
}
GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
{
- pthread_t my_pthread = pthread_self();
+ pthread_t self = pthread_self();
GC_thread me;
DCL_LOCK_STATE;
ABORT("Threads explicit registering is not previously enabled");
LOCK();
- me = GC_lookup_thread(my_pthread);
+ me = GC_lookup_thread(self);
if (0 == me) {
- me = GC_register_my_thread_inner(sb, my_pthread);
+ me = GC_register_my_thread_inner(sb, self);
me -> flags |= DETACHED;
/* Treat as detached, since we do not need to worry about */
/* pointer results. */
struct GC_stack_base *sb, void *arg)
{
struct start_info * si = arg;
+ pthread_t self = pthread_self();
GC_thread me;
- pthread_t my_pthread;
DCL_LOCK_STATE;
- my_pthread = pthread_self();
# ifdef DEBUG_THREADS
GC_log_printf("Starting thread 0x%x, pid = %ld, sp = %p\n",
- (unsigned)my_pthread, (long)getpid(), &arg);
+ (unsigned)self, (long)getpid(), &arg);
# endif
LOCK();
- me = GC_register_my_thread_inner(sb, my_pthread);
+ me = GC_register_my_thread_inner(sb, self);
me -> flags = si -> flags;
# if defined(THREAD_LOCAL_ALLOC)
GC_init_thread_local(&(me->tlfs));
{
DCL_LOCK_STATE;
+# ifdef DEBUG_THREADS
+ GC_log_printf("Unregistering thread 0x%lx\n", (long)GetCurrentThreadId());
+# endif
+
/* FIXME: is GC_wait_for_gc_completion(FALSE) needed here? */
if (GC_win32_dll_threads) {
# if defined(THREAD_LOCAL_ALLOC)
pthread_cleanup_pop(1);
# ifdef DEBUG_THREADS
- GC_log_printf("thread %p(0x%lx) returned from start routine\n",
- GC_PTHREAD_PTRVAL(pthread_self()),
- (long)GetCurrentThreadId());
+ GC_log_printf("thread %p(0x%x) returned from start routine\n",
+ GC_PTHREAD_PTRVAL(pthread_id), (int)thread_id);
# endif
return(result);
}