moved threads into base common hiearchy and started an a new cache manager.

This commit is contained in:
Mark Vejvoda
2010-04-30 22:54:24 +00:00
parent b10bb3c2bc
commit fd2274775e
10 changed files with 371 additions and 304 deletions

View 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

View 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

View 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

View File

@@ -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();
};
// =====================================================