mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 03:44:00 +02:00
moved threads into base common hiearchy and started an a new cache manager.
This commit is contained in:
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 <map>
|
||||
#include <vector>
|
||||
#include "thread.h"
|
||||
#include "base_thread.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -37,6 +37,8 @@ using std::string;
|
||||
|
||||
#endif
|
||||
|
||||
using namespace Shared::PlatformCommon;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
//
|
||||
@@ -127,26 +129,14 @@ protected:
|
||||
static void throwException(string str);
|
||||
};
|
||||
|
||||
class BroadCastClientSocketThread : public Thread
|
||||
class BroadCastClientSocketThread : public BaseThread
|
||||
{
|
||||
private:
|
||||
Mutex mutexRunning;
|
||||
Mutex mutexQuit;
|
||||
|
||||
bool quit;
|
||||
bool running;
|
||||
|
||||
DiscoveredServersInterface *discoveredServersCB;
|
||||
|
||||
void setRunningStatus(bool value);
|
||||
void setQuitStatus(bool value);
|
||||
|
||||
public:
|
||||
BroadCastClientSocketThread(DiscoveredServersInterface *cb);
|
||||
virtual void execute();
|
||||
void signalQuit();
|
||||
bool getQuitStatus();
|
||||
bool getRunningStatus();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -168,24 +158,13 @@ protected:
|
||||
static void startBroadCastClientThread(DiscoveredServersInterface *cb);
|
||||
};
|
||||
|
||||
class BroadCastSocketThread : public Thread
|
||||
class BroadCastSocketThread : public BaseThread
|
||||
{
|
||||
private:
|
||||
Mutex mutexRunning;
|
||||
Mutex mutexQuit;
|
||||
|
||||
bool quit;
|
||||
bool running;
|
||||
|
||||
void setRunningStatus(bool value);
|
||||
void setQuitStatus(bool value);
|
||||
|
||||
public:
|
||||
BroadCastSocketThread();
|
||||
virtual void execute();
|
||||
void signalQuit();
|
||||
bool getQuitStatus();
|
||||
bool getRunningStatus();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
Reference in New Issue
Block a user