Fixed multithreaded NextSubTest() output problems

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@157 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-07-12 20:30:45 +00:00
parent 40ea65d602
commit 0a99bdf489
6 changed files with 131 additions and 20 deletions
+36 -7
View File
@@ -1,16 +1,17 @@
#include <ThreadedTestCase.h>
#include <SafetyLock.h>
#include <Autolock.h>
#include <stdio.h>
BThreadedTestCase::BThreadedTestCase(std::string name, std::string progressSeparator)
: BTestCase(name)
, fProgressSeparator(progressSeparator)
, fNumberMapLock(new BLocker())
, fUpdateLock(new BLocker())
{
}
BThreadedTestCase::~BThreadedTestCase() {
// Kill our locker
delete fNumberMapLock;
delete fUpdateLock;
// Clean up
for (std::map<thread_id, ThreadSubTestInfo*>::iterator i = fNumberMap.begin();
@@ -27,13 +28,16 @@ BThreadedTestCase::NextSubTest() {
thread_id id = find_thread(NULL);
{
// Lock the number map
SafetyLock lock(fNumberMapLock);
// Acquire the update lock
BAutolock lock(fUpdateLock);
std::map<thread_id, ThreadSubTestInfo*>::iterator i = fNumberMap.find(id);
if (i != fNumberMap.end() && i->second) {
// Handle multi-threaded case
ThreadSubTestInfo *info = i->second;
cout << "[" << info->subTestNum++ << fProgressSeparator << info->name << "]";
char num[32];
sprintf(num, "%ld", info->subTestNum++);
std::string str = std::string("[") + info->name + fProgressSeparator + num + "]";
fUpdateList.push_back(str);
return;
}
}
@@ -44,7 +48,7 @@ BThreadedTestCase::NextSubTest() {
void
BThreadedTestCase::InitThreadInfo(thread_id id, std::string threadName) {
SafetyLock lock(fNumberMapLock); // Lock the number map
BAutolock lock(fUpdateLock); // Lock the number map
std::map<thread_id, ThreadSubTestInfo*>::iterator i = fNumberMap.find(id);
if (i != fNumberMap.end() && i->second) {
i->second->name = threadName;
@@ -57,3 +61,28 @@ BThreadedTestCase::InitThreadInfo(thread_id id, std::string threadName) {
fNumberMap[id] = info;
}
}
bool
BThreadedTestCase::RegisterForUse() {
if (!fInUse) {
fInUse = true;
return true;
} else
return false;
}
void
BThreadedTestCase::UnregisterForUse() {
fInUse = false;
}
std::vector<std::string>&
BThreadedTestCase::AcquireUpdateList() {
fUpdateLock->Lock();
return fUpdateList;
}
void
BThreadedTestCase::ReleaseUpdateList() {
fUpdateLock->Unlock();
}