andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #include "primpl.h" andre@0: andre@0: #if defined(WIN95) andre@0: /* andre@0: ** Some local variables report warnings on Win95 because the code paths andre@0: ** using them are conditioned on HAVE_CUSTOME_USER_THREADS. andre@0: ** The pragma suppresses the warning. andre@0: ** andre@0: */ andre@0: #pragma warning(disable : 4101) andre@0: #endif andre@0: andre@0: /* XXX use unbuffered nspr stdio */ andre@0: andre@0: PRFileDesc *_pr_dumpOut; andre@0: andre@0: PRUint32 _PR_DumpPrintf(PRFileDesc *fd, const char *fmt, ...) andre@0: { andre@0: char buf[100]; andre@0: PRUint32 nb; andre@0: va_list ap; andre@0: andre@0: va_start(ap, fmt); andre@0: nb = PR_vsnprintf(buf, sizeof(buf), fmt, ap); andre@0: va_end(ap); andre@0: PR_Write(fd, buf, nb); andre@0: andre@0: return nb; andre@0: } andre@0: andre@0: void _PR_DumpThread(PRFileDesc *fd, PRThread *thread) andre@0: { andre@0: andre@0: #ifndef _PR_GLOBAL_THREADS_ONLY andre@0: _PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x", andre@0: thread->id, thread, thread->priority, thread->flags); andre@0: switch (thread->state) { andre@0: case _PR_RUNNABLE: andre@0: case _PR_RUNNING: andre@0: break; andre@0: case _PR_LOCK_WAIT: andre@0: _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock); andre@0: break; andre@0: case _PR_COND_WAIT: andre@0: _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms", andre@0: thread->wait.cvar, thread->sleep); andre@0: break; andre@0: case _PR_SUSPENDED: andre@0: _PR_DumpPrintf(fd, " suspended"); andre@0: break; andre@0: } andre@0: PR_Write(fd, "\n", 1); andre@0: #endif andre@0: andre@0: /* Now call dump routine */ andre@0: if (thread->dump) { andre@0: thread->dump(fd, thread, thread->dumpArg); andre@0: } andre@0: } andre@0: andre@0: static void DumpThreadQueue(PRFileDesc *fd, PRCList *list) andre@0: { andre@0: #ifndef _PR_GLOBAL_THREADS_ONLY andre@0: PRCList *q; andre@0: andre@0: q = list->next; andre@0: while (q != list) { andre@0: PRThread *t = _PR_THREAD_PTR(q); andre@0: _PR_DumpThread(fd, t); andre@0: q = q->next; andre@0: } andre@0: #endif andre@0: } andre@0: andre@0: void _PR_DumpThreads(PRFileDesc *fd) andre@0: { andre@0: PRThread *t; andre@0: PRIntn i; andre@0: andre@0: _PR_DumpPrintf(fd, "Current Thread:\n"); andre@0: t = _PR_MD_CURRENT_THREAD(); andre@0: _PR_DumpThread(fd, t); andre@0: andre@0: _PR_DumpPrintf(fd, "Runnable Threads:\n"); andre@0: for (i = 0; i < 32; i++) { andre@0: DumpThreadQueue(fd, &_PR_RUNQ(t->cpu)[i]); andre@0: } andre@0: andre@0: _PR_DumpPrintf(fd, "CondVar timed wait Threads:\n"); andre@0: DumpThreadQueue(fd, &_PR_SLEEPQ(t->cpu)); andre@0: andre@0: _PR_DumpPrintf(fd, "CondVar wait Threads:\n"); andre@0: DumpThreadQueue(fd, &_PR_PAUSEQ(t->cpu)); andre@0: andre@0: _PR_DumpPrintf(fd, "Suspended Threads:\n"); andre@0: DumpThreadQueue(fd, &_PR_SUSPENDQ(t->cpu)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(void) PR_ShowStatus(void) andre@0: { andre@0: PRIntn is; andre@0: andre@0: if ( _PR_MD_CURRENT_THREAD() andre@0: && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_INTSOFF(is); andre@0: _pr_dumpOut = _pr_stderr; andre@0: _PR_DumpThreads(_pr_dumpOut); andre@0: if ( _PR_MD_CURRENT_THREAD() andre@0: && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_FAST_INTSON(is); andre@0: } andre@0: andre@0: PR_IMPLEMENT(void) andre@0: PR_SetThreadDumpProc(PRThread* thread, PRThreadDumpProc dump, void *arg) andre@0: { andre@0: thread->dump = dump; andre@0: thread->dumpArg = arg; andre@0: }