/* * Get current thread-local JSThread info, creating one if it doesn't exist. * Each thread has a unique JSThread pointer. * * Since we are dealing with thread-local data, no lock is needed. * * Return a pointer to the thread local info, NULL if the system runs out * of memory, or it failed to set thread private data (neither case is very * likely; both are probably due to out-of-memory). It is up to the caller * to report an error, if possible. */ JSThread * js_GetCurrentThread(JSRuntime *rt) { JSThread *thread; thread = (JSThread *)PR_GetThreadPrivate(threadTPIndex); if (!thread) { thread = (JSThread *) calloc(1, sizeof(JSThread)); if (!thread) return NULL; if (PR_FAILURE == PR_SetThreadPrivate(threadTPIndex, thread)) { free(thread); return NULL; } JS_INIT_CLIST(&thread->contextList); thread->id = js_CurrentThreadId(); /* js_SetContextThread initialize gcFreeLists as necessary. */ #ifdef DEBUG memset(thread->gcFreeLists, JS_FREE_PATTERN, sizeof(thread->gcFreeLists)); #endif } return thread; }
/* * Get current thread-local JSThread info, creating one if it doesn't exist. * Each thread has a unique JSThread pointer. * * Since we are dealing with thread-local data, no lock is needed. * * Return a pointer to the thread local info, NULL if the system runs out * of memory, or it failed to set thread private data (neither case is very * likely; both are probably due to out-of-memory). It is up to the caller * to report an error, if possible. */ JSThread * js_GetCurrentThread(JSRuntime *rt) { JSThread *thread; thread = (JSThread *)PR_GetThreadPrivate(rt->threadTPIndex); if (!thread) { /* New memory is set to 0 so that elements in gcFreeLists are NULL. */ thread = (JSThread *) calloc(1, sizeof(JSThread)); if (!thread) return NULL; if (PR_FAILURE == PR_SetThreadPrivate(rt->threadTPIndex, thread)) { free(thread); return NULL; } JS_INIT_CLIST(&thread->contextList); thread->id = js_CurrentThreadId(); } return thread; }