Showimage: Wait for loader threads on exit.

* Uses find_thread to wait for loader threads.
  (better solutions are welcome)
* As suggested by Axel the cache isn't static anymore.
* Fixes 8902.
This commit is contained in:
Janus
2015-04-07 16:15:46 +00:00
parent 51362d85d8
commit be63ec85a8
5 changed files with 33 additions and 12 deletions
+24 -4
View File
@@ -38,9 +38,6 @@ struct QueueEntry {
}; };
/*static*/ ImageCache ImageCache::sCache;
// #pragma mark - // #pragma mark -
@@ -82,7 +79,7 @@ ImageCache::ImageCache()
ImageCache::~ImageCache() ImageCache::~ImageCache()
{ {
// TODO: delete CacheEntries, and QueueEntries Stop();
} }
@@ -160,6 +157,29 @@ ImageCache::RetrieveImage(const entry_ref& ref, int32 page,
} }
void
ImageCache::Stop()
{
// empty the working queue
fLocker.Lock();
while (!fQueue.empty()) {
QueueEntry* entry = *fQueue.begin();
fQueue.pop_front();
delete entry;
}
fLocker.Unlock();
// wait for running thread
thread_id thread;
while (true) {
thread = find_thread("image loader");
if (thread == B_NAME_NOT_FOUND)
break;
wait_for_thread(thread, NULL);
}
}
/*static*/ status_t /*static*/ status_t
ImageCache::_QueueWorkerThread(void* _self) ImageCache::_QueueWorkerThread(void* _self)
{ {
+3 -6
View File
@@ -53,15 +53,14 @@ struct CacheEntry : DoublyLinkedListLinkImpl<CacheEntry> {
class ImageCache { class ImageCache {
public: public:
static ImageCache& Default() { return sCache; } ImageCache();
virtual ~ImageCache();
status_t RetrieveImage(const entry_ref& ref, status_t RetrieveImage(const entry_ref& ref,
int32 page = 1, int32 page = 1,
const BMessenger* target = NULL); const BMessenger* target = NULL);
void Stop();
private: private:
ImageCache();
virtual ~ImageCache();
static status_t _QueueWorkerThread(void* self); static status_t _QueueWorkerThread(void* self);
@@ -91,8 +90,6 @@ private:
uint64 fBytes; uint64 fBytes;
uint64 fMaxBytes; uint64 fMaxBytes;
size_t fMaxEntries; size_t fMaxEntries;
static ImageCache sCache;
}; };
+1
View File
@@ -174,6 +174,7 @@ ShowImageApp::QuitRequested()
be_clipboard->StopWatching(be_app_messenger); be_clipboard->StopWatching(be_app_messenger);
// tell clipboard we don't want anymore notification // tell clipboard we don't want anymore notification
} }
DefaultCache().Stop();
return result; return result;
} }
+3
View File
@@ -11,6 +11,7 @@
#define SHOW_IMAGE_APP_H #define SHOW_IMAGE_APP_H
#include "ImageCache.h"
#include "ShowImageSettings.h" #include "ShowImageSettings.h"
#include <Application.h> #include <Application.h>
@@ -35,6 +36,7 @@ public:
virtual bool QuitRequested(); virtual bool QuitRequested();
ShowImageSettings* Settings() { return &fSettings; } ShowImageSettings* Settings() { return &fSettings; }
ImageCache& DefaultCache() { return fImageCache; }
private: private:
void _StartPulse(); void _StartPulse();
@@ -48,6 +50,7 @@ private:
BFilePanel* fOpenPanel; BFilePanel* fOpenPanel;
bool fPulseStarted; bool fPulseStarted;
ShowImageSettings fSettings; ShowImageSettings fSettings;
ImageCache fImageCache;
BRect fLastWindowFrame; BRect fLastWindowFrame;
}; };
+2 -2
View File
@@ -1234,7 +1234,7 @@ status_t
ShowImageWindow::_LoadImage(bool forward) ShowImageWindow::_LoadImage(bool forward)
{ {
BMessenger us(this); BMessenger us(this);
status_t status = ImageCache::Default().RetrieveImage( status_t status = my_app->DefaultCache().RetrieveImage(
fNavigator.CurrentRef(), fNavigator.CurrentPage(), &us); fNavigator.CurrentRef(), fNavigator.CurrentPage(), &us);
if (status != B_OK) if (status != B_OK)
return status; return status;
@@ -1263,7 +1263,7 @@ ShowImageWindow::_PreloadImage(bool forward, entry_ref& ref)
|| (!forward && !fNavigator.GetPreviousFile(currentRef, ref))) || (!forward && !fNavigator.GetPreviousFile(currentRef, ref)))
return false; return false;
return ImageCache::Default().RetrieveImage(ref) == B_OK; return my_app->DefaultCache().RetrieveImage(ref) == B_OK;
} }