Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
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/. */
6 /* thread.cpp - a test program */
8 #include "rcthread.h"
10 #include <prlog.h>
12 #include <stdio.h>
14 class TestThread: public RCThread
15 {
16 public:
17 TestThread(RCThread::State state, PRIntn count);
19 virtual void RootFunction();
21 protected:
22 virtual ~TestThread();
24 private:
25 PRUint32 mydata;
26 };
28 TestThread::~TestThread() { }
30 TestThread::TestThread(RCThread::State state, PRIntn count):
31 RCThread(RCThread::global, state, 0) { mydata = count; }
33 void TestThread::RootFunction()
34 {
35 SetPriority(RCThread::high);
36 printf("TestThread::RootFunction %d did it\n", mydata);
37 } /* TestThread::RootFunction */
39 class Foo1
40 {
41 public:
42 Foo1();
43 virtual ~Foo1();
45 TestThread *thread;
46 PRIntn data;
47 };
49 Foo1::Foo1()
50 {
51 data = 0xafaf;
52 thread = new TestThread(RCThread::joinable, 0xafaf);
53 thread->Start();
54 }
56 Foo1::~Foo1()
57 {
58 PRStatus rv = thread->Join();
59 PR_ASSERT(PR_SUCCESS == rv);
60 } /* Foo1::~Foo1 */
62 PRIntn main(PRIntn argc, char **agrv)
63 {
64 PRStatus status;
65 PRIntn count = 100;
66 RCThread *thread[10];
67 while (--count > 0)
68 {
69 TestThread *thread = new TestThread(RCThread::joinable, count);
70 status = thread->Start(); /* have to remember to start it */
71 PR_ASSERT(PR_SUCCESS == status);
72 status = thread->Join(); /* this should work */
73 PR_ASSERT(PR_SUCCESS == status);
74 }
75 while (++count < 100)
76 {
77 TestThread *thread = new TestThread(RCThread::unjoinable, count);
78 status = thread->Start(); /* have to remember to start it */
79 PR_ASSERT(PR_SUCCESS == status);
80 }
82 {
83 Foo1 *foo1 = new Foo1();
84 PR_ASSERT(NULL != foo1);
85 delete foo1;
86 }
88 {
89 for (count = 0; count < 10; ++count)
90 {
91 thread[count] = new TestThread( RCThread::joinable, count);
92 status = thread[count]->Start(); /* have to remember to start it */
93 PR_ASSERT(PR_SUCCESS == status);
94 }
95 for (count = 0; count < 10; ++count)
96 {
97 PRStatus rv = thread[count]->Join();
98 PR_ASSERT(PR_SUCCESS == rv);
99 }
100 }
102 (void)RCPrimordialThread::Cleanup();
104 return 0;
105 } /* main */
107 /* thread.cpp */