Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "primpl.h" |
michael@0 | 7 | |
michael@0 | 8 | #if defined(WIN95) |
michael@0 | 9 | /* |
michael@0 | 10 | ** Some local variables report warnings on Win95 because the code paths |
michael@0 | 11 | ** using them are conditioned on HAVE_CUSTOME_USER_THREADS. |
michael@0 | 12 | ** The pragma suppresses the warning. |
michael@0 | 13 | ** |
michael@0 | 14 | */ |
michael@0 | 15 | #pragma warning(disable : 4101) |
michael@0 | 16 | #endif |
michael@0 | 17 | |
michael@0 | 18 | /* XXX use unbuffered nspr stdio */ |
michael@0 | 19 | |
michael@0 | 20 | PRFileDesc *_pr_dumpOut; |
michael@0 | 21 | |
michael@0 | 22 | PRUint32 _PR_DumpPrintf(PRFileDesc *fd, const char *fmt, ...) |
michael@0 | 23 | { |
michael@0 | 24 | char buf[100]; |
michael@0 | 25 | PRUint32 nb; |
michael@0 | 26 | va_list ap; |
michael@0 | 27 | |
michael@0 | 28 | va_start(ap, fmt); |
michael@0 | 29 | nb = PR_vsnprintf(buf, sizeof(buf), fmt, ap); |
michael@0 | 30 | va_end(ap); |
michael@0 | 31 | PR_Write(fd, buf, nb); |
michael@0 | 32 | |
michael@0 | 33 | return nb; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void _PR_DumpThread(PRFileDesc *fd, PRThread *thread) |
michael@0 | 37 | { |
michael@0 | 38 | |
michael@0 | 39 | #ifndef _PR_GLOBAL_THREADS_ONLY |
michael@0 | 40 | _PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x", |
michael@0 | 41 | thread->id, thread, thread->priority, thread->flags); |
michael@0 | 42 | switch (thread->state) { |
michael@0 | 43 | case _PR_RUNNABLE: |
michael@0 | 44 | case _PR_RUNNING: |
michael@0 | 45 | break; |
michael@0 | 46 | case _PR_LOCK_WAIT: |
michael@0 | 47 | _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock); |
michael@0 | 48 | break; |
michael@0 | 49 | case _PR_COND_WAIT: |
michael@0 | 50 | _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms", |
michael@0 | 51 | thread->wait.cvar, thread->sleep); |
michael@0 | 52 | break; |
michael@0 | 53 | case _PR_SUSPENDED: |
michael@0 | 54 | _PR_DumpPrintf(fd, " suspended"); |
michael@0 | 55 | break; |
michael@0 | 56 | } |
michael@0 | 57 | PR_Write(fd, "\n", 1); |
michael@0 | 58 | #endif |
michael@0 | 59 | |
michael@0 | 60 | /* Now call dump routine */ |
michael@0 | 61 | if (thread->dump) { |
michael@0 | 62 | thread->dump(fd, thread, thread->dumpArg); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | static void DumpThreadQueue(PRFileDesc *fd, PRCList *list) |
michael@0 | 67 | { |
michael@0 | 68 | #ifndef _PR_GLOBAL_THREADS_ONLY |
michael@0 | 69 | PRCList *q; |
michael@0 | 70 | |
michael@0 | 71 | q = list->next; |
michael@0 | 72 | while (q != list) { |
michael@0 | 73 | PRThread *t = _PR_THREAD_PTR(q); |
michael@0 | 74 | _PR_DumpThread(fd, t); |
michael@0 | 75 | q = q->next; |
michael@0 | 76 | } |
michael@0 | 77 | #endif |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void _PR_DumpThreads(PRFileDesc *fd) |
michael@0 | 81 | { |
michael@0 | 82 | PRThread *t; |
michael@0 | 83 | PRIntn i; |
michael@0 | 84 | |
michael@0 | 85 | _PR_DumpPrintf(fd, "Current Thread:\n"); |
michael@0 | 86 | t = _PR_MD_CURRENT_THREAD(); |
michael@0 | 87 | _PR_DumpThread(fd, t); |
michael@0 | 88 | |
michael@0 | 89 | _PR_DumpPrintf(fd, "Runnable Threads:\n"); |
michael@0 | 90 | for (i = 0; i < 32; i++) { |
michael@0 | 91 | DumpThreadQueue(fd, &_PR_RUNQ(t->cpu)[i]); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | _PR_DumpPrintf(fd, "CondVar timed wait Threads:\n"); |
michael@0 | 95 | DumpThreadQueue(fd, &_PR_SLEEPQ(t->cpu)); |
michael@0 | 96 | |
michael@0 | 97 | _PR_DumpPrintf(fd, "CondVar wait Threads:\n"); |
michael@0 | 98 | DumpThreadQueue(fd, &_PR_PAUSEQ(t->cpu)); |
michael@0 | 99 | |
michael@0 | 100 | _PR_DumpPrintf(fd, "Suspended Threads:\n"); |
michael@0 | 101 | DumpThreadQueue(fd, &_PR_SUSPENDQ(t->cpu)); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | PR_IMPLEMENT(void) PR_ShowStatus(void) |
michael@0 | 105 | { |
michael@0 | 106 | PRIntn is; |
michael@0 | 107 | |
michael@0 | 108 | if ( _PR_MD_CURRENT_THREAD() |
michael@0 | 109 | && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_INTSOFF(is); |
michael@0 | 110 | _pr_dumpOut = _pr_stderr; |
michael@0 | 111 | _PR_DumpThreads(_pr_dumpOut); |
michael@0 | 112 | if ( _PR_MD_CURRENT_THREAD() |
michael@0 | 113 | && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_FAST_INTSON(is); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | PR_IMPLEMENT(void) |
michael@0 | 117 | PR_SetThreadDumpProc(PRThread* thread, PRThreadDumpProc dump, void *arg) |
michael@0 | 118 | { |
michael@0 | 119 | thread->dump = dump; |
michael@0 | 120 | thread->dumpArg = arg; |
michael@0 | 121 | } |