-made most thread stacks static, that should increase speed and stability

-moved some memory positions so we have 45mb mem2 compared to 44mb mem2 previously
-slighly increased some timeouts and memory sizes for security
This commit is contained in:
fix94.1 2014-03-17 17:38:32 +00:00
parent 3bc03871fe
commit 18bab7faf5
18 changed files with 90 additions and 71 deletions

View File

@ -202,6 +202,7 @@ void Config::save(bool unload)
{ {
if (m_changed) if (m_changed)
{ {
//gprintf("changed:%d\n",m_changed);
ofstream file(m_filename.c_str(), ios::out | ios::binary); ofstream file(m_filename.c_str(), ios::out | ios::binary);
for (Config::DomainMap::iterator k = m_domains.begin(); k != m_domains.end(); ++k) for (Config::DomainMap::iterator k = m_domains.begin(); k != m_domains.end(); ++k)
{ {
@ -227,6 +228,7 @@ bool Config::has(const std::string &domain, const std::string &key) const
void Config::setWString(const string &domain, const string &key, const wstringEx &val) void Config::setWString(const string &domain, const string &key, const wstringEx &val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setWString %s\n", val.toUTF8().c_str());
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = val.toUTF8(); m_domains[upperCase(domain)][lowerCase(key)] = val.toUTF8();
} }
@ -234,6 +236,7 @@ void Config::setWString(const string &domain, const string &key, const wstringEx
void Config::setString(const string &domain, const string &key, const string &val) void Config::setString(const string &domain, const string &key, const string &val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setString %s\n", val.c_str());
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = val; m_domains[upperCase(domain)][lowerCase(key)] = val;
} }
@ -241,6 +244,7 @@ void Config::setString(const string &domain, const string &key, const string &va
void Config::setBool(const string &domain, const string &key, bool val) void Config::setBool(const string &domain, const string &key, bool val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setBool %d\n", val);
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = val ? "yes" : "no"; m_domains[upperCase(domain)][lowerCase(key)] = val ? "yes" : "no";
} }
@ -248,6 +252,7 @@ void Config::setBool(const string &domain, const string &key, bool val)
void Config::remove(const string &domain, const string &key) void Config::remove(const string &domain, const string &key)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("remove %s\n", key.c_str());
m_changed = true; m_changed = true;
m_domains[upperCase(domain)].erase(lowerCase(key)); m_domains[upperCase(domain)].erase(lowerCase(key));
} }
@ -255,6 +260,7 @@ void Config::remove(const string &domain, const string &key)
void Config::setOptBool(const string &domain, const string &key, int val) void Config::setOptBool(const string &domain, const string &key, int val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setOptBool %d\n", val);
m_changed = true; m_changed = true;
switch (val) switch (val)
{ {
@ -272,6 +278,7 @@ void Config::setOptBool(const string &domain, const string &key, int val)
void Config::setInt(const string &domain, const string &key, int val) void Config::setInt(const string &domain, const string &key, int val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setInt %i\n", val);
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%i", val); m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%i", val);
} }
@ -279,6 +286,7 @@ void Config::setInt(const string &domain, const string &key, int val)
void Config::setUInt(const std::string &domain, const std::string &key, unsigned int val) void Config::setUInt(const std::string &domain, const std::string &key, unsigned int val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setUInt %u\n", val);
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%u", val); m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%u", val);
} }
@ -286,6 +294,7 @@ void Config::setUInt(const std::string &domain, const std::string &key, unsigned
void Config::setFloat(const string &domain, const string &key, float val) void Config::setFloat(const string &domain, const string &key, float val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setFloat %f\n", val);
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%.*g", g_floatPrecision, val); m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%.*g", g_floatPrecision, val);
} }
@ -293,6 +302,7 @@ void Config::setFloat(const string &domain, const string &key, float val)
void Config::setVector3D(const std::string &domain, const std::string &key, const Vector3D &val) void Config::setVector3D(const std::string &domain, const std::string &key, const Vector3D &val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setVector3D\n");
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%.*g, %.*g, %.*g", g_floatPrecision, val.x, g_floatPrecision, val.y, g_floatPrecision, val.z); m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%.*g, %.*g, %.*g", g_floatPrecision, val.x, g_floatPrecision, val.y, g_floatPrecision, val.z);
} }
@ -300,6 +310,7 @@ void Config::setVector3D(const std::string &domain, const std::string &key, cons
void Config::setColor(const std::string &domain, const std::string &key, const CColor &val) void Config::setColor(const std::string &domain, const std::string &key, const CColor &val)
{ {
if (domain.empty() || key.empty()) return; if (domain.empty() || key.empty()) return;
//gprintf("setColor\n");
m_changed = true; m_changed = true;
m_domains[upperCase(domain)][lowerCase(key)] = sfmt("#%.2X%.2X%.2X%.2X", val.r, val.g, val.b, val.a); m_domains[upperCase(domain)][lowerCase(key)] = sfmt("#%.2X%.2X%.2X%.2X", val.r, val.g, val.b, val.a);
} }
@ -311,6 +322,7 @@ wstringEx Config::getWString(const string &domain, const string &key, const wstr
if (data.empty()) if (data.empty())
{ {
data = defVal.toUTF8(); data = defVal.toUTF8();
//gprintf("getWString %s\n", defVal.toUTF8().c_str());
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -327,6 +339,7 @@ string Config::getString(const string &domain, const string &key, const string &
if(data.empty()) if(data.empty())
{ {
data = defVal; data = defVal;
//gprintf("setString %s\n", defVal.c_str());
m_changed = true; m_changed = true;
} }
return data; return data;
@ -387,6 +400,7 @@ bool Config::getBool(const string &domain, const string &key, bool defVal)
if (data.empty()) if (data.empty())
{ {
data = defVal ? "yes" : "no"; data = defVal ? "yes" : "no";
//gprintf("getBool %d\n", defVal);
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -427,6 +441,7 @@ int Config::getOptBool(const string &domain, const string &key, int defVal)
default: default:
data = "default"; data = "default";
} }
//gprintf("getOptBool %s\n", data.c_str());
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -445,6 +460,7 @@ int Config::getInt(const string &domain, const string &key, int defVal)
if (data.empty()) if (data.empty())
{ {
data = sfmt("%i", defVal); data = sfmt("%i", defVal);
//gprintf("getInt %i\n", defVal);
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -467,6 +483,7 @@ unsigned int Config::getUInt(const string &domain, const string &key, unsigned i
if (data.empty()) if (data.empty())
{ {
data = sfmt("%u", defVal); data = sfmt("%u", defVal);
//gprintf("getUInt %u\n", defVal);
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -480,6 +497,7 @@ float Config::getFloat(const string &domain, const string &key, float defVal)
if (data.empty()) if (data.empty())
{ {
data = sfmt("%.*g", g_floatPrecision, defVal); data = sfmt("%.*g", g_floatPrecision, defVal);
//gprintf("getFloat %s\n", data.c_str());
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -497,6 +515,7 @@ Vector3D Config::getVector3D(const std::string &domain, const std::string &key,
if (j == string::npos) if (j == string::npos)
{ {
data = sfmt("%.*g, %.*g, %.*g", g_floatPrecision, defVal.x, g_floatPrecision, defVal.y, g_floatPrecision, defVal.z); data = sfmt("%.*g, %.*g, %.*g", g_floatPrecision, defVal.x, g_floatPrecision, defVal.y, g_floatPrecision, defVal.z);
//gprintf("getVector3D\n");
m_changed = true; m_changed = true;
return defVal; return defVal;
} }
@ -528,6 +547,7 @@ CColor Config::getColor(const std::string &domain, const std::string &key, const
} }
} }
data = sfmt("#%.2X%.2X%.2X%.2X", defVal.r, defVal.g, defVal.b, defVal.a); data = sfmt("#%.2X%.2X%.2X%.2X", defVal.r, defVal.g, defVal.b, defVal.a);
//gprintf("getColor\n");
m_changed = true; m_changed = true;
return defVal; return defVal;
} }

View File

@ -26,7 +26,7 @@
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <malloc.h> #include "memory/mem2.hpp"
#include "WiiMovie.hpp" #include "WiiMovie.hpp"
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
@ -73,7 +73,7 @@ void WiiMovie::DeInit()
} }
if(ThreadStack != NULL) if(ThreadStack != NULL)
{ {
free(ThreadStack); MEM2_lo_free(ThreadStack);
ThreadStack = NULL; ThreadStack = NULL;
} }
@ -88,7 +88,7 @@ bool WiiMovie::Play(TexData *Background, bool loop)
if(!vFile) if(!vFile)
return false; return false;
ThreadStack = (u8 *)malloc(32768); ThreadStack = (u8*)MEM2_lo_alloc(32768);
if(!ThreadStack) if(!ThreadStack)
return false; return false;
@ -99,7 +99,7 @@ bool WiiMovie::Play(TexData *Background, bool loop)
PlayTime.reset(); PlayTime.reset();
Playing = true; Playing = true;
LWP_CreateThread (&ReadThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST); LWP_CreateThread(&ReadThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST);
gprintf("Reading frames thread started\n"); gprintf("Reading frames thread started\n");
return true; return true;
} }

View File

@ -46,6 +46,9 @@ static inline int loopNum(int i, int s)
CCoverFlow CoverFlow; CCoverFlow CoverFlow;
u8 CCoverFlow::coverThreadStack[32768] ATTRIBUTE_ALIGN(32);
const u32 CCoverFlow::coverThreadStackSize = 32768;
CCoverFlow::CCover::CCover(void) CCoverFlow::CCover::CCover(void)
{ {
index = 0; index = 0;
@ -651,7 +654,8 @@ void CCoverFlow::startCoverLoader(void)
m_loadingCovers = true; m_loadingCovers = true;
m_moved = true; m_moved = true;
LWP_CreateThread(&coverLoaderThread, (void*(*)(void*))CCoverFlow::_coverLoader, (void*)this, NULL, 0, 30); LWP_CreateThread(&coverLoaderThread, (void*(*)(void*))CCoverFlow::_coverLoader,
(void*)this, coverThreadStack, coverThreadStackSize, 30);
//gprintf("Coverflow started!\n"); //gprintf("Coverflow started!\n");
} }

View File

@ -310,6 +310,9 @@ private:
u8 m_aniso; u8 m_aniso;
bool m_edgeLOD; bool m_edgeLOD;
Sorting m_sorting; Sorting m_sorting;
//thread stack
static u8 coverThreadStack[32768];
static const u32 coverThreadStackSize;
private: private:
void _draw(DrawMode dm = CFDR_NORMAL, bool mirror = false, bool blend = true); void _draw(DrawMode dm = CFDR_NORMAL, bool mirror = false, bool blend = true);
u32 _currentPos(void) const; u32 _currentPos(void) const;

View File

@ -84,6 +84,10 @@ const int CVideo::_stencilHeight = 128;
static lwp_t waitThread = LWP_THREAD_NULL; static lwp_t waitThread = LWP_THREAD_NULL;
CVideo m_vid; CVideo m_vid;
u8 CVideo::waitMessageStack[2048] ATTRIBUTE_ALIGN(32);
const u32 CVideo::waitMessageStackSize = 2048;
CVideo::CVideo(void) : CVideo::CVideo(void) :
m_rmode(NULL), m_frameBuf(), m_curFB(0), m_fifo(NULL), m_rmode(NULL), m_frameBuf(), m_curFB(0), m_fifo(NULL),
m_yScale(0.0f), m_xfbHeight(0), m_wide(false), m_yScale(0.0f), m_xfbHeight(0), m_wide(false),
@ -560,9 +564,6 @@ void CVideo::_showWaitMessages(CVideo *m)
m->m_showingWaitMessages = false; m->m_showingWaitMessages = false;
} }
u32 waitMessageStackSize = 1024;
u8 *waitMessageStack = NULL;
void CVideo::hideWaitMessage() void CVideo::hideWaitMessage()
{ {
m_showWaitMessage = false; m_showWaitMessage = false;
@ -574,9 +575,6 @@ void CVideo::hideWaitMessage()
while(m_showingWaitMessages) while(m_showingWaitMessages)
usleep(50); usleep(50);
LWP_JoinThread(waitThread, NULL); LWP_JoinThread(waitThread, NULL);
if(waitMessageStack != NULL)
MEM2_free(waitMessageStack);
waitMessageStack = NULL;
/* end light thread */ /* end light thread */
wiiLightEndThread(); wiiLightEndThread();
m_WaitThreadRunning = false; m_WaitThreadRunning = false;
@ -628,8 +626,6 @@ void CVideo::waitMessage(const vector<TexData> &tex, float delay)
wiiLightStartThread(); wiiLightStartThread();
/* onscreen animation */ /* onscreen animation */
m_showWaitMessage = true; m_showWaitMessage = true;
if(waitMessageStack == NULL)
waitMessageStack = (u8*)MEM2_memalign(32, waitMessageStackSize);
LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages, LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages,
(void*)this, waitMessageStack, waitMessageStackSize, LWP_PRIO_HIGHEST); (void*)this, waitMessageStack, waitMessageStackSize, LWP_PRIO_HIGHEST);
} }

View File

@ -113,6 +113,9 @@ private:
static const float _jitter5[5][2]; static const float _jitter5[5][2];
static const float _jitter6[6][2]; static const float _jitter6[6][2];
static const float _jitter8[8][2]; static const float _jitter8[8][2];
//thread stack
static u8 waitMessageStack[2048];
static const u32 waitMessageStackSize;
private: private:
void _drawAASceneWithAlpha(float w, float h); void _drawAASceneWithAlpha(float w, float h);
void _setViewPort(float x, float y, float w, float h); void _setViewPort(float x, float y, float w, float h);

View File

@ -21,7 +21,6 @@
#include "menu/menu.hpp" #include "menu/menu.hpp"
#include "memory/memory.h" #include "memory/memory.h"
CMenu mainMenu;
bool useMainIOS = false; bool useMainIOS = false;
volatile bool NANDemuView = false; volatile bool NANDemuView = false;
volatile bool networkInit = false; volatile bool networkInit = false;

View File

@ -16,19 +16,19 @@ u32 MALLOC_MEM2 = 0;
u8 *MEM1_lo_start = (u8*)0x80004000; u8 *MEM1_lo_start = (u8*)0x80004000;
u8 *MEM1_lo_end = (u8*)0x8061ff00; u8 *MEM1_lo_end = (u8*)0x8061ff00;
u8 *MEM1_lo_list = (u8*)0x932B0000; u8 *MEM1_lo_list = (u8*)0x90080800;
u8 *MEM2_lo_start = (u8*)0x90200000; u8 *MEM2_lo_start = (u8*)0x90200000;
u8 *MEM2_lo_end = (u8*)0x905fff00; u8 *MEM2_lo_end = (u8*)0x905fff00;
u8 *MEM2_lo_list = (u8*)0x932D0000; u8 *MEM2_lo_list = (u8*)0x900a0800;
u8 *MEM2_start = (u8*)0x90600000; u8 *MEM2_start = (u8*)0x90600000;
u8 *MEM2_end = (u8*)0x931fff00; u8 *MEM2_end = (u8*)0x932fff00;
u8 *MEM2_list = (u8*)0x93200000; u8 *MEM2_list = (u8*)0x90000800;
MemManager g_mem1lo; static MemManager g_mem1lo;
MemManager g_mem2lo; static MemManager g_mem2lo;
MemManager g_mem2gp; static MemManager g_mem2gp;
extern "C" extern "C"
{ {
@ -42,15 +42,13 @@ extern __typeof(malloc_usable_size) __real_malloc_usable_size;
void MEM_init() void MEM_init()
{ {
MemMutexInit();
g_mem1lo.Init(MEM1_lo_start, MEM1_lo_list, (u32)(MEM1_lo_end-MEM1_lo_start)); //about 6mb g_mem1lo.Init(MEM1_lo_start, MEM1_lo_list, (u32)(MEM1_lo_end-MEM1_lo_start)); //about 6mb
g_mem1lo.ClearMem(); g_mem1lo.ClearMem();
g_mem2lo.Init(MEM2_lo_start, MEM2_lo_list, (u32)(MEM2_lo_end-MEM2_lo_start)); //about 4mb g_mem2lo.Init(MEM2_lo_start, MEM2_lo_list, (u32)(MEM2_lo_end-MEM2_lo_start)); //about 4mb
g_mem2lo.ClearMem(); g_mem2lo.ClearMem();
g_mem2gp.Init(MEM2_start, MEM2_list, (u32)(MEM2_end-MEM2_start)); //about 44mb g_mem2gp.Init(MEM2_start, MEM2_list, (u32)(MEM2_end-MEM2_start)); //about 45mb
g_mem2gp.ClearMem(); g_mem2gp.ClearMem();
} }

View File

@ -20,19 +20,7 @@
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
#include "loader/utils.h" #include "loader/utils.h"
static mutex_t memMutex = 0; static const u32 MEM_BLOCK_SIZE = 0x80;
static const u32 MEM_BLOCK_SIZE = 128;
void MemMutexInit()
{
LWP_MutexInit(&memMutex, 0);
}
void MemMutexDestroy()
{
LWP_MutexDestroy(memMutex);
memset(&memMutex, 0, sizeof(mutex_t));
}
MemManager::MemManager() MemManager::MemManager()
{ {
@ -40,6 +28,12 @@ MemManager::MemManager()
memList = NULL; memList = NULL;
memListEnd = NULL; memListEnd = NULL;
memSize = 0; memSize = 0;
LWP_MutexInit(&memMutex, 0);
}
MemManager::~MemManager()
{
LWP_MutexDestroy(memMutex);
} }
void MemManager::Init(u8 *start, u8 *list, u32 size) void MemManager::Init(u8 *start, u8 *list, u32 size)
@ -51,10 +45,8 @@ void MemManager::Init(u8 *start, u8 *list, u32 size)
memList = list; memList = list;
memSize = ALIGN(MEM_BLOCK_SIZE, size) / MEM_BLOCK_SIZE; memSize = ALIGN(MEM_BLOCK_SIZE, size) / MEM_BLOCK_SIZE;
memListEnd = list + memSize; memListEnd = list + memSize;
ICInvalidateRange(memList, memSize+1);
memset(memList, MEM_FREE , memSize); memset(memList, MEM_FREE , memSize);
memset(memListEnd, MEM_END, 1); //thats the +1 memset(memListEnd, MEM_END, 1); //thats the +1
DCFlushRange(memList, memSize+1);
LWP_MutexUnlock(memMutex); LWP_MutexUnlock(memMutex);
} }
@ -65,9 +57,7 @@ void MemManager::ClearMem()
//gprintf("ClearMem %x %i\n", startAddr, memSize * MEM_BLOCK_SIZE); //gprintf("ClearMem %x %i\n", startAddr, memSize * MEM_BLOCK_SIZE);
u32 MemFull = memSize * MEM_BLOCK_SIZE; u32 MemFull = memSize * MEM_BLOCK_SIZE;
ICInvalidateRange(startAddr, MemFull);
memset(startAddr, 0, MemFull); memset(startAddr, 0, MemFull);
DCFlushRange(startAddr, MemFull);
LWP_MutexUnlock(memMutex); LWP_MutexUnlock(memMutex);
} }
@ -92,10 +82,8 @@ void *MemManager::Alloc(u32 size)
if(blocksFree == size) if(blocksFree == size)
{ {
u8 *addr = (u8*)block; u8 *addr = (u8*)block;
ICInvalidateRange(addr, blocksFree);
memset(addr, ALLOC_USED, blocksFree - 1); //start blocks memset(addr, ALLOC_USED, blocksFree - 1); //start blocks
memset(addr + blocksFree - 1, ALLOC_END, 1); //end block memset(addr + blocksFree - 1, ALLOC_END, 1); //end block
DCFlushRange(addr, blocksFree);
void *ptr = (void*)(startAddr + ((addr - memList)*MEM_BLOCK_SIZE)); void *ptr = (void*)(startAddr + ((addr - memList)*MEM_BLOCK_SIZE));
//gprintf("Alloc %x mem, %i blocks\n", ptr, blocksFree); //gprintf("Alloc %x mem, %i blocks\n", ptr, blocksFree);
LWP_MutexUnlock(memMutex); LWP_MutexUnlock(memMutex);
@ -126,9 +114,7 @@ void MemManager::Free(void *mem)
size++; size++;
u8 *addr = (u8*)blockUsed; u8 *addr = (u8*)blockUsed;
ICInvalidateRange(addr, size);
memset(addr, MEM_FREE, size); memset(addr, MEM_FREE, size);
DCFlushRange(addr, size);
LWP_MutexUnlock(memMutex); LWP_MutexUnlock(memMutex);
} }

View File

@ -31,6 +31,7 @@ enum mem_states
class MemManager { class MemManager {
public: public:
MemManager(); MemManager();
~MemManager();
void Init(u8 *start, u8 *list, u32 size); void Init(u8 *start, u8 *list, u32 size);
void ClearMem(); void ClearMem();
void *Alloc(u32 size); void *Alloc(u32 size);
@ -39,13 +40,11 @@ public:
u32 FreeSize(); u32 FreeSize();
void *ReAlloc(void *mem, u32 size); void *ReAlloc(void *mem, u32 size);
private: private:
mutex_t memMutex;
u8 *startAddr; u8 *startAddr;
u8 *memList; u8 *memList;
u8 *memListEnd; u8 *memListEnd;
u32 memSize; u32 memSize;
}; };
void MemMutexInit();
void MemMutexDestroy();
#endif #endif

View File

@ -36,6 +36,11 @@ extern const u32 hover_wav_size;
extern const u8 camera_wav[]; extern const u8 camera_wav[];
extern const u32 camera_wav_size; extern const u32 camera_wav_size;
CMenu mainMenu;
u8 CMenu::downloadStack[8192] ATTRIBUTE_ALIGN(32);
const u32 CMenu::downloadStackSize = 8192;
CMenu::CMenu() CMenu::CMenu()
{ {
m_aa = 0; m_aa = 0;

View File

@ -1190,6 +1190,9 @@ private:
static const SCFParamDesc _cfParams[]; static const SCFParamDesc _cfParams[];
static const int _nbCfgPages; static const int _nbCfgPages;
static const u32 SVN_REV_NUM; static const u32 SVN_REV_NUM;
//thread stack
static u8 downloadStack[8192];
static const u32 downloadStackSize;
}; };
extern CMenu mainMenu; extern CMenu mainMenu;

View File

@ -178,7 +178,8 @@ void CMenu::_CheatSettings()
m_thrdWorking = true; m_thrdWorking = true;
lwp_t thread = LWP_THREAD_NULL; lwp_t thread = LWP_THREAD_NULL;
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadCheatFileAsync, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadCheatFileAsync,
(void *)this, downloadStack, downloadStackSize, 40);
while(m_thrdWorking) while(m_thrdWorking)
{ {
_mainLoopCommon(); _mainLoopCommon();

View File

@ -1234,9 +1234,11 @@ void CMenu::_download(string gameId)
m_thrdWorking = true; m_thrdWorking = true;
gameId.clear(); gameId.clear();
if (dlAll) if (dlAll)
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderAll, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderAll,
(void *)this, downloadStack, downloadStackSize, 40);
else else
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderMissing, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderMissing,
(void *)this, downloadStack, downloadStackSize, 40);
} }
else if (m_btnMgr.selected(m_downloadBtnPrioM) && !m_thrdWorking) else if (m_btnMgr.selected(m_downloadBtnPrioM) && !m_thrdWorking)
{ {
@ -1456,7 +1458,8 @@ void CMenu::_download(string gameId)
_updateGametdb = true; _updateGametdb = true;
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_gametdbDownloader, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_gametdbDownloader,
(void *)this, downloadStack, downloadStackSize, 40);
} }
else if (m_btnMgr.selected(m_downloadBtnCancel)) else if (m_btnMgr.selected(m_downloadBtnCancel))
{ {
@ -2121,7 +2124,8 @@ void CMenu::_downloadBnr(const char *gameID)
m_thrdWorking = true; m_thrdWorking = true;
lwp_t thread = LWP_THREAD_NULL; lwp_t thread = LWP_THREAD_NULL;
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadBannerAsync, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadBannerAsync,
(void *)this, downloadStack, downloadStackSize, 40);
wstringEx prevMsg; wstringEx prevMsg;
while(m_thrdWorking) while(m_thrdWorking)
@ -2203,7 +2207,8 @@ void CMenu::_downloadUrl(const char *url, u8 **dl_file, u32 *dl_size)
m_thrdWorking = true; m_thrdWorking = true;
lwp_t thread = LWP_THREAD_NULL; lwp_t thread = LWP_THREAD_NULL;
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadUrlAsync, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadUrlAsync,
(void *)this, downloadStack, downloadStackSize, 40);
wstringEx prevMsg; wstringEx prevMsg;
while(m_thrdWorking) while(m_thrdWorking)

View File

@ -359,7 +359,6 @@ void CMenu::_game(bool launch)
m_gameSelected = true; m_gameSelected = true;
} }
if(m_banner.GetZoomSetting() != m_zoom_banner) if(m_banner.GetZoomSetting() != m_zoom_banner)
m_banner.ToogleZoom(); m_banner.ToogleZoom();
@ -1753,7 +1752,7 @@ void CMenu::_playGameSound(void)
if(m_gameSoundThread != LWP_THREAD_NULL) if(m_gameSoundThread != LWP_THREAD_NULL)
CheckGameSoundThread(); CheckGameSoundThread();
GameSoundStack = (u8*)MEM2_alloc(GameSoundSize); GameSoundStack = (u8*)MEM2_lo_alloc(GameSoundSize);
LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void*)this, GameSoundStack, GameSoundSize, 60); LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void*)this, GameSoundStack, GameSoundSize, 60);
} }
@ -1766,12 +1765,12 @@ void CMenu::CheckGameSoundThread()
LWP_ResumeThread(m_gameSoundThread); LWP_ResumeThread(m_gameSoundThread);
while(m_soundThrdBusy) while(m_soundThrdBusy)
usleep(50); usleep(500);
LWP_JoinThread(m_gameSoundThread, NULL); LWP_JoinThread(m_gameSoundThread, NULL);
m_gameSoundThread = LWP_THREAD_NULL; m_gameSoundThread = LWP_THREAD_NULL;
if(GameSoundStack) if(GameSoundStack)
free(GameSoundStack); MEM2_lo_free(GameSoundStack);
GameSoundStack = NULL; GameSoundStack = NULL;
} }

View File

@ -47,7 +47,8 @@ void CMenu::_system()
m_btnMgr.setProgress(m_downloadPBar, 0.f); m_btnMgr.setProgress(m_downloadPBar, 0.f);
m_thrdStop = false; m_thrdStop = false;
m_thrdWorking = true; m_thrdWorking = true;
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionTxtDownloaderInit, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionTxtDownloaderInit,
(void *)this, downloadStack, downloadStackSize, 40);
} }
if (m_showtimer > 0 && !m_thrdWorking) if (m_showtimer > 0 && !m_thrdWorking)
{ {
@ -112,7 +113,8 @@ void CMenu::_system()
m_data_update_url = fmt("%s/r%i/data.zip", m_version.getString("GENERAL", "update_url", "http://open-wiiflow-mod.googlecode.com/files").c_str(), newVer); m_data_update_url = fmt("%s/r%i/data.zip", m_version.getString("GENERAL", "update_url", "http://open-wiiflow-mod.googlecode.com/files").c_str(), newVer);
m_showtimer = 120; m_showtimer = 120;
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionDownloaderInit, (void *)this, 0, 8192, 40); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionDownloaderInit,
(void *)this, downloadStack, downloadStackSize, 40);
if (m_exit && !m_thrdWorking) if (m_exit && !m_thrdWorking)
{ {
m_thrdStop = true; m_thrdStop = true;

View File

@ -36,6 +36,9 @@
SoundHandler SoundHandle; SoundHandler SoundHandle;
u8 SoundHandler::SoundStack[32768] ATTRIBUTE_ALIGN(32);
const u32 SoundHandler::SoundStackSize = 32768;
void SoundHandler::Init() void SoundHandler::Init()
{ {
Decoding = false; Decoding = false;
@ -43,11 +46,7 @@ void SoundHandler::Init()
for(u32 i = 0; i < MAX_DECODERS; ++i) for(u32 i = 0; i < MAX_DECODERS; ++i)
DecoderList[i] = NULL; DecoderList[i] = NULL;
ThreadStack = (u8 *)MEM2_memalign(32, 32768); LWP_CreateThread(&SoundThread, UpdateThread, this, SoundStack, SoundStackSize, LWP_PRIO_HIGHEST);
if(!ThreadStack)
return;
LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST);
gprintf("SHND: Running sound thread\n"); gprintf("SHND: Running sound thread\n");
} }
@ -59,11 +58,6 @@ void SoundHandler::Cleanup()
ThreadSignal(); ThreadSignal();
LWP_JoinThread(SoundThread, NULL); LWP_JoinThread(SoundThread, NULL);
SoundThread = LWP_THREAD_NULL; SoundThread = LWP_THREAD_NULL;
if(ThreadStack != NULL)
{
MEM2_free(ThreadStack);
ThreadStack = NULL;
}
ClearDecoderList(); ClearDecoderList();
gprintf("SHND: Stopped sound thread\n"); gprintf("SHND: Stopped sound thread\n");

View File

@ -46,6 +46,9 @@ public:
SoundDecoder *Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); }; SoundDecoder *Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); }; void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
bool IsDecoding() { return Decoding; }; bool IsDecoding() { return Decoding; };
private: //thread stack
static u8 SoundStack[32768];
static const u32 SoundStackSize;
protected: protected:
static void *UpdateThread(void *arg); static void *UpdateThread(void *arg);
void InternalSoundUpdates(); void InternalSoundUpdates();
@ -53,7 +56,6 @@ protected:
SoundDecoder *GetSoundDecoder(const char *filepath); SoundDecoder *GetSoundDecoder(const char *filepath);
SoundDecoder *GetSoundDecoder(const u8 *sound, int length); SoundDecoder *GetSoundDecoder(const u8 *sound, int length);
u8 *ThreadStack;
lwp_t SoundThread; lwp_t SoundThread;
lwpq_t ThreadQueue; lwpq_t ThreadQueue;
bool Decoding; bool Decoding;