/* Helper function for thread_self in the case of user-provided stacks */ #ifndef THREAD_SELF /* User-resetable flag: find self using process ID. This allows LinuxThreads to work with user-level threads (which have their own stacks); but because of the syscall is rather slow, and won't work once we have CLONE_PID working. Orion Sky Lawlor, olawlor@acm.org, 2001/8/7 */ int __pthread_find_self_with_pid=0; pthread_descr __pthread_find_self() { if (__pthread_find_self_with_pid) { /* Determine current thread by matching the process ID */ int myPID=__getpid(); /* <- a syscall, and hence rather slow */ pthread_handle h; h = __pthread_handles; while (h->h_descr->p_pid != myPID) h++; return h->h_descr; } else { /*Determine current thread by searching for the stack pointer */ char * sp = CURRENT_STACK_FRAME; pthread_handle h; /* __pthread_handles[0] is the initial thread, __pthread_handles[1] is the manager threads handled specially in thread_self(), so start at 2 */ h = __pthread_handles + 2; while (! (sp <= (char *) h->h_descr && sp >= h->h_bottom)) h++; return h->h_descr; } } #endif