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