~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/tests/cleanup.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
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/
 
7
 * 
 
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.
 
12
 * 
 
13
 * The Original Code is the Netscape Portable Runtime (NSPR).
 
14
 * 
 
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
 
18
 * Rights Reserved.
 
19
 * 
 
20
 * Contributor(s):
 
21
 * 
 
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
 
32
 * GPL.
 
33
 */
 
34
 
 
35
#include "prprf.h"
 
36
#include "prio.h"
 
37
#include "prinit.h"
 
38
#include "prthread.h"
 
39
#include "prinrval.h"
 
40
 
 
41
#include "plgetopt.h"
 
42
 
 
43
#include <stdlib.h>
 
44
 
 
45
static void PR_CALLBACK Thread(void *sleep)
 
46
{
 
47
    PR_Sleep(PR_SecondsToInterval((PRUint32)sleep));
 
48
    printf("Thread exiting\n");
 
49
}
 
50
 
 
51
static void Help(void)
 
52
{
 
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");
 
62
}  /* Help */
 
63
 
 
64
PRIntn main(PRIntn argc, char **argv)
 
65
{
 
66
    PLOptStatus os;
 
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;
 
72
 
 
73
    PR_STDIO_INIT();
 
74
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
 
75
    {
 
76
        if (PL_OPT_BAD == os) continue;
 
77
        switch (opt->option)
 
78
        {
 
79
        case 'c':  /* call PR_Cleanup() before exiting */
 
80
            cleanup = PR_TRUE;
 
81
            break;
 
82
        case 'G':  /* local vs global threads */
 
83
            type = PR_GLOBAL_THREAD;
 
84
            break;
 
85
        case 's':  /* time to sleep */
 
86
            child_sleep = atoi(opt->value);
 
87
            break;
 
88
        case 'S':  /* time to sleep */
 
89
            main_sleep = atoi(opt->value);
 
90
            break;
 
91
        case 'C':  /* number of cpus to create */
 
92
            concurrency = atoi(opt->value);
 
93
            break;
 
94
        case 't':  /* number of threads to create */
 
95
            threads = atoi(opt->value);
 
96
            break;
 
97
        case 'h':  /* user wants some guidance */
 
98
            Help();  /* so give him an earful */
 
99
            return 2;  /* but not a lot else */
 
100
            break;
 
101
         default:
 
102
            break;
 
103
        }
 
104
    }
 
105
    PL_DestroyOptState(opt);
 
106
 
 
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 "); 
 
115
 
 
116
    PR_SetConcurrency(concurrency);
 
117
 
 
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));
 
123
 
 
124
    if (cleanup) PR_Cleanup();
 
125
 
 
126
    PR_fprintf(err, "main() exiting\n");
 
127
    return 0;
 
128
}  /* main */