home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / many_cv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.2 KB  |  112 lines

  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 Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "prinit.h"
  20. #include "prprf.h"
  21. #include "prthread.h"
  22. #include "prcvar.h"
  23. #include "prlock.h"
  24. #include "prlog.h"
  25. #include "prmem.h"
  26.  
  27. #include "plgetopt.h"
  28.  
  29. #include <stdlib.h>
  30.  
  31. static void Help(void)
  32. {
  33.     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
  34.     PR_fprintf(err, "many_cv usage: [-c n] [-l n] [-h]\n");
  35.     PR_fprintf(err, "\t-c n Number of conditions per lock       (default: 10)\n");
  36.     PR_fprintf(err, "\t-l n Number of times to loop the test    (default:  1)\n");
  37.     PR_fprintf(err, "\t-h   This message and nothing else\n");
  38. }  /* Help */
  39.  
  40. static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
  41. {
  42.     PLOptStatus os;
  43.     PRIntn index, nl;
  44.     PRLock *ml = NULL;
  45.     PRCondVar **cv = NULL;
  46.     PRIntn loops = 1, cvs = 10;
  47.     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
  48.     PLOptState *opt = PL_CreateOptState(argc, argv, "hc:l:");
  49.  
  50.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  51.     {
  52.         if (PL_OPT_BAD == os) continue;
  53.         switch (opt->option)
  54.         {
  55.         case 'c':  /* number of CVs to association with lock */
  56.             cvs = atoi(opt->value);
  57.             break;
  58.         case 'l':  /* number of times to run the tests */
  59.             loops = atoi(opt->value);
  60.             break;
  61.         case 'h':  /* user wants some guidance */
  62.          default:
  63.             Help();  /* so give him an earful */
  64.             return 2;  /* but not a lot else */
  65.         }
  66.     }
  67.     PL_DestroyOptState(opt);
  68.  
  69.     PR_fprintf(err, "Settings\n");
  70.     PR_fprintf(err, "\tConditions / lock: %d\n", cvs);
  71.     PR_fprintf(err, "\tLoops to run test: %d\n", loops);
  72.  
  73.     ml = PR_NewLock();
  74.     PR_ASSERT(NULL != ml);
  75.  
  76.     cv = (PRCondVar**)PR_CALLOC(sizeof(PRCondVar*) * cvs);
  77.     PR_ASSERT(NULL != cv);
  78.  
  79.     for (index = 0; index < cvs; ++index)
  80.     {
  81.         cv[index] = PR_NewCondVar(ml);
  82.         PR_ASSERT(NULL != cv[index]);
  83.     }
  84.  
  85.     for (index = 0; index < loops; ++index)
  86.     {
  87.         PR_Lock(ml);
  88.         for (nl = 0; nl < cvs; ++nl)
  89.             PR_NotifyCondVar(cv[nl]);
  90.         PR_Unlock(ml);
  91.     }
  92.  
  93.     for (index = 0; index < cvs; ++index)
  94.         PR_DestroyCondVar(cv[index]);
  95.  
  96.     PR_DestroyLock(ml);
  97.     
  98.     printf("PASS\n");
  99.  
  100.     return 0;
  101. }
  102.  
  103.  
  104. PRIntn main(PRIntn argc, char **argv)
  105. {
  106.     PRIntn rv;
  107.     
  108.     PR_STDIO_INIT();
  109.     rv = PR_Initialize(RealMain, argc, argv, 0);
  110.     return rv;
  111. }  /* main */
  112.