1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 ** Some local variables report warnings on Win95 because the code paths
11 ** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
12 ** The pragma suppresses the warning.
15 # pragma warning(disable : 4101)
18 /* XXX use unbuffered nspr stdio */
20 PRFileDesc
* _pr_dumpOut
;
22 PRUint32
_PR_DumpPrintf(PRFileDesc
* fd
, const char* fmt
, ...) {
28 nb
= PR_vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
30 PR_Write(fd
, buf
, nb
);
35 void _PR_DumpThread(PRFileDesc
* fd
, PRThread
* thread
) {
36 #ifndef _PR_GLOBAL_THREADS_ONLY
37 _PR_DumpPrintf(fd
, "%05d[%08p] pri=%2d flags=0x%02x", thread
->id
, thread
,
38 thread
->priority
, thread
->flags
);
39 switch (thread
->state
) {
44 _PR_DumpPrintf(fd
, " lock=%p", thread
->wait
.lock
);
47 _PR_DumpPrintf(fd
, " condvar=%p sleep=%lldms", thread
->wait
.cvar
,
51 _PR_DumpPrintf(fd
, " suspended");
54 PR_Write(fd
, "\n", 1);
57 /* Now call dump routine */
59 thread
->dump(fd
, thread
, thread
->dumpArg
);
63 static void DumpThreadQueue(PRFileDesc
* fd
, PRCList
* list
) {
64 #ifndef _PR_GLOBAL_THREADS_ONLY
69 PRThread
* t
= _PR_THREAD_PTR(q
);
70 _PR_DumpThread(fd
, t
);
76 void _PR_DumpThreads(PRFileDesc
* fd
) {
80 _PR_DumpPrintf(fd
, "Current Thread:\n");
81 t
= _PR_MD_CURRENT_THREAD();
82 _PR_DumpThread(fd
, t
);
84 _PR_DumpPrintf(fd
, "Runnable Threads:\n");
85 for (i
= 0; i
< PR_ARRAY_SIZE(_PR_RUNQ(t
->cpu
)); i
++) {
86 DumpThreadQueue(fd
, &_PR_RUNQ(t
->cpu
)[i
]);
89 _PR_DumpPrintf(fd
, "CondVar timed wait Threads:\n");
90 DumpThreadQueue(fd
, &_PR_SLEEPQ(t
->cpu
));
92 _PR_DumpPrintf(fd
, "CondVar wait Threads:\n");
93 DumpThreadQueue(fd
, &_PR_PAUSEQ(t
->cpu
));
95 _PR_DumpPrintf(fd
, "Suspended Threads:\n");
96 DumpThreadQueue(fd
, &_PR_SUSPENDQ(t
->cpu
));
99 PR_IMPLEMENT(void) PR_ShowStatus(void) {
102 if (_PR_MD_CURRENT_THREAD() &&
103 !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
106 _pr_dumpOut
= _pr_stderr
;
107 _PR_DumpThreads(_pr_dumpOut
);
108 if (_PR_MD_CURRENT_THREAD() &&
109 !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
115 PR_SetThreadDumpProc(PRThread
* thread
, PRThreadDumpProc dump
, void* arg
) {
117 thread
->dumpArg
= arg
;