~ubuntu-branches/ubuntu/intrepid/xulrunner-1.9/intrepid

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Fabien Tassin
  • Date: 2008-02-13 11:47:21 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080213114721-7om0mgzngvuk9czv
Tags: 1.9~b3+nobinonly-0ubuntu1
* release FIREFOX_3_0b3_RELEASE

[ Alexander Sack ]
* submit patch that ships xpcshell to bugzilla
  - rename debian/patches/ship_xpcshell.patch =>
           debian/patches/bz410617_att295212_ship_xpcshell.patch
  - update debian/patches/series
* fix tooltip in epiphany: previously displayed out of screen bounds
  (LP: #37507)
  - add debian/patches/bz233371_att297343_fix_outofscreen_embed_tooltip.patch
  - update debian/patches/series
* use default upstream gcc tweaks for improved performance - especially of the
  javascript engine
  - update debian/rules
* update global extension/plugin patch to apply cleanly against latest code
  - update debian/patches/bzXXX_gre_extension_plugin_support.patch
* fix pyxpcom build failure introduced by recent commit
  - add debian/patches/bzXXX_fix_pyxpcom_build_failure.patch
  - update debian/patches/series
* add distro independent global install locations for extensions,
  /usr/lib/mozilla/extensions and /usr/share/mozilla/extensions
  - update debian/xulrunner-1.9.dirs
* support embedded tarball layout when either there is a *.tar.bz2 in orig tarball
  or if DEBIAN_MOZCLIENT_EMBEDDED is not unset (you will need this to produce embedded
  tarballs during |get-orig-source|
  - update debian/rules
* bump minimum libnss3-dev build requirements to >= 3.12.0~1.9b3
  - update debian/control
* bump minimum libnspr4-dev build requirements to >= 4.7.0~1.9b3
  - update debian/control

[ Fabien Tassin ]
* Drop patches applied upstream
  - drop debian/patches/bz410617_att295212_ship_xpcshell.patch
  - drop debian/patches/bz404634_att294921.patch
  - drop debian/patches/bz386610_python2.5_ftbfs_amd64.patch
  - drop debian/patches/bz373918_att295042.patch
  - drop debian/patches/bz408062_unstable_pc.patch
  - drop debian/patches/bz384304_fix_recursive_symlinks.patch
  - update debian/patches/series
* Refresh diverged patches:
  - update debian/patches/bzXXX_pc_honour_system_nspr_nss.patch
  - update debian/patches/rename_venkman_addon.patch
  - update debian/patches/bz344818_cairo_xrender.patch
* Install links for all .so libs in the -dev package
  - update debian/patches/dont_install_so_in_dev.patch
* Bump gtk requirement to 2.12 as per Mozilla bug 412432
  - update debian/control
* Add #DEBHELPER# token to postinst/prerm scripts
  - update debian/xulrunner-1.9.{postinst,prerm}
* Install previously missed libdbusservice.so
  - update debian/xulrunner-1.9.install
* Update venkman patch to also rename locales
  - update debian/patches/rename_venkman_addon.patch
* Bump requirement for system cairo to >= 1.5.8 as we now need
  the newly added cairo_path_extents()
  - update debian/rules
* Include mozilla-devscripts file using -include so ifneq could be omitted
  - update debian/rules
* Fix missing .so symlinks regression
  - update debian/patches/dont_install_so_in_dev.patch

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
 
/* ***** BEGIN LICENSE BLOCK *****
3
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 
 *
5
 
 * The contents of this file are subject to the Mozilla Public License Version
6
 
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 
 * the License. You may obtain a copy of the License at
8
 
 * http://www.mozilla.org/MPL/
9
 
 *
10
 
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 
 * for the specific language governing rights and limitations under the
13
 
 * License.
14
 
 *
15
 
 * The Original Code is the Netscape Portable Runtime (NSPR).
16
 
 *
17
 
 * The Initial Developer of the Original Code is
18
 
 * Netscape Communications Corporation.
19
 
 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20
 
 * the Initial Developer. All Rights Reserved.
21
 
 *
22
 
 * Contributor(s):
23
 
 *
24
 
 * Alternatively, the contents of this file may be used under the terms of
25
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 
 * of those above. If you wish to allow use of your version of this file only
29
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 
 * use your version of this file under the terms of the MPL, indicate your
31
 
 * decision by deleting the provisions above and replace them with the notice
32
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 
 * the provisions above, a recipient may use your version of this file under
34
 
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 
 *
36
 
 * ***** END LICENSE BLOCK ***** */
37
 
 
38
 
/*
39
 
Attached is a test program that uses the nspr1 to demonstrate a bug
40
 
under NT4.0. The fix has already been mentioned (add a ResetEvent just
41
 
before leaving the critical section in _PR_CondWait in hwmon.c).
42
 
*/
43
 
 
44
 
#include "prthread.h"
45
 
#include "prtypes.h"
46
 
#include "prinit.h"
47
 
#include "prmon.h"
48
 
#include "prlog.h"
49
 
 
50
 
typedef struct Arg_s
51
 
{
52
 
        PRInt32 a, b;
53
 
} Arg_t;
54
 
 
55
 
PRMonitor*  gMonitor;       // the monitor
56
 
PRInt32     gReading;       // number of read locks
57
 
PRInt32     gWriteWaiting;  // number of threads waiting for write lock
58
 
PRInt32     gReadWaiting;   // number of threads waiting for read lock
59
 
 
60
 
PRInt32     gCounter;       // a counter
61
 
 
62
 
                            // stats
63
 
PRInt32     gReads;         // number of successful reads
64
 
PRInt32     gMaxReads;      // max number of simultaneous reads
65
 
PRInt32     gMaxWriteWaits; // max number of writes that waited for read
66
 
PRInt32     gMaxReadWaits;  // max number of reads that waited for write wait
67
 
 
68
 
 
69
 
void spin (PRInt32 aDelay)
70
 
{
71
 
  PRInt32 index;
72
 
  PRInt32 delay = aDelay * 1000;
73
 
 
74
 
  PR_Sleep(0);
75
 
 
76
 
  // randomize delay a bit
77
 
  delay = (delay / 2) + (PRInt32)((float)delay *
78
 
          ((float)rand () / (float)RAND_MAX));
79
 
 
80
 
  for (index = 0; index < delay * 10; index++)
81
 
          // consume a bunch of cpu cycles
82
 
    ;
83
 
  PR_Sleep(0); 
84
 
}
85
 
 
86
 
void  doWriteThread (void* arg)
87
 
{
88
 
  PRInt32 last;
89
 
  Arg_t *args = (Arg_t*)arg;
90
 
  PRInt32 aWorkDelay = args->a, aWaitDelay = args->b;
91
 
  PR_Sleep(0);
92
 
 
93
 
  while (1)
94
 
  {
95
 
    // -- enter write lock
96
 
    PR_EnterMonitor (gMonitor);
97
 
 
98
 
    if (0 < gReading)     // wait for read locks to go away
99
 
    {
100
 
      PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
101
 
 
102
 
      gWriteWaiting++;
103
 
      if (gWriteWaiting > gMaxWriteWaits) // stats
104
 
        gMaxWriteWaits = gWriteWaiting;
105
 
      while (0 < gReading)
106
 
        PR_Wait (gMonitor, fiveSecs);
107
 
      gWriteWaiting--;
108
 
    }
109
 
    // -- write lock entered
110
 
 
111
 
    last = gCounter;
112
 
    gCounter++;
113
 
 
114
 
    spin (aWorkDelay);
115
 
 
116
 
    PR_ASSERT (gCounter == (last + 1)); // test invariance
117
 
 
118
 
    // -- exit write lock        
119
 
//    if (0 < gReadWaiting)   // notify waiting reads (do it anyway to show off the CondWait bug)
120
 
      PR_NotifyAll (gMonitor);
121
 
 
122
 
    PR_ExitMonitor (gMonitor);
123
 
    // -- write lock exited
124
 
 
125
 
    spin (aWaitDelay);
126
 
  }
127
 
}
128
 
 
129
 
void  doReadThread (void* arg)
130
 
{
131
 
  PRInt32 last;
132
 
  Arg_t *args = (Arg_t*)arg;
133
 
  PRInt32 aWorkDelay = args->a, aWaitDelay = args->b;
134
 
  PR_Sleep(0);
135
 
 
136
 
  while (1)
137
 
  {
138
 
    // -- enter read lock
139
 
    PR_EnterMonitor (gMonitor); 
140
 
 
141
 
    if (0 < gWriteWaiting)  // give up the monitor to waiting writes
142
 
    {
143
 
      PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
144
 
 
145
 
      gReadWaiting++;
146
 
      if (gReadWaiting > gMaxReadWaits) // stats
147
 
        gMaxReadWaits = gReadWaiting;
148
 
      while (0 < gWriteWaiting)
149
 
        PR_Wait (gMonitor, fiveSecs);
150
 
      gReadWaiting--;
151
 
    }
152
 
 
153
 
    gReading++;
154
 
 
155
 
    gReads++;   // stats
156
 
    if (gReading > gMaxReads) // stats
157
 
      gMaxReads = gReading;
158
 
 
159
 
    PR_ExitMonitor (gMonitor);
160
 
    // -- read lock entered
161
 
 
162
 
    last = gCounter;
163
 
 
164
 
    spin (aWorkDelay);
165
 
 
166
 
    PR_ASSERT (gCounter == last); // test invariance
167
 
 
168
 
    // -- exit read lock
169
 
    PR_EnterMonitor (gMonitor);  // read unlock
170
 
    gReading--;
171
 
 
172
 
//    if ((0 == gReading) && (0 < gWriteWaiting))  // notify waiting writes  (do it anyway to show off the CondWait bug)
173
 
      PR_NotifyAll (gMonitor);
174
 
    PR_ExitMonitor (gMonitor);
175
 
    // -- read lock exited
176
 
 
177
 
    spin (aWaitDelay);
178
 
  }
179
 
}
180
 
 
181
 
 
182
 
void fireThread (
183
 
    char* aName, void (*aProc)(void *arg), Arg_t *aArg)
184
 
{
185
 
  PRThread *thread = PR_CreateThread(
186
 
          PR_USER_THREAD, aProc, aArg, PR_PRIORITY_NORMAL,
187
 
          PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
188
 
}
189
 
 
190
 
int pseudoMain (int argc, char** argv, char *pad)
191
 
{
192
 
  PRInt32 lastWriteCount  = gCounter;
193
 
  PRInt32 lastReadCount   = gReads;
194
 
  Arg_t a1 = {500, 250};
195
 
  Arg_t a2 = {500, 500};
196
 
  Arg_t a3 = {250, 500};
197
 
  Arg_t a4 = {750, 250};
198
 
  Arg_t a5 = {100, 750};
199
 
  Arg_t a6 = {100, 500};
200
 
  Arg_t a7 = {100, 750};
201
 
 
202
 
  gMonitor = PR_NewMonitor ();
203
 
 
204
 
  fireThread ("R1", doReadThread,   &a1);
205
 
  fireThread ("R2", doReadThread,   &a2);
206
 
  fireThread ("R3", doReadThread,   &a3);
207
 
  fireThread ("R4", doReadThread,   &a4);
208
 
 
209
 
  fireThread ("W1", doWriteThread,  &a5);
210
 
  fireThread ("W2", doWriteThread,  &a6);
211
 
  fireThread ("W3", doWriteThread,  &a7);
212
 
 
213
 
  fireThread ("R5", doReadThread,   &a1);
214
 
  fireThread ("R6", doReadThread,   &a2);
215
 
  fireThread ("R7", doReadThread,   &a3);
216
 
  fireThread ("R8", doReadThread,   &a4);
217
 
 
218
 
  fireThread ("W4", doWriteThread,  &a5);
219
 
  fireThread ("W5", doWriteThread,  &a6);
220
 
  fireThread ("W6", doWriteThread,  &a7);
221
 
  
222
 
  while (1)
223
 
  {
224
 
        PRInt32 writeCount, readCount;
225
 
    PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
226
 
    PR_Sleep (fiveSecs);  // get out of the way
227
 
 
228
 
    // print some stats, not threadsafe, informative only
229
 
    writeCount = gCounter;
230
 
    readCount   = gReads;
231
 
    printf ("\ntick %d writes (+%d), %d reads (+%d) [max %d, %d, %d]", 
232
 
            writeCount, writeCount - lastWriteCount,
233
 
            readCount, readCount - lastReadCount, 
234
 
            gMaxReads, gMaxWriteWaits, gMaxReadWaits);
235
 
    lastWriteCount = writeCount;
236
 
    lastReadCount = readCount;
237
 
    gMaxReads = gMaxWriteWaits = gMaxReadWaits = 0;
238
 
  }
239
 
  return 0;
240
 
}
241
 
 
242
 
 
243
 
static void padStack (int argc, char** argv)
244
 
{
245
 
  char pad[512];      /* Work around bug in nspr on windoze */
246
 
  pseudoMain (argc, argv, pad);
247
 
}
248
 
 
249
 
void main (int argc, char **argv)
250
 
{
251
 
  PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
252
 
  PR_STDIO_INIT();
253
 
  padStack (argc, argv);
254
 
}
255
 
 
256
 
 
257
 
/* bug1test.c */