mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 13:23:59 +02:00
moved threads into base common hiearchy and started an a new cache manager.
This commit is contained in:
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
|
||||
//version.
|
||||
#include "platform_common.h"
|
||||
#include "cache_manager.h"
|
||||
|
||||
#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__);
|
||||
|
||||
static std::map<string,int32> crcTreeCache;
|
||||
//string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
|
||||
//std::map<string,int32> &crcTreeCache = CacheManager::getCachedItem(cacheLookupId);
|
||||
|
||||
string cacheKey = "";
|
||||
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 <cstdlib>
|
||||
#include <stdexcept>
|
||||
//#include <sstream>
|
||||
|
||||
#if defined(HAVE_SYS_IOCTL_H)
|
||||
#define BSD_COMP /* needed for FIONREAD on Solaris2 */
|
||||
@@ -1153,7 +1152,6 @@ void Socket::throwException(string str){
|
||||
ClientSocket::ClientSocket() : Socket() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//broadCastClientThread = NULL;
|
||||
stopBroadCastClientThread();
|
||||
|
||||
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
|
||||
// other servers
|
||||
//
|
||||
BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterface *cb) {
|
||||
BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterface *cb) : BaseThread() {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
setQuitStatus(false);
|
||||
setRunningStatus(false);
|
||||
discoveredServersCB = cb;
|
||||
|
||||
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
|
||||
// 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);
|
||||
}
|
||||
|
||||
BroadCastSocketThread::BroadCastSocketThread() {
|
||||
|
||||
BroadCastSocketThread::BroadCastSocketThread() : 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__);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user