mirror of
https://github.com/glest/glest-source.git
synced 2025-08-14 12:23:59 +02:00
moved threads into base common hiearchy and started an a new cache manager.
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
#include "sound_renderer.h"
|
#include "sound_renderer.h"
|
||||||
#include "ImageReaders.h"
|
#include "ImageReaders.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "thread.h"
|
#include "simple_threads.h"
|
||||||
|
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
@@ -101,157 +101,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileCRCPreCacheThread : public Thread
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Mutex mutexRunning;
|
|
||||||
Mutex mutexQuit;
|
|
||||||
|
|
||||||
bool quit;
|
|
||||||
bool running;
|
|
||||||
|
|
||||||
void setRunningStatus(bool value);
|
|
||||||
void setQuitStatus(bool value);
|
|
||||||
|
|
||||||
public:
|
|
||||||
FileCRCPreCacheThread();
|
|
||||||
virtual void execute();
|
|
||||||
void signalQuit();
|
|
||||||
bool getQuitStatus();
|
|
||||||
bool getRunningStatus();
|
|
||||||
static void shutdownAndWait(FileCRCPreCacheThread *pThread);
|
|
||||||
};
|
|
||||||
|
|
||||||
FileCRCPreCacheThread::FileCRCPreCacheThread() {
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
setQuitStatus(false);
|
|
||||||
setRunningStatus(false);
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileCRCPreCacheThread::signalQuit() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
setQuitStatus(true);
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileCRCPreCacheThread::setQuitStatus(bool value) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
mutexQuit.p();
|
|
||||||
quit = value;
|
|
||||||
mutexQuit.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileCRCPreCacheThread::getQuitStatus() {
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
bool retval = false;
|
|
||||||
mutexQuit.p();
|
|
||||||
retval = quit;
|
|
||||||
mutexQuit.v();
|
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileCRCPreCacheThread::getRunningStatus() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
bool retval = false;
|
|
||||||
mutexRunning.p();
|
|
||||||
retval = running;
|
|
||||||
mutexRunning.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileCRCPreCacheThread::setRunningStatus(bool value) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
|
||||||
|
|
||||||
mutexRunning.p();
|
|
||||||
running = value;
|
|
||||||
mutexRunning.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileCRCPreCacheThread::execute() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
setRunningStatus(true);
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Config &config = Config::getInstance();
|
|
||||||
vector<string> techDataPaths = config.getPathListForType(ptTechs);
|
|
||||||
//tech Tree listBox
|
|
||||||
vector<string> techPaths;
|
|
||||||
findDirs(techDataPaths, techPaths);
|
|
||||||
if(techPaths.empty() == false) {
|
|
||||||
for(int idx = 0; idx < techPaths.size(); idx++) {
|
|
||||||
string &techPath = techPaths[idx];
|
|
||||||
for(int idx2 = 0; idx2 < techPaths.size(); idx2++) {
|
|
||||||
string techName = techPaths[idx2];
|
|
||||||
|
|
||||||
printf("In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str());
|
|
||||||
int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL);
|
|
||||||
printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC);
|
|
||||||
|
|
||||||
if(getQuitStatus() == true) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sleep( 100 );
|
|
||||||
}
|
|
||||||
if(getQuitStatus() == true) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(const exception &ex) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
|
||||||
setRunningStatus(false);
|
|
||||||
}
|
|
||||||
catch(...) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
setRunningStatus(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
setRunningStatus(false);
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is exiting\n");
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileCRCPreCacheThread::shutdownAndWait(FileCRCPreCacheThread *pThread) {
|
|
||||||
if(pThread != NULL) {
|
|
||||||
pThread->signalQuit();
|
|
||||||
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 10; ) {
|
|
||||||
if(pThread->getRunningStatus() == false) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sleep(50);
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class MainWindow
|
// class MainWindow
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -494,6 +343,8 @@ int glestMain(int argc, char** argv){
|
|||||||
gameInitialized = true;
|
gameInitialized = true;
|
||||||
|
|
||||||
if(config.getBool("AllowGameDataSynchCheck","false") == true) {
|
if(config.getBool("AllowGameDataSynchCheck","false") == true) {
|
||||||
|
vector<string> techDataPaths = config.getPathListForType(ptTechs);
|
||||||
|
preCacheThread.setTechDataPaths(techDataPaths);
|
||||||
preCacheThread.start();
|
preCacheThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,27 +359,27 @@ int glestMain(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
FileCRCPreCacheThread::shutdownAndWait(&preCacheThread);
|
preCacheThread.shutdownAndWait();
|
||||||
//exceptionMessage(e);
|
//exceptionMessage(e);
|
||||||
ExceptionHandler::handleRuntimeError(e.what());
|
ExceptionHandler::handleRuntimeError(e.what());
|
||||||
}
|
}
|
||||||
catch(const char *e){
|
catch(const char *e){
|
||||||
//exceptionMessage(e);
|
//exceptionMessage(e);
|
||||||
FileCRCPreCacheThread::shutdownAndWait(&preCacheThread);
|
preCacheThread.shutdownAndWait();
|
||||||
ExceptionHandler::handleRuntimeError(e);
|
ExceptionHandler::handleRuntimeError(e);
|
||||||
}
|
}
|
||||||
catch(const string &ex){
|
catch(const string &ex){
|
||||||
//exceptionMessage(e);
|
//exceptionMessage(e);
|
||||||
FileCRCPreCacheThread::shutdownAndWait(&preCacheThread);
|
preCacheThread.shutdownAndWait();
|
||||||
ExceptionHandler::handleRuntimeError(ex.c_str());
|
ExceptionHandler::handleRuntimeError(ex.c_str());
|
||||||
}
|
}
|
||||||
catch(...){
|
catch(...){
|
||||||
//exceptionMessage(e);
|
//exceptionMessage(e);
|
||||||
FileCRCPreCacheThread::shutdownAndWait(&preCacheThread);
|
preCacheThread.shutdownAndWait();
|
||||||
ExceptionHandler::handleRuntimeError("Unknown error!");
|
ExceptionHandler::handleRuntimeError("Unknown error!");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileCRCPreCacheThread::shutdownAndWait(&preCacheThread);
|
preCacheThread.shutdownAndWait();
|
||||||
|
|
||||||
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
//soundRenderer.stopAllSounds();
|
//soundRenderer.stopAllSounds();
|
||||||
|
51
source/shared_lib/include/platform/common/base_thread.h
Normal file
51
source/shared_lib/include/platform/common/base_thread.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
// ==============================================================
|
||||||
|
#ifndef _SHARED_PLATFORMCOMMON_BASETHREAD_H_
|
||||||
|
#define _SHARED_PLATFORMCOMMON_BASETHREAD_H_
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
using namespace Shared::Platform;
|
||||||
|
|
||||||
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class BaseThread
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class BaseThread : public Thread
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Mutex mutexRunning;
|
||||||
|
Mutex mutexQuit;
|
||||||
|
|
||||||
|
bool quit;
|
||||||
|
bool running;
|
||||||
|
|
||||||
|
void setRunningStatus(bool value);
|
||||||
|
void setQuitStatus(bool value);
|
||||||
|
|
||||||
|
public:
|
||||||
|
BaseThread();
|
||||||
|
~BaseThread();
|
||||||
|
virtual void execute()=0;
|
||||||
|
|
||||||
|
void signalQuit();
|
||||||
|
bool getQuitStatus();
|
||||||
|
bool getRunningStatus();
|
||||||
|
static void shutdownAndWait(BaseThread *pThread);
|
||||||
|
void shutdownAndWait();
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
71
source/shared_lib/include/platform/common/cache_manager.h
Normal file
71
source/shared_lib/include/platform/common/cache_manager.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _SHARED_PLATFORMCOMMON_CACHEMANAGER_H_
|
||||||
|
#define _SHARED_PLATFORMCOMMON_CACHEMANAGER_H_
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
using namespace Shared::Platform;
|
||||||
|
|
||||||
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class BaseThread
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class CacheManager
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Mutex mutexCache;
|
||||||
|
|
||||||
|
static std::map<string, bool> masterCacheList;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
cacheItemGet,
|
||||||
|
cacheItemSet
|
||||||
|
} CacheAccessorType;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T manageCachedItem(string cacheKey, T *value,CacheAccessorType accessor) {
|
||||||
|
static std::map<string, T> itemCache;
|
||||||
|
|
||||||
|
if(accessor == cacheItemSet) {
|
||||||
|
masterCacheList[cacheKey] = true;
|
||||||
|
itemCache[cacheKey] = *value;
|
||||||
|
}
|
||||||
|
return itemCache[cacheKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CacheManager() {
|
||||||
|
|
||||||
|
}
|
||||||
|
~CacheManager() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T setCachedItem(string cacheKey, T value) {
|
||||||
|
manageCachedItem<T>(cacheKey,value,cacheItemSet);
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
static T getCachedItem(string cacheKey) {
|
||||||
|
return manageCachedItem<T>(cacheKey,NULL,cacheItemGet);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
41
source/shared_lib/include/platform/common/simple_threads.h
Normal file
41
source/shared_lib/include/platform/common/simple_threads.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// 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
|
||||||
|
// ==============================================================
|
||||||
|
#ifndef _SHARED_PLATFORMCOMMON_SIMPLETHREAD_H_
|
||||||
|
#define _SHARED_PLATFORMCOMMON_SIMPLETHREAD_H_
|
||||||
|
|
||||||
|
#include "base_thread.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class FileCRCPreCacheThread
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class FileCRCPreCacheThread : public BaseThread
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
vector<string> techDataPaths;
|
||||||
|
|
||||||
|
public:
|
||||||
|
FileCRCPreCacheThread();
|
||||||
|
FileCRCPreCacheThread(vector<string> techDataPaths);
|
||||||
|
virtual void execute();
|
||||||
|
void setTechDataPaths(vector<string> techDataPaths) { this->techDataPaths = techDataPaths; }
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
@@ -19,7 +19,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "thread.h"
|
#include "base_thread.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ using std::string;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
namespace Shared{ namespace Platform{
|
namespace Shared{ namespace Platform{
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -127,26 +129,14 @@ protected:
|
|||||||
static void throwException(string str);
|
static void throwException(string str);
|
||||||
};
|
};
|
||||||
|
|
||||||
class BroadCastClientSocketThread : public Thread
|
class BroadCastClientSocketThread : public BaseThread
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Mutex mutexRunning;
|
|
||||||
Mutex mutexQuit;
|
|
||||||
|
|
||||||
bool quit;
|
|
||||||
bool running;
|
|
||||||
|
|
||||||
DiscoveredServersInterface *discoveredServersCB;
|
DiscoveredServersInterface *discoveredServersCB;
|
||||||
|
|
||||||
void setRunningStatus(bool value);
|
|
||||||
void setQuitStatus(bool value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BroadCastClientSocketThread(DiscoveredServersInterface *cb);
|
BroadCastClientSocketThread(DiscoveredServersInterface *cb);
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
void signalQuit();
|
|
||||||
bool getQuitStatus();
|
|
||||||
bool getRunningStatus();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -168,24 +158,13 @@ protected:
|
|||||||
static void startBroadCastClientThread(DiscoveredServersInterface *cb);
|
static void startBroadCastClientThread(DiscoveredServersInterface *cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
class BroadCastSocketThread : public Thread
|
class BroadCastSocketThread : public BaseThread
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Mutex mutexRunning;
|
|
||||||
Mutex mutexQuit;
|
|
||||||
|
|
||||||
bool quit;
|
|
||||||
bool running;
|
|
||||||
|
|
||||||
void setRunningStatus(bool value);
|
|
||||||
void setQuitStatus(bool value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BroadCastSocketThread();
|
BroadCastSocketThread();
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
void signalQuit();
|
|
||||||
bool getQuitStatus();
|
|
||||||
bool getRunningStatus();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
106
source/shared_lib/sources/platform/common/base_thread.cpp
Normal file
106
source/shared_lib/sources/platform/common/base_thread.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
|
//
|
||||||
|
// 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 "base_thread.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
using namespace Shared::Util;
|
||||||
|
|
||||||
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
BaseThread::BaseThread() {
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
setQuitStatus(false);
|
||||||
|
setRunningStatus(false);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseThread::~BaseThread() {
|
||||||
|
shutdownAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseThread::signalQuit() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
setQuitStatus(true);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseThread::setQuitStatus(bool value) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
mutexQuit.p();
|
||||||
|
quit = value;
|
||||||
|
mutexQuit.v();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseThread::getQuitStatus() {
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
bool retval = false;
|
||||||
|
mutexQuit.p();
|
||||||
|
retval = quit;
|
||||||
|
mutexQuit.v();
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseThread::getRunningStatus() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
bool retval = false;
|
||||||
|
mutexRunning.p();
|
||||||
|
retval = running;
|
||||||
|
mutexRunning.v();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseThread::setRunningStatus(bool value) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
||||||
|
|
||||||
|
mutexRunning.p();
|
||||||
|
running = value;
|
||||||
|
mutexRunning.v();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseThread::shutdownAndWait(BaseThread *pThread) {
|
||||||
|
if(pThread != NULL) {
|
||||||
|
pThread->signalQuit();
|
||||||
|
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 10; ) {
|
||||||
|
if(pThread->getRunningStatus() == false) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep(50);
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseThread::shutdownAndWait() {
|
||||||
|
BaseThread::shutdownAndWait(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
11
source/shared_lib/sources/platform/common/cache_manager.cpp
Normal file
11
source/shared_lib/sources/platform/common/cache_manager.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
// ==============================================================
|
@@ -7,6 +7,7 @@
|
|||||||
//Foundation; either version 2 of the License, or (at your option) any later
|
//Foundation; either version 2 of the License, or (at your option) any later
|
||||||
//version.
|
//version.
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
|
#include "cache_manager.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
@@ -290,6 +291,8 @@ int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string path
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
static std::map<string,int32> crcTreeCache;
|
static std::map<string,int32> crcTreeCache;
|
||||||
|
//string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
|
||||||
|
//std::map<string,int32> &crcTreeCache = CacheManager::getCachedItem(cacheLookupId);
|
||||||
|
|
||||||
string cacheKey = "";
|
string cacheKey = "";
|
||||||
size_t count = paths.size();
|
size_t count = paths.size();
|
||||||
|
73
source/shared_lib/sources/platform/common/simple_threads.cpp
Normal file
73
source/shared_lib/sources/platform/common/simple_threads.cpp
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
|
//
|
||||||
|
// 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 "simple_threads.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "platform_common.h"
|
||||||
|
|
||||||
|
using namespace Shared::Util;
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileCRCPreCacheThread::execute() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
setRunningStatus(true);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n");
|
||||||
|
|
||||||
|
try {
|
||||||
|
//tech Tree listBox
|
||||||
|
vector<string> techPaths;
|
||||||
|
findDirs(techDataPaths, techPaths);
|
||||||
|
if(techPaths.empty() == false) {
|
||||||
|
for(int idx = 0; idx < techPaths.size(); idx++) {
|
||||||
|
string &techPath = techPaths[idx];
|
||||||
|
for(int idx2 = 0; idx2 < techPaths.size(); idx2++) {
|
||||||
|
string techName = techPaths[idx2];
|
||||||
|
|
||||||
|
printf("In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str());
|
||||||
|
int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL);
|
||||||
|
printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC);
|
||||||
|
|
||||||
|
if(getQuitStatus() == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep( 100 );
|
||||||
|
}
|
||||||
|
if(getQuitStatus() == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const exception &ex) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||||
|
setRunningStatus(false);
|
||||||
|
}
|
||||||
|
catch(...) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
setRunningStatus(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
setRunningStatus(false);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is exiting\n");
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
@@ -12,7 +12,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
//#include <sstream>
|
|
||||||
|
|
||||||
#if defined(HAVE_SYS_IOCTL_H)
|
#if defined(HAVE_SYS_IOCTL_H)
|
||||||
#define BSD_COMP /* needed for FIONREAD on Solaris2 */
|
#define BSD_COMP /* needed for FIONREAD on Solaris2 */
|
||||||
@@ -1153,7 +1152,6 @@ void Socket::throwException(string str){
|
|||||||
ClientSocket::ClientSocket() : Socket() {
|
ClientSocket::ClientSocket() : Socket() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//broadCastClientThread = NULL;
|
|
||||||
stopBroadCastClientThread();
|
stopBroadCastClientThread();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -1310,71 +1308,15 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
// Description: Runs in its own thread to listen for broadcasts from
|
// Description: Runs in its own thread to listen for broadcasts from
|
||||||
// other servers
|
// other servers
|
||||||
//
|
//
|
||||||
BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterface *cb) {
|
BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterface *cb) : BaseThread() {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
setQuitStatus(false);
|
|
||||||
setRunningStatus(false);
|
|
||||||
discoveredServersCB = cb;
|
discoveredServersCB = cb;
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadCastClientSocketThread::signalQuit() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
setQuitStatus(true);
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCastClientSocketThread::setQuitStatus(bool value) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
mutexQuit.p();
|
|
||||||
quit = value;
|
|
||||||
mutexQuit.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BroadCastClientSocketThread::getQuitStatus() {
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
bool retval = false;
|
|
||||||
mutexQuit.p();
|
|
||||||
retval = quit;
|
|
||||||
mutexQuit.v();
|
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BroadCastClientSocketThread::getRunningStatus() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
bool retval = false;
|
|
||||||
mutexRunning.p();
|
|
||||||
retval = running;
|
|
||||||
mutexRunning.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCastClientSocketThread::setRunningStatus(bool value) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
|
||||||
|
|
||||||
mutexRunning.p();
|
|
||||||
running = value;
|
|
||||||
mutexRunning.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
// Function : broadcast thread
|
// Function : broadcast thread
|
||||||
// Description: Runs in its own thread to send out a broadcast to the local network
|
// Description: Runs in its own thread to send out a broadcast to the local network
|
||||||
@@ -1624,68 +1566,8 @@ Socket *ServerSocket::accept()
|
|||||||
return new Socket(newSock);
|
return new Socket(newSock);
|
||||||
}
|
}
|
||||||
|
|
||||||
BroadCastSocketThread::BroadCastSocketThread() {
|
BroadCastSocketThread::BroadCastSocketThread() : BaseThread() {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
setQuitStatus(false);
|
|
||||||
setRunningStatus(false);
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCastSocketThread::signalQuit() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
setQuitStatus(true);
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCastSocketThread::setQuitStatus(bool value) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
mutexQuit.p();
|
|
||||||
quit = value;
|
|
||||||
mutexQuit.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BroadCastSocketThread::getQuitStatus() {
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
bool retval = false;
|
|
||||||
mutexQuit.p();
|
|
||||||
retval = quit;
|
|
||||||
mutexQuit.v();
|
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BroadCastSocketThread::getRunningStatus() {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
bool retval = false;
|
|
||||||
mutexRunning.p();
|
|
||||||
retval = running;
|
|
||||||
mutexRunning.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCastSocketThread::setRunningStatus(bool value) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
|
||||||
|
|
||||||
mutexRunning.p();
|
|
||||||
running = value;
|
|
||||||
mutexRunning.v();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
@@ -1829,4 +1711,3 @@ void BroadCastSocketThread::execute() {
|
|||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user