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 "nspr.h" michael@0: #include "prinrval.h" michael@0: #include "plgetopt.h" michael@0: #include "pprthred.h" michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: PRMonitor *mon; michael@0: PRInt32 count, iterations, alive; michael@0: michael@0: PRBool debug_mode = PR_FALSE, passed = PR_TRUE; michael@0: michael@0: void michael@0: PR_CALLBACK michael@0: ReallyDumbThread(void *arg) michael@0: { michael@0: return; michael@0: } michael@0: michael@0: void michael@0: PR_CALLBACK michael@0: DumbThread(void *arg) michael@0: { michael@0: PRInt32 tmp = (PRInt32)arg; michael@0: PRThreadScope scope = (PRThreadScope)tmp; michael@0: PRThread *thr; michael@0: michael@0: thr = PR_CreateThread(PR_USER_THREAD, michael@0: ReallyDumbThread, michael@0: NULL, michael@0: PR_PRIORITY_NORMAL, michael@0: scope, michael@0: PR_JOINABLE_THREAD, michael@0: 0); michael@0: michael@0: if (!thr) { michael@0: if (debug_mode) { michael@0: printf("Could not create really dumb thread (%d, %d)!\n", michael@0: PR_GetError(), PR_GetOSError()); michael@0: } michael@0: passed = PR_FALSE; michael@0: } else { 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: } michael@0: michael@0: static void CreateThreads(PRThreadScope scope1, PRThreadScope scope2) michael@0: { michael@0: PRThread *thr; michael@0: int n; michael@0: michael@0: alive = 0; michael@0: mon = PR_NewMonitor(); michael@0: michael@0: alive = count; michael@0: for (n=0; noption) michael@0: { michael@0: case 'd': /* debug mode */ michael@0: debug_mode = PR_TRUE; michael@0: break; michael@0: case 'c': /* loop counter */ michael@0: count = atoi(opt->value); michael@0: break; michael@0: case 'i': /* loop counter */ michael@0: iterations = atoi(opt->value); michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: } michael@0: michael@0: if (0 == count) count = 50; michael@0: if (0 == iterations) iterations = 10; michael@0: michael@0: if (debug_mode) michael@0: { michael@0: printf("\ michael@0: ** Tests lots of thread creations. \n\ michael@0: ** Create %ld native threads %ld times. \n\ michael@0: ** Create %ld user threads %ld times \n", iterations,count,iterations,count); michael@0: } michael@0: michael@0: for (index=0; index