Ticket #8902: 0001-Fix-8902.-Wait-for-loader-threads-before-exit.patch

File 0001-Fix-8902.-Wait-for-loader-threads-before-exit.patch, 2.1 KB (added by Janus, 6 years ago)
  • src/apps/showimage/ImageCache.cpp

    From 762e0f5639a6f6916ff567256726fc36905dff97 Mon Sep 17 00:00:00 2001
    From: Janus <janus2@ymail.com>
    Date: Thu, 26 Feb 2015 23:06:04 +0000
    Subject: [PATCH] Fix #8902. Wait for loader threads before exit
    
    ---
     src/apps/showimage/ImageCache.cpp   | 23 +++++++++++++++++++++++
     src/apps/showimage/ImageCache.h     |  1 +
     src/apps/showimage/ShowImageApp.cpp |  3 +++
     3 files changed, 27 insertions(+)
    
    diff --git a/src/apps/showimage/ImageCache.cpp b/src/apps/showimage/ImageCache.cpp
    index 6f3e5ff..187c2b5 100644
    a b ImageCache::RetrieveImage(const entry_ref& ref, int32 page,  
    160160}
    161161
    162162
     163void
     164ImageCache::Stop()
     165{
     166    // empty the working queue
     167    fLocker.Lock();
     168    while (!fQueue.empty()) {
     169        QueueEntry* entry = *fQueue.begin();
     170        fQueue.pop_front();
     171        delete entry;
     172    }
     173    fLocker.Unlock();
     174
     175    // wait for running thread
     176    thread_id thread;
     177    while (true) {
     178        thread = find_thread("image loader");
     179        if (thread == B_NAME_NOT_FOUND)
     180            break;
     181        wait_for_thread(thread, NULL);
     182    }
     183}
     184
     185
    163186/*static*/ status_t
    164187ImageCache::_QueueWorkerThread(void* _self)
    165188{
  • src/apps/showimage/ImageCache.h

    diff --git a/src/apps/showimage/ImageCache.h b/src/apps/showimage/ImageCache.h
    index ac572c0..87fea3b 100644
    a b public:  
    5858            status_t            RetrieveImage(const entry_ref& ref,
    5959                                    int32 page = 1,
    6060                                    const BMessenger* target = NULL);
     61            void                Stop();
    6162
    6263private:
    6364                                ImageCache();
  • src/apps/showimage/ShowImageApp.cpp

    diff --git a/src/apps/showimage/ShowImageApp.cpp b/src/apps/showimage/ShowImageApp.cpp
    index c3147da..dd37414 100644
    a b  
    2222#include <Screen.h>
    2323#include <String.h>
    2424
     25#include "ImageCache.h"
    2526#include "ShowImageConstants.h"
    2627#include "ShowImageWindow.h"
    2728#include "ToolBarIcons.h"
    ShowImageApp::QuitRequested()  
    175176            // tell clipboard we don't want anymore notification
    176177    }
    177178
     179    ImageCache::Default().Stop();
     180
    178181    return result;
    179182}
    180183