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: #ifdef XP_BEOS michael@0: #include michael@0: int main() michael@0: { michael@0: printf( "This test is not ported to the BeOS\n" ); michael@0: return 0; michael@0: } michael@0: #else michael@0: michael@0: #include "nspr.h" michael@0: #include "prpriv.h" michael@0: #include "prinrval.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: PRMonitor *mon; michael@0: PRInt32 count; michael@0: PRInt32 alive; michael@0: michael@0: #define SLEEP_TIME 4 /* secs */ michael@0: michael@0: void PR_CALLBACK michael@0: Level_2_Thread(void *arg) michael@0: { michael@0: PR_Sleep(PR_MillisecondsToInterval(4 * 1000)); michael@0: printf("Level_2_Thread[0x%lx] exiting\n",PR_GetCurrentThread()); michael@0: return; michael@0: } michael@0: michael@0: void PR_CALLBACK michael@0: Level_1_Thread(void *arg) michael@0: { michael@0: PRUint32 tmp = (PRUint32)arg; michael@0: PRThreadScope scope = (PRThreadScope) tmp; michael@0: PRThread *thr; michael@0: michael@0: thr = PR_CreateThreadGCAble(PR_USER_THREAD, michael@0: Level_2_Thread, michael@0: NULL, michael@0: PR_PRIORITY_HIGH, michael@0: scope, michael@0: PR_JOINABLE_THREAD, michael@0: 0); michael@0: michael@0: if (!thr) { michael@0: printf("Could not create thread!\n"); michael@0: } else { michael@0: printf("Level_1_Thread[0x%lx] created %15s thread 0x%lx\n", michael@0: PR_GetCurrentThread(), michael@0: (scope == PR_GLOBAL_THREAD) ? michael@0: "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD", michael@0: thr); michael@0: PR_JoinThread(thr); michael@0: } michael@0: PR_EnterMonitor(mon); michael@0: alive--; michael@0: PR_Notify(mon); michael@0: PR_ExitMonitor(mon); michael@0: printf("Thread[0x%lx] exiting\n",PR_GetCurrentThread()); michael@0: } michael@0: michael@0: static PRStatus PR_CALLBACK print_thread(PRThread *thread, int i, void *arg) michael@0: { michael@0: PRInt32 words; michael@0: PRWord *registers; michael@0: michael@0: printf( michael@0: "\nprint_thread[0x%lx]: %-20s - i = %ld\n",thread, michael@0: (PR_GLOBAL_THREAD == PR_GetThreadScope(thread)) ? michael@0: "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD", i); michael@0: registers = PR_GetGCRegisters(thread, 0, (int *)&words); michael@0: if (registers) michael@0: printf("Registers R0 = 0x%x R1 = 0x%x R2 = 0x%x R3 = 0x%x\n", michael@0: registers[0],registers[1],registers[2],registers[3]); michael@0: printf("Stack Pointer = 0x%lx\n", PR_GetSP(thread)); michael@0: return PR_SUCCESS; michael@0: } michael@0: michael@0: static void Level_0_Thread(PRThreadScope scope1, PRThreadScope scope2) michael@0: { michael@0: PRThread *thr; michael@0: PRThread *me = PR_GetCurrentThread(); michael@0: int n; michael@0: PRInt32 words; michael@0: PRWord *registers; michael@0: michael@0: alive = 0; michael@0: mon = PR_NewMonitor(); michael@0: michael@0: alive = count; michael@0: for (n=0; n 1) { michael@0: count = atoi(argv[1]); michael@0: } else { michael@0: count = 5; michael@0: } michael@0: michael@0: printf("\n\n%20s%30s\n\n"," ","Suspend_Resume Test"); michael@0: CreateThreadsUU(); michael@0: CreateThreadsUK(); michael@0: CreateThreadsKU(); michael@0: CreateThreadsKK(); michael@0: PR_SetConcurrency(2); michael@0: michael@0: printf("\n%20s%30s\n\n"," ","Added 2nd CPU\n"); michael@0: michael@0: CreateThreadsUK(); michael@0: CreateThreadsKK(); michael@0: CreateThreadsUU(); michael@0: CreateThreadsKU(); michael@0: PR_Cleanup(); michael@0: michael@0: return 0; michael@0: } michael@0: michael@0: #endif /* XP_BEOS */