VirtualBox

Changeset 14382 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 19, 2008 10:50:38 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: Fixed unsafe usage of QLinkedList on multiple threads.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp

    r14372 r14382  
    608608    /** Constructs a regular enum event */
    609609    VBoxMediaEnumEvent (const VBoxMedium &aMedium,
    610                         VBoxMediaList::const_iterator &aIterator)
     610                        VBoxMediaList::iterator &aIterator)
    611611        : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType)
    612612        , mMedium (aMedium), mIterator (aIterator), mLast (false)
    613613        {}
    614614    /** Constructs the last enum event */
    615     VBoxMediaEnumEvent()
     615    VBoxMediaEnumEvent (VBoxMediaList::iterator &aIterator)
    616616        : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType)
    617         , mLast (true)
     617        , mIterator (aIterator), mLast (true)
    618618        {}
    619619
    620     /** The last enumerated medium iterator (invalid when #last is true) */
    621     VBoxMediaList::const_iterator mIterator;
    622     /** The last enumerated medium (not valid when #last is true) */
     620    /** Last enumerated medium (not valid when #last is true) */
    623621    const VBoxMedium mMedium;
     622    /** Opaque iterator provided by the event sender (guaranteed to be
     623     *  the same variable for all media in the single enumeration procedure) */
     624    VBoxMediaList::iterator &mIterator;
    624625    /** Whether this is the last event for the given enumeration or not */
    625626    const bool mLast;
     
    28422843    public:
    28432844
    2844         MediaEnumThread (const VBoxMediaList &aList) : mList (aList) {}
     2845        MediaEnumThread (VBoxMediaList &aList)
     2846            : mSavedIt (aList.begin())
     2847        {
     2848            for (VBoxMediaList::const_iterator it = aList.begin();
     2849                 it != aList.end(); ++ it)
     2850                mVector.append (*it);
     2851        }
    28452852
    28462853        virtual void run()
     
    28532860
    28542861            /* Enumerate the list */
    2855             for (VBoxMediaList::const_iterator it = mList.begin();
    2856                  it != mList.end() && !sVBoxGlobalInCleanup; ++ it)
     2862            for (int i = 0; i < mVector.size() && !sVBoxGlobalInCleanup; ++ i)
    28572863            {
    2858                 VBoxMedium medium = *it;
    2859                 medium.blockAndQueryState();
    2860                 QApplication::postEvent (self, new VBoxMediaEnumEvent (medium, it));
     2864                mVector [i].blockAndQueryState();
     2865                QApplication::
     2866                    postEvent (self,
     2867                               new VBoxMediaEnumEvent (mVector [i], mSavedIt));
    28612868            }
    28622869
    28632870            /* Post the end-of-enumeration event */
    28642871            if (!sVBoxGlobalInCleanup)
    2865                 QApplication::postEvent (self, new VBoxMediaEnumEvent());
     2872                QApplication::postEvent (self, new VBoxMediaEnumEvent (mSavedIt));
    28662873
    28672874            COMBase::CleanupCOM();
     
    28712878    private:
    28722879
    2873         const VBoxMediaList &mList;
     2880        QVector <VBoxMedium> mVector;
     2881        VBoxMediaList::iterator mSavedIt;
    28742882    };
    28752883
     
    49504958                    vboxProblem().cannotGetMediaAccessibility (ev->mMedium);
    49514959                Assert (ev->mIterator != mMediaList.end());
    4952                 VBoxMedium *medium = unconst (&*ev->mIterator);
    4953                 *medium = ev->mMedium;
    4954                 emit mediumEnumerated (*medium);
     4960                *(ev->mIterator) = ev->mMedium;
     4961                emit mediumEnumerated (*ev->mIterator);
     4962                ++ ev->mIterator;
    49554963            }
    49564964            else
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette