Debian Codegraph @

nsprpub/pr/tests/short_thread.c

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include <stdio.h>
7 #include "nspr.h"
8 #include "plgetopt.h"
9
10 /*
11 * Create a thread that exits right away; useful for testing race conditions in
12 * thread creation
13 */
14
15 int _debug_on = 0;
16 #define DPRINTF(arg) \
17 if (_debug_on) printf arg
18
19 static void housecleaning(void* cur_time);
20
21 int main(int argc, char** argv) {
22 static PRIntervalTime thread_start_time;
23 static PRThread* housekeeping_tid = NULL;
24 PLOptStatus os;
25 PLOptState* opt = PL_CreateOptState(argc, argv, "d");
26
27 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) {
28 if (PL_OPT_BAD == os) {
29 continue;
30 }
31 switch (opt->option) {
32 case 'd': /* debug mode */
33 _debug_on = 1;
34 break;
35 default:
36 break;
37 }
38 }
39 PL_DestroyOptState(opt);
40
41 if ((housekeeping_tid = PR_CreateThread(
42 PR_USER_THREAD, housecleaning, (void*)&thread_start_time,
43 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0)) ==
44 NULL) {
45 fprintf(stderr, "simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
46 PR_GetError(), PR_GetOSError());
47 exit(1);
48 }
49 PR_Cleanup();
50 return (0);
51 }
52
53 static void housecleaning(void* cur_time) {
54 DPRINTF(("Child Thread exiting\n"));
55 }