michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* thread.cpp - a test program */ michael@0: michael@0: #include "rcthread.h" michael@0: michael@0: #include michael@0: michael@0: #include michael@0: michael@0: class TestThread: public RCThread michael@0: { michael@0: public: michael@0: TestThread(RCThread::State state, PRIntn count); michael@0: michael@0: virtual void RootFunction(); michael@0: michael@0: protected: michael@0: virtual ~TestThread(); michael@0: michael@0: private: michael@0: PRUint32 mydata; michael@0: }; michael@0: michael@0: TestThread::~TestThread() { } michael@0: michael@0: TestThread::TestThread(RCThread::State state, PRIntn count): michael@0: RCThread(RCThread::global, state, 0) { mydata = count; } michael@0: michael@0: void TestThread::RootFunction() michael@0: { michael@0: SetPriority(RCThread::high); michael@0: printf("TestThread::RootFunction %d did it\n", mydata); michael@0: } /* TestThread::RootFunction */ michael@0: michael@0: class Foo1 michael@0: { michael@0: public: michael@0: Foo1(); michael@0: virtual ~Foo1(); michael@0: michael@0: TestThread *thread; michael@0: PRIntn data; michael@0: }; michael@0: michael@0: Foo1::Foo1() michael@0: { michael@0: data = 0xafaf; michael@0: thread = new TestThread(RCThread::joinable, 0xafaf); michael@0: thread->Start(); michael@0: } michael@0: michael@0: Foo1::~Foo1() michael@0: { michael@0: PRStatus rv = thread->Join(); michael@0: PR_ASSERT(PR_SUCCESS == rv); michael@0: } /* Foo1::~Foo1 */ michael@0: michael@0: PRIntn main(PRIntn argc, char **agrv) michael@0: { michael@0: PRStatus status; michael@0: PRIntn count = 100; michael@0: RCThread *thread[10]; michael@0: while (--count > 0) michael@0: { michael@0: TestThread *thread = new TestThread(RCThread::joinable, count); michael@0: status = thread->Start(); /* have to remember to start it */ michael@0: PR_ASSERT(PR_SUCCESS == status); michael@0: status = thread->Join(); /* this should work */ michael@0: PR_ASSERT(PR_SUCCESS == status); michael@0: } michael@0: while (++count < 100) michael@0: { michael@0: TestThread *thread = new TestThread(RCThread::unjoinable, count); michael@0: status = thread->Start(); /* have to remember to start it */ michael@0: PR_ASSERT(PR_SUCCESS == status); michael@0: } michael@0: michael@0: { michael@0: Foo1 *foo1 = new Foo1(); michael@0: PR_ASSERT(NULL != foo1); michael@0: delete foo1; michael@0: } michael@0: michael@0: { michael@0: for (count = 0; count < 10; ++count) michael@0: { michael@0: thread[count] = new TestThread( RCThread::joinable, count); michael@0: status = thread[count]->Start(); /* have to remember to start it */ michael@0: PR_ASSERT(PR_SUCCESS == status); michael@0: } michael@0: for (count = 0; count < 10; ++count) michael@0: { michael@0: PRStatus rv = thread[count]->Join(); michael@0: PR_ASSERT(PR_SUCCESS == rv); michael@0: } michael@0: } michael@0: michael@0: (void)RCPrimordialThread::Cleanup(); michael@0: michael@0: return 0; michael@0: } /* main */ michael@0: michael@0: /* thread.cpp */ michael@0: