- added a special thread to calculate interpolation to try to improve performance

This commit is contained in:
Mark Vejvoda
2010-05-08 09:06:30 +00:00
parent 54bcbf4303
commit 3547276699
10 changed files with 670 additions and 85 deletions

View File

@@ -67,7 +67,7 @@ void FileCRCPreCacheThread::execute() {
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
unsigned int executionCount,
unsigned int millisecsBetweenExecutions,
bool needTaskSignal) {
bool needTaskSignal) : BaseThread() {
this->simpleTaskInterface = simpleTaskInterface;
this->executionCount = executionCount;
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
@@ -79,7 +79,7 @@ void SimpleTaskThread::execute() {
try {
setRunningStatus(true);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
unsigned int idx = 0;
for(;this->simpleTaskInterface != NULL;) {
@@ -93,7 +93,7 @@ void SimpleTaskThread::execute() {
}
if(getQuitStatus() == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
@@ -108,19 +108,19 @@ void SimpleTaskThread::execute() {
}
}
if(getQuitStatus() == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
sleep(this->millisecsBetweenExecutions);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
catch(const exception &ex) {
setRunningStatus(false);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw runtime_error(ex.what());
}
@@ -128,24 +128,24 @@ void SimpleTaskThread::execute() {
}
void SimpleTaskThread::setTaskSignalled(bool value) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
mutexTaskSignaller.p();
taskSignalled = value;
mutexTaskSignaller.v();
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
bool SimpleTaskThread::getTaskSignalled() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool retval = false;
mutexTaskSignaller.p();
retval = taskSignalled;
mutexTaskSignaller.v();
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return retval;
}

View File

@@ -0,0 +1,89 @@
//This file is part of Glest Shared Library (www.glest.org)
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//You can redistribute this code and/or modify it under
//the terms of the GNU General Public License as published by the Free Software
//Foundation; either version 2 of the License, or (at your option) any later
//version.
#include "thread.h"
#include <iostream>
#include <sstream>
#include <stdexcept>
#include "noimpl.h"
namespace Shared{ namespace Platform{
// =====================================
// Threads
// =====================================
void Thread::start() {
thread = SDL_CreateThread(beginExecution, this);
}
void Thread::setPriority(Thread::Priority threadPriority) {
NOIMPL;
}
int Thread::beginExecution(void* data) {
Thread* thread = static_cast<Thread*> (data);
thread->execute();
return 0;
}
void Thread::suspend() {
NOIMPL;
}
void Thread::resume() {
NOIMPL;
}
// =====================================
// Mutex
// =====================================
Mutex::Mutex() {
mutex = SDL_CreateMutex();
if(mutex == 0)
throw std::runtime_error("Couldn't initialize mutex");
}
Mutex::~Mutex() {
SDL_DestroyMutex(mutex);
}
void Mutex::p() {
SDL_mutexP(mutex);
}
void Mutex::v() {
SDL_mutexV(mutex);
}
// =====================================================
// class Semaphore
// =====================================================
Semaphore::Semaphore(Uint32 initialValue) {
semaphore = SDL_CreateSemaphore(initialValue);
}
Semaphore::~Semaphore() {
SDL_DestroySemaphore(semaphore);
semaphore = NULL;
}
void Semaphore::signal() {
SDL_SemPost(semaphore);
}
int Semaphore::waitTillSignalled() {
int semValue = SDL_SemWait(semaphore);
return semValue;
}
}}//end namespace

View File

@@ -0,0 +1,88 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "thread.h"
#include "leak_dumper.h"
namespace Shared{ namespace Platform{
// =====================================================
// class Threads
// =====================================================
ThreadId Thread::nextThreadId= threadIdBase;
void Thread::start(){
threadHandle= CreateThread(NULL, 0, beginExecution, this, 0, &nextThreadId);
nextThreadId++;
}
void Thread::setPriority(Thread::Priority threadPriority){
SetThreadPriority(threadHandle, threadPriority);
}
DWORD WINAPI Thread::beginExecution(void *param){
static_cast<Thread*>(param)->execute();
return 0;
}
void Thread::suspend(){
SuspendThread(threadHandle);
}
void Thread::resume(){
ResumeThread(threadHandle);
}
// =====================================================
// class Mutex
// =====================================================
Mutex::Mutex(){
InitializeCriticalSection(&mutex);
}
Mutex::~Mutex(){
DeleteCriticalSection(&mutex);
}
void Mutex::p(){
EnterCriticalSection(&mutex);
}
void Mutex::v(){
LeaveCriticalSection(&mutex);
}
// =====================================================
// class Semaphore
// =====================================================
Semaphore::Semaphore(Uint32 initialValue) {
semaphore = SDL_CreateSemaphore(initialValue);
}
Semaphore::~Semaphore() {
SDL_DestroySemaphore(semaphore);
semaphore = NULL;
}
void Semaphore::signal() {
SDL_SemPost(semaphore);
}
int Semaphore::waitTillSignalled() {
int semValue = SDL_SemWait(semaphore);
return semValue;
}
}}//end namespace