Multi-threaded file dialog

meow-7.2.2
Dave Parks 2010-03-08 21:33:19 -06:00
parent b9a2c6eafa
commit 38334e22e3
5 changed files with 99 additions and 8 deletions

View File

@ -78,6 +78,7 @@
#include "llteleporthistory.h"
#include "lllocationhistory.h"
#include "llfasttimerview.h"
#include "llviewermenufile.h"
#include "llvoicechannel.h"
#include "llsidetray.h"
@ -1567,6 +1568,8 @@ bool LLAppViewer::cleanup()
sTextureFetch->shutDownTextureCacheThread() ;
sTextureFetch->shutDownImageDecodeThread() ;
LLFilePickerThread::cleanupClass();
delete sTextureCache;
sTextureCache = NULL;
delete sTextureFetch;
@ -1717,6 +1720,8 @@ bool LLAppViewer::initThreads()
// Mesh streaming and caching
gMeshRepo.init();
LLFilePickerThread::initClass();
// *FIX: no error handling here!
return true;
}
@ -3461,6 +3466,8 @@ void LLAppViewer::idle()
LLEventTimer::updateClass();
LLCriticalDamp::updateInterpolants();
LLMortician::updateClass();
LLFilePickerThread::clearDead(); //calls LLFilePickerThread::notify()
F32 dt_raw = idle_timer.getElapsedTimeAndResetF32();
// Cap out-of-control frame times

View File

@ -211,7 +211,7 @@ BOOL LLFilePicker::setupFilter(ELoadFilter filter)
return res;
}
BOOL LLFilePicker::getOpenFile(ELoadFilter filter)
BOOL LLFilePicker::getOpenFile(ELoadFilter filter, BOOL blocking)
{
if( mLocked )
{
@ -230,8 +230,11 @@ BOOL LLFilePicker::getOpenFile(ELoadFilter filter)
setupFilter(filter);
// Modal, so pause agent
send_agent_pause();
if (blocking)
{
// Modal, so pause agent
send_agent_pause();
}
reset();
@ -242,10 +245,14 @@ BOOL LLFilePicker::getOpenFile(ELoadFilter filter)
std::string filename = utf16str_to_utf8str(llutf16string(mFilesW));
mFiles.push_back(filename);
}
send_agent_resume();
// Account for the fact that the app has been stalled.
LLFrameTimer::updateFrameTime();
if (blocking)
{
send_agent_resume();
// Account for the fact that the app has been stalled.
LLFrameTimer::updateFrameTime();
}
return success;
}

View File

@ -113,7 +113,7 @@ public:
// open the dialog. This is a modal operation
BOOL getSaveFile( ESaveFilter filter = FFSAVE_ALL, const std::string& filename = LLStringUtil::null );
BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL );
BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL, BOOL blocking = TRUE );
BOOL getMultipleOpenFiles( ELoadFilter filter = FFLOAD_ALL );
// Get the filename(s) found. getFirstFile() sets the pointer to

View File

@ -100,6 +100,57 @@ class LLFileEnableUploadModel : public view_listener_t
}
};
LLMutex* LLFilePickerThread::sMutex = NULL;
std::queue<LLFilePickerThread*> LLFilePickerThread::sDeadQ;
//virtual
void LLFilePickerThread::run()
{
LLFilePicker picker;
if (picker.getOpenFile(mFilter, FALSE))
{
mFile = picker.getFirstFile();
}
{
LLMutexLock lock(sMutex);
sDeadQ.push(this);
}
}
//static
void LLFilePickerThread::initClass()
{
sMutex = new LLMutex(NULL);
}
//static
void LLFilePickerThread::cleanupClass()
{
clearDead();
delete sMutex;
sMutex = NULL;
}
//static
void LLFilePickerThread::clearDead()
{
if (!sDeadQ.empty())
{
LLMutexLock lock(sMutex);
while (!sDeadQ.empty())
{
LLFilePickerThread* thread = sDeadQ.front();
thread->notify(thread->mFile);
delete thread;
sDeadQ.pop();
}
}
}
//============================================================================
#if LL_WINDOWS
@ -290,7 +341,7 @@ class LLFileUploadModel : public view_listener_t
{
bool handleEvent(const LLSD& userdata)
{
LLFloaterModelPreview* fmp = (LLFloaterModelPreview*) LLFloaterReg::showInstance("upload_model");
LLFloaterModelPreview* fmp = (LLFloaterModelPreview*) LLFloaterReg::getInstance("upload_model");
if (fmp)
{
fmp->loadModel(3);

View File

@ -36,6 +36,7 @@
#include "llfoldertype.h"
#include "llassetstorage.h"
#include "llinventorytype.h"
#include "llfilepicker.h"
class LLTransactionID;
@ -120,5 +121,30 @@ void on_new_single_inventory_upload_complete(
const LLSD& server_response,
S32 upload_price);
class LLFilePickerThread : public LLThread
{ //multi-threaded file picker (runs system specific file picker in background and calls "notify" from main thread)
public:
static std::queue<LLFilePickerThread*> sDeadQ;
static LLMutex* sMutex;
static void initClass();
static void cleanupClass();
static void clearDead();
std::string mFile;
LLFilePicker::ELoadFilter mFilter;
LLFilePickerThread(LLFilePicker::ELoadFilter filter)
: LLThread("file picker"), mFilter(filter)
{
}
virtual void run();
virtual void notify(const std::string& filename) = 0;
};
#endif