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 "prio.h" michael@0: #include "prprf.h" michael@0: #include "prinit.h" michael@0: #include "prthread.h" michael@0: #include "prproces.h" michael@0: #include "prinrval.h" michael@0: michael@0: #include "plgetopt.h" michael@0: michael@0: #include michael@0: michael@0: static PRInt32 dally = 0; michael@0: static PRFileDesc *err = NULL; michael@0: static PRBool verbose = PR_FALSE, force = PR_FALSE; michael@0: michael@0: static void Help(void) michael@0: { michael@0: PR_fprintf(err, "Usage: [-t s] [-h]\n"); michael@0: PR_fprintf(err, "\t-d Verbose output (default: FALSE)\n"); michael@0: PR_fprintf(err, "\t-x Forced termination (default: FALSE)\n"); michael@0: PR_fprintf(err, "\t-t Time for thread to block (default: 10 seconds)\n"); michael@0: PR_fprintf(err, "\t-h This message and nothing else\n"); michael@0: } /* Help */ michael@0: michael@0: static void Dull(void *arg) michael@0: { michael@0: PR_Sleep(PR_SecondsToInterval(dally)); michael@0: if (verbose && force) michael@0: PR_fprintf(err, "If you see this, the test failed\n"); michael@0: } /* Dull */ michael@0: michael@0: static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv) michael@0: { michael@0: PLOptStatus os; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "ht:dx"); michael@0: michael@0: err = PR_GetSpecialFD(PR_StandardError); michael@0: michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 'd': /* verbosity */ michael@0: verbose = PR_TRUE; michael@0: break; michael@0: case 'x': /* force exit */ michael@0: force = PR_TRUE; michael@0: break; michael@0: case 't': /* seconds to dally in child */ michael@0: dally = atoi(opt->value); michael@0: break; michael@0: case 'h': /* user wants some guidance */ michael@0: default: michael@0: Help(); /* so give him an earful */ michael@0: return 2; /* but not a lot else */ michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: michael@0: if (0 == dally) dally = 10; michael@0: michael@0: /* michael@0: * Create LOCAL and GLOBAL threads michael@0: */ michael@0: (void)PR_CreateThread( michael@0: PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL, michael@0: PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0); michael@0: michael@0: (void)PR_CreateThread( michael@0: PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL, michael@0: PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); michael@0: michael@0: if (verbose) michael@0: PR_fprintf( michael@0: err, "Main is exiting now. Program should exit %s.\n", michael@0: (force) ? "immediately" : "after child dally time"); michael@0: michael@0: if (force) michael@0: { michael@0: PR_ProcessExit(0); michael@0: if (verbose) michael@0: { michael@0: PR_fprintf(err, "You should not have gotten here.\n"); michael@0: return 1; michael@0: } michael@0: } michael@0: return 0; michael@0: michael@0: } michael@0: michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRIntn rv; michael@0: michael@0: PR_STDIO_INIT(); michael@0: rv = PR_Initialize(RealMain, argc, argv, 0); michael@0: return rv; michael@0: } /* main */