Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* thread.cpp - a test program */ |
michael@0 | 7 | |
michael@0 | 8 | #include "rcthread.h" |
michael@0 | 9 | |
michael@0 | 10 | #include <prlog.h> |
michael@0 | 11 | |
michael@0 | 12 | #include <stdio.h> |
michael@0 | 13 | |
michael@0 | 14 | class TestThread: public RCThread |
michael@0 | 15 | { |
michael@0 | 16 | public: |
michael@0 | 17 | TestThread(RCThread::State state, PRIntn count); |
michael@0 | 18 | |
michael@0 | 19 | virtual void RootFunction(); |
michael@0 | 20 | |
michael@0 | 21 | protected: |
michael@0 | 22 | virtual ~TestThread(); |
michael@0 | 23 | |
michael@0 | 24 | private: |
michael@0 | 25 | PRUint32 mydata; |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | TestThread::~TestThread() { } |
michael@0 | 29 | |
michael@0 | 30 | TestThread::TestThread(RCThread::State state, PRIntn count): |
michael@0 | 31 | RCThread(RCThread::global, state, 0) { mydata = count; } |
michael@0 | 32 | |
michael@0 | 33 | void TestThread::RootFunction() |
michael@0 | 34 | { |
michael@0 | 35 | SetPriority(RCThread::high); |
michael@0 | 36 | printf("TestThread::RootFunction %d did it\n", mydata); |
michael@0 | 37 | } /* TestThread::RootFunction */ |
michael@0 | 38 | |
michael@0 | 39 | class Foo1 |
michael@0 | 40 | { |
michael@0 | 41 | public: |
michael@0 | 42 | Foo1(); |
michael@0 | 43 | virtual ~Foo1(); |
michael@0 | 44 | |
michael@0 | 45 | TestThread *thread; |
michael@0 | 46 | PRIntn data; |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | Foo1::Foo1() |
michael@0 | 50 | { |
michael@0 | 51 | data = 0xafaf; |
michael@0 | 52 | thread = new TestThread(RCThread::joinable, 0xafaf); |
michael@0 | 53 | thread->Start(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | Foo1::~Foo1() |
michael@0 | 57 | { |
michael@0 | 58 | PRStatus rv = thread->Join(); |
michael@0 | 59 | PR_ASSERT(PR_SUCCESS == rv); |
michael@0 | 60 | } /* Foo1::~Foo1 */ |
michael@0 | 61 | |
michael@0 | 62 | PRIntn main(PRIntn argc, char **agrv) |
michael@0 | 63 | { |
michael@0 | 64 | PRStatus status; |
michael@0 | 65 | PRIntn count = 100; |
michael@0 | 66 | RCThread *thread[10]; |
michael@0 | 67 | while (--count > 0) |
michael@0 | 68 | { |
michael@0 | 69 | TestThread *thread = new TestThread(RCThread::joinable, count); |
michael@0 | 70 | status = thread->Start(); /* have to remember to start it */ |
michael@0 | 71 | PR_ASSERT(PR_SUCCESS == status); |
michael@0 | 72 | status = thread->Join(); /* this should work */ |
michael@0 | 73 | PR_ASSERT(PR_SUCCESS == status); |
michael@0 | 74 | } |
michael@0 | 75 | while (++count < 100) |
michael@0 | 76 | { |
michael@0 | 77 | TestThread *thread = new TestThread(RCThread::unjoinable, count); |
michael@0 | 78 | status = thread->Start(); /* have to remember to start it */ |
michael@0 | 79 | PR_ASSERT(PR_SUCCESS == status); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | { |
michael@0 | 83 | Foo1 *foo1 = new Foo1(); |
michael@0 | 84 | PR_ASSERT(NULL != foo1); |
michael@0 | 85 | delete foo1; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | { |
michael@0 | 89 | for (count = 0; count < 10; ++count) |
michael@0 | 90 | { |
michael@0 | 91 | thread[count] = new TestThread( RCThread::joinable, count); |
michael@0 | 92 | status = thread[count]->Start(); /* have to remember to start it */ |
michael@0 | 93 | PR_ASSERT(PR_SUCCESS == status); |
michael@0 | 94 | } |
michael@0 | 95 | for (count = 0; count < 10; ++count) |
michael@0 | 96 | { |
michael@0 | 97 | PRStatus rv = thread[count]->Join(); |
michael@0 | 98 | PR_ASSERT(PR_SUCCESS == rv); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | (void)RCPrimordialThread::Cleanup(); |
michael@0 | 103 | |
michael@0 | 104 | return 0; |
michael@0 | 105 | } /* main */ |
michael@0 | 106 | |
michael@0 | 107 | /* thread.cpp */ |
michael@0 | 108 |