nsprpub/pr/tests/short_thread.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 <stdio.h>
michael@0 7 #include "nspr.h"
michael@0 8 #include "plgetopt.h"
michael@0 9
michael@0 10 /*
michael@0 11 * Create a thread that exits right away; useful for testing race conditions in thread
michael@0 12 * creation
michael@0 13 */
michael@0 14
michael@0 15 int _debug_on = 0;
michael@0 16 #define DPRINTF(arg) if (_debug_on) printf arg
michael@0 17
michael@0 18 static void housecleaning(void *cur_time);
michael@0 19
michael@0 20 int main (int argc, char **argv)
michael@0 21 {
michael@0 22 static PRIntervalTime thread_start_time;
michael@0 23 static PRThread *housekeeping_tid = NULL;
michael@0 24 PLOptStatus os;
michael@0 25 PLOptState *opt = PL_CreateOptState(argc, argv, "d");
michael@0 26
michael@0 27 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
michael@0 28 {
michael@0 29 if (PL_OPT_BAD == os) continue;
michael@0 30 switch (opt->option)
michael@0 31 {
michael@0 32 case 'd': /* debug mode */
michael@0 33 _debug_on = 1;
michael@0 34 break;
michael@0 35 default:
michael@0 36 break;
michael@0 37 }
michael@0 38 }
michael@0 39 PL_DestroyOptState(opt);
michael@0 40
michael@0 41 if (( housekeeping_tid =
michael@0 42 PR_CreateThread (PR_USER_THREAD, housecleaning, (void*)&thread_start_time,
michael@0 43 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0))
michael@0 44 == NULL ) {
michael@0 45 fprintf(stderr,
michael@0 46 "simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
michael@0 47 PR_GetError(), PR_GetOSError());
michael@0 48 exit( 1 );
michael@0 49 }
michael@0 50 PR_Cleanup();
michael@0 51 return(0);
michael@0 52 }
michael@0 53
michael@0 54 static void
michael@0 55 housecleaning (void *cur_time)
michael@0 56 {
michael@0 57 DPRINTF(("Child Thread exiting\n"));
michael@0 58 }

mercurial