Wed, 31 Dec 2014 06:09:35 +0100
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 "prprf.h" |
michael@0 | 7 | #include "prio.h" |
michael@0 | 8 | #include "prinit.h" |
michael@0 | 9 | #include "prthread.h" |
michael@0 | 10 | #include "prinrval.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "plgetopt.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <stdlib.h> |
michael@0 | 15 | |
michael@0 | 16 | static void PR_CALLBACK Thread(void *sleep) |
michael@0 | 17 | { |
michael@0 | 18 | PR_Sleep(PR_SecondsToInterval((PRUint32)sleep)); |
michael@0 | 19 | printf("Thread exiting\n"); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | static void Help(void) |
michael@0 | 23 | { |
michael@0 | 24 | PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); |
michael@0 | 25 | PR_fprintf(err, "Cleanup usage: [-g] [-s n] [-t n] [-c n] [-h]\n"); |
michael@0 | 26 | PR_fprintf(err, "\t-c Call cleanup before exiting (default: false)\n"); |
michael@0 | 27 | PR_fprintf(err, "\t-G Use global threads only (default: local)\n"); |
michael@0 | 28 | PR_fprintf(err, "\t-t n Number of threads involved (default: 1)\n"); |
michael@0 | 29 | PR_fprintf(err, "\t-s n Seconds thread(s) should dally (defaut: 10)\n"); |
michael@0 | 30 | PR_fprintf(err, "\t-S n Seconds main() should dally (defaut: 5)\n"); |
michael@0 | 31 | PR_fprintf(err, "\t-C n Value to set concurrency (default 1)\n"); |
michael@0 | 32 | PR_fprintf(err, "\t-h This message and nothing else\n"); |
michael@0 | 33 | } /* Help */ |
michael@0 | 34 | |
michael@0 | 35 | int main(int argc, char **argv) |
michael@0 | 36 | { |
michael@0 | 37 | PLOptStatus os; |
michael@0 | 38 | PRBool cleanup = PR_FALSE; |
michael@0 | 39 | PRThreadScope type = PR_LOCAL_THREAD; |
michael@0 | 40 | PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); |
michael@0 | 41 | PLOptState *opt = PL_CreateOptState(argc, argv, "Ghs:S:t:cC:"); |
michael@0 | 42 | PRIntn concurrency = 1, child_sleep = 10, main_sleep = 5, threads = 1; |
michael@0 | 43 | |
michael@0 | 44 | PR_STDIO_INIT(); |
michael@0 | 45 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
michael@0 | 46 | { |
michael@0 | 47 | if (PL_OPT_BAD == os) continue; |
michael@0 | 48 | switch (opt->option) |
michael@0 | 49 | { |
michael@0 | 50 | case 'c': /* call PR_Cleanup() before exiting */ |
michael@0 | 51 | cleanup = PR_TRUE; |
michael@0 | 52 | break; |
michael@0 | 53 | case 'G': /* local vs global threads */ |
michael@0 | 54 | type = PR_GLOBAL_THREAD; |
michael@0 | 55 | break; |
michael@0 | 56 | case 's': /* time to sleep */ |
michael@0 | 57 | child_sleep = atoi(opt->value); |
michael@0 | 58 | break; |
michael@0 | 59 | case 'S': /* time to sleep */ |
michael@0 | 60 | main_sleep = atoi(opt->value); |
michael@0 | 61 | break; |
michael@0 | 62 | case 'C': /* number of cpus to create */ |
michael@0 | 63 | concurrency = atoi(opt->value); |
michael@0 | 64 | break; |
michael@0 | 65 | case 't': /* number of threads to create */ |
michael@0 | 66 | threads = atoi(opt->value); |
michael@0 | 67 | break; |
michael@0 | 68 | case 'h': /* user wants some guidance */ |
michael@0 | 69 | Help(); /* so give him an earful */ |
michael@0 | 70 | return 2; /* but not a lot else */ |
michael@0 | 71 | break; |
michael@0 | 72 | default: |
michael@0 | 73 | break; |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | PL_DestroyOptState(opt); |
michael@0 | 77 | |
michael@0 | 78 | PR_fprintf(err, "Cleanup settings\n"); |
michael@0 | 79 | PR_fprintf(err, "\tThread type: %s\n", |
michael@0 | 80 | (PR_LOCAL_THREAD == type) ? "LOCAL" : "GLOBAL"); |
michael@0 | 81 | PR_fprintf(err, "\tConcurrency: %d\n", concurrency); |
michael@0 | 82 | PR_fprintf(err, "\tNumber of threads: %d\n", threads); |
michael@0 | 83 | PR_fprintf(err, "\tThread sleep: %d\n", child_sleep); |
michael@0 | 84 | PR_fprintf(err, "\tMain sleep: %d\n", main_sleep); |
michael@0 | 85 | PR_fprintf(err, "\tCleanup will %sbe called\n\n", (cleanup) ? "" : "NOT "); |
michael@0 | 86 | |
michael@0 | 87 | PR_SetConcurrency(concurrency); |
michael@0 | 88 | |
michael@0 | 89 | while (threads-- > 0) |
michael@0 | 90 | (void)PR_CreateThread( |
michael@0 | 91 | PR_USER_THREAD, Thread, (void*)child_sleep, PR_PRIORITY_NORMAL, |
michael@0 | 92 | type, PR_UNJOINABLE_THREAD, 0); |
michael@0 | 93 | PR_Sleep(PR_SecondsToInterval(main_sleep)); |
michael@0 | 94 | |
michael@0 | 95 | if (cleanup) PR_Cleanup(); |
michael@0 | 96 | |
michael@0 | 97 | PR_fprintf(err, "main() exiting\n"); |
michael@0 | 98 | return 0; |
michael@0 | 99 | } /* main */ |