1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is the Netscape Portable Runtime (NSPR).
15
* The Initial Developer of the Original Code is Netscape
16
* Communications Corporation. Portions created by Netscape are
17
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
22
* Alternatively, the contents of this file may be used under the
23
* terms of the GNU General Public License Version 2 or later (the
24
* "GPL"), in which case the provisions of the GPL are applicable
25
* instead of those above. If you wish to allow use of your
26
* version of this file only under the terms of the GPL and not to
27
* allow others to use your version of this file under the MPL,
28
* indicate your decision by deleting the provisions above and
29
* replace them with the notice and other provisions required by
30
* the GPL. If you do not delete the provisions above, a recipient
31
* may use your version of this file under either the MPL or the
45
static void PR_CALLBACK Thread(void *sleep)
47
PR_Sleep(PR_SecondsToInterval((PRUint32)sleep));
48
printf("Thread exiting\n");
51
static void Help(void)
53
PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
54
PR_fprintf(err, "Cleanup usage: [-g] [-s n] [-t n] [-c n] [-h]\n");
55
PR_fprintf(err, "\t-c Call cleanup before exiting (default: false)\n");
56
PR_fprintf(err, "\t-G Use global threads only (default: local)\n");
57
PR_fprintf(err, "\t-t n Number of threads involved (default: 1)\n");
58
PR_fprintf(err, "\t-s n Seconds thread(s) should dally (defaut: 10)\n");
59
PR_fprintf(err, "\t-S n Seconds main() should dally (defaut: 5)\n");
60
PR_fprintf(err, "\t-C n Value to set concurrency (default 1)\n");
61
PR_fprintf(err, "\t-h This message and nothing else\n");
64
PRIntn main(PRIntn argc, char **argv)
67
PRBool cleanup = PR_FALSE;
68
PRThreadScope type = PR_LOCAL_THREAD;
69
PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
70
PLOptState *opt = PL_CreateOptState(argc, argv, "Ghs:S:t:cC:");
71
PRIntn concurrency = 1, child_sleep = 10, main_sleep = 5, threads = 1;
74
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
76
if (PL_OPT_BAD == os) continue;
79
case 'c': /* call PR_Cleanup() before exiting */
82
case 'G': /* local vs global threads */
83
type = PR_GLOBAL_THREAD;
85
case 's': /* time to sleep */
86
child_sleep = atoi(opt->value);
88
case 'S': /* time to sleep */
89
main_sleep = atoi(opt->value);
91
case 'C': /* number of cpus to create */
92
concurrency = atoi(opt->value);
94
case 't': /* number of threads to create */
95
threads = atoi(opt->value);
97
case 'h': /* user wants some guidance */
98
Help(); /* so give him an earful */
99
return 2; /* but not a lot else */
105
PL_DestroyOptState(opt);
107
PR_fprintf(err, "Cleanup settings\n");
108
PR_fprintf(err, "\tThread type: %s\n",
109
(PR_LOCAL_THREAD == type) ? "LOCAL" : "GLOBAL");
110
PR_fprintf(err, "\tConcurrency: %d\n", concurrency);
111
PR_fprintf(err, "\tNumber of threads: %d\n", threads);
112
PR_fprintf(err, "\tThread sleep: %d\n", child_sleep);
113
PR_fprintf(err, "\tMain sleep: %d\n", main_sleep);
114
PR_fprintf(err, "\tCleanup will %sbe called\n\n", (cleanup) ? "" : "NOT ");
116
PR_SetConcurrency(concurrency);
118
while (threads-- > 0)
119
(void)PR_CreateThread(
120
PR_USER_THREAD, Thread, (void*)child_sleep, PR_PRIORITY_NORMAL,
121
type, PR_UNJOINABLE_THREAD, 0);
122
PR_Sleep(PR_SecondsToInterval(main_sleep));
124
if (cleanup) PR_Cleanup();
126
PR_fprintf(err, "main() exiting\n");