File: | pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/many_cv.c |
Warning: | line 54, column 17 Value stored to 'stats' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 "prinit.h" |
7 | #include "prprf.h" |
8 | #include "prthread.h" |
9 | #include "prcvar.h" |
10 | #include "prlock.h" |
11 | #include "prlog.h" |
12 | #include "prmem.h" |
13 | |
14 | #include "primpl.h" |
15 | |
16 | #include "plgetopt.h" |
17 | |
18 | #include <stdlib.h> |
19 | |
20 | static PRInt32 RandomNum(void) |
21 | { |
22 | PRInt32 ran = rand() >> 16; |
23 | return ran; |
24 | } /* RandomNum */ |
25 | |
26 | static void Help(void) |
27 | { |
28 | PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); |
29 | PR_fprintf(err, "many_cv usage: [-c n] [-l n] [-h]\n"); |
30 | PR_fprintf(err, "\t-c n Number of conditions per lock (default: 10)\n"); |
31 | PR_fprintf(err, "\t-l n Number of times to loop the test (default: 1)\n"); |
32 | PR_fprintf(err, "\t-h This message and nothing else\n"); |
33 | } /* Help */ |
34 | |
35 | static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv ) |
36 | { |
37 | PLOptStatus os; |
38 | PRIntn index, nl; |
39 | PRLock *ml = NULL((void*)0); |
40 | PRCondVar **cv = NULL((void*)0); |
41 | PRBool stats = PR_FALSE0; |
42 | PRIntn nc, loops = 1, cvs = 10; |
43 | PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); |
44 | PLOptState *opt = PL_CreateOptState(argc, argv, "hsc:l:"); |
45 | |
46 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
47 | { |
48 | if (PL_OPT_BAD == os) { |
49 | continue; |
50 | } |
51 | switch (opt->option) |
52 | { |
53 | case 's': /* number of CVs to association with lock */ |
54 | stats = PR_TRUE1; |
Value stored to 'stats' is never read | |
55 | break; |
56 | case 'c': /* number of CVs to association with lock */ |
57 | cvs = atoi(opt->value); |
58 | break; |
59 | case 'l': /* number of times to run the tests */ |
60 | loops = atoi(opt->value); |
61 | break; |
62 | case 'h': /* user wants some guidance */ |
63 | default: |
64 | Help(); /* so give him an earful */ |
65 | return 2; /* but not a lot else */ |
66 | } |
67 | } |
68 | PL_DestroyOptState(opt); |
69 | |
70 | PR_fprintf(err, "Settings\n"); |
71 | PR_fprintf(err, "\tConditions / lock: %d\n", cvs); |
72 | PR_fprintf(err, "\tLoops to run test: %d\n", loops); |
73 | |
74 | ml = PR_NewLock(); |
75 | PR_ASSERT(NULL != ml)((((void*)0) != ml)?((void)0):PR_Assert("NULL != ml","../../../pr/tests/many_cv.c" ,75)); |
76 | |
77 | cv = (PRCondVar**)PR_CALLOC(sizeof(PRCondVar*) * cvs)(PR_Calloc(1, (sizeof(PRCondVar*) * cvs))); |
78 | PR_ASSERT(NULL != cv)((((void*)0) != cv)?((void)0):PR_Assert("NULL != cv","../../../pr/tests/many_cv.c" ,78)); |
79 | |
80 | for (index = 0; index < cvs; ++index) |
81 | { |
82 | cv[index] = PR_NewCondVar(ml); |
83 | PR_ASSERT(NULL != cv[index])((((void*)0) != cv[index])?((void)0):PR_Assert("NULL != cv[index]" ,"../../../pr/tests/many_cv.c",83)); |
84 | } |
85 | |
86 | for (index = 0; index < loops; ++index) |
87 | { |
88 | PR_Lock(ml); |
89 | for (nl = 0; nl < cvs; ++nl) |
90 | { |
91 | PRInt32 ran = RandomNum() % 8; |
92 | if (0 == ran) { |
93 | PR_NotifyAllCondVar(cv[nl]); |
94 | } |
95 | else for (nc = 0; nc < ran; ++nc) { |
96 | PR_NotifyCondVar(cv[nl]); |
97 | } |
98 | } |
99 | PR_Unlock(ml); |
100 | } |
101 | |
102 | for (index = 0; index < cvs; ++index) { |
103 | PR_DestroyCondVar(cv[index]); |
104 | } |
105 | |
106 | PR_DELETE(cv){ PR_Free(cv); (cv) = ((void*)0); }; |
107 | |
108 | PR_DestroyLock(ml); |
109 | |
110 | printf("PASS\n"); |
111 | |
112 | PT_FPrintStats(err, "\nPThread Statistics\n"); |
113 | return 0; |
114 | } |
115 | |
116 | |
117 | int main(int argc, char **argv) |
118 | { |
119 | PRIntn rv; |
120 | |
121 | PR_STDIO_INIT(); |
122 | rv = PR_Initialize(RealMain, argc, argv, 0); |
123 | return rv; |
124 | } /* main */ |