VirtualBox

Changeset 26167 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 2, 2010 7:59:09 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57181
Message:

Main: get rid of isModified() loops in Machine and subclasses; instead, on every change in machine settings, set dirty bits in Machine

Location:
trunk/src/VBox/Main
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/AudioAdapterImpl.cpp

    r26156 r26167  
    205205        mData.backup();
    206206        mData->mEnabled = aEnabled;
     207
     208        alock.release();
     209        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     210        mParent->setModified(Machine::IsModified_AudioAdapter);
    207211    }
    208212
     
    279283                mData.backup();
    280284                mData->mAudioDriver = aAudioDriver;
     285
     286                alock.release();
     287                AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     288                mParent->setModified(Machine::IsModified_AudioAdapter);
    281289                break;
    282290            }
     
    330338            case AudioControllerType_AC97:
    331339            case AudioControllerType_SB16:
     340            {
    332341                mData.backup();
    333342                mData->mAudioController = aAudioController;
     343
     344                alock.release();
     345                AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     346                mParent->setModified(Machine::IsModified_AudioAdapter);
    334347                break;
     348            }
    335349
    336350            default:
    337             {
    338351                AssertMsgFailed (("Wrong audio controller type %d\n",
    339352                                  aAudioController));
    340353                rc = E_FAIL;
    341             }
    342354        }
    343355    }
     
    414426}
    415427
    416 bool AudioAdapter::isModified()
    417 {
    418     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    419     return mData.isBackedUp();
    420 }
    421 
    422428/**
    423429 *  @note Locks this object for writing.
  • trunk/src/VBox/Main/BIOSSettingsImpl.cpp

    r26156 r26167  
    213213    m->bd->fLogoFadeIn = enable;
    214214
     215    alock.release();
     216    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     217    m->pMachine->setModified(Machine::IsModified_BIOS);
     218
    215219    return S_OK;
    216220}
     
    245249    m->bd->fLogoFadeOut = enable;
    246250
     251    alock.release();
     252    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     253    m->pMachine->setModified(Machine::IsModified_BIOS);
     254
    247255    return S_OK;
    248256}
     
    276284    m->bd.backup();
    277285    m->bd->ulLogoDisplayTime = displayTime;
     286
     287    alock.release();
     288    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     289    m->pMachine->setModified(Machine::IsModified_BIOS);
    278290
    279291    return S_OK;
     
    312324    m->bd->strLogoImagePath = imagePath;
    313325
     326    alock.release();
     327    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     328    m->pMachine->setModified(Machine::IsModified_BIOS);
     329
    314330    return S_OK;
    315331}
     
    343359    m->bd->biosBootMenuMode = bootMenuMode;
    344360
     361    alock.release();
     362    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     363    m->pMachine->setModified(Machine::IsModified_BIOS);
     364
    345365    return S_OK;
    346366}
     
    375395    m->bd->fACPIEnabled = enable;
    376396
     397    alock.release();
     398    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     399    m->pMachine->setModified(Machine::IsModified_BIOS);
     400
    377401    return S_OK;
    378402}
     
    407431    m->bd->fIOAPICEnabled = enable;
    408432
     433    alock.release();
     434    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     435    m->pMachine->setModified(Machine::IsModified_BIOS);
     436
    409437    return S_OK;
    410438}
     
    439467    m->bd->fPXEDebugEnabled = enable;
    440468
     469    alock.release();
     470    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     471    m->pMachine->setModified(Machine::IsModified_BIOS);
     472
    441473    return S_OK;
    442474}
     
    470502    m->bd.backup();
    471503    m->bd->llTimeOffset = offset;
     504
     505    alock.release();
     506    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);  // mParent is const, needs no locking
     507    m->pMachine->setModified(Machine::IsModified_BIOS);
    472508
    473509    return S_OK;
     
    519555
    520556    return S_OK;
    521 }
    522 
    523 bool BIOSSettings::isModified()
    524 {
    525     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    526     return m->bd.isBackedUp();
    527557}
    528558
  • trunk/src/VBox/Main/MachineImpl.cpp

    r26156 r26167  
    408408    unconst(mParent) = aParent;
    409409
     410    m_flModifications = 0;
     411
    410412    /* allocate the essential machine data structure (the rest will be
    411413     * allocated later by initDataAndChildObjects() */
     
    413415
    414416    mData->m_pMachineConfigFile = NULL;
     417    m_flModifications = 0;
    415418
    416419    /* memorize the config file name (as provided) */
     
    681684    alock.leave();
    682685
    683     if (isModified())
     686    // has machine been modified?
     687    if (m_flModifications)
    684688    {
    685689        LogWarningThisFunc(("Discarding unsaved settings changes!\n"));
    686         rollback (false /* aNotify */);
     690        rollback(false /* aNotify */);
    687691    }
    688692
     
    828832    if (FAILED(rc)) return rc;
    829833
     834    setModified(IsModified_MachineData);
    830835    mUserData.backup();
    831836    mUserData->mName = aName;
     
    858863    if (FAILED(rc)) return rc;
    859864
     865    setModified(IsModified_MachineData);
    860866    mUserData.backup();
    861867    mUserData->mDescription = aDescription;
     
    916922    if (FAILED(rc)) return rc;
    917923
     924    setModified(IsModified_MachineData);
    918925    mUserData.backup();
    919926    mUserData->mOSTypeId = osTypeId;
     
    946953    if (FAILED(rc)) return rc;
    947954
     955    setModified(IsModified_MachineData);
    948956    mHWData.backup();
    949957    mHWData->mFirmwareType = aFirmwareType;
     
    984992    if (FAILED(rc)) return rc;
    985993
     994    setModified(IsModified_MachineData);
    986995    mHWData.backup();
    987996    mHWData->mHWVersion = hwVersion;
     
    10211030    if (FAILED(rc)) return rc;
    10221031
     1032    setModified(IsModified_MachineData);
    10231033    mHWData.backup();
    10241034    if (hardwareUUID == mData->mUuid)
     
    10631073    if (FAILED(rc)) return rc;
    10641074
     1075    setModified(IsModified_MachineData);
    10651076    mHWData.backup();
    10661077    mHWData->mMemorySize = memorySize;
     
    11141125    if (FAILED(rc)) return rc;
    11151126
     1127    setModified(IsModified_MachineData);
    11161128    mHWData.backup();
    11171129    mHWData->mCPUCount = CPUCount;
     
    11511163        if (enabled)
    11521164        {
     1165            setModified(IsModified_MachineData);
    11531166            mHWData.backup();
    11541167
     
    11821195                                tr("CPU hotplugging can't be disabled because the maximum number of CPUs is not equal to the amount of CPUs attached\n"));
    11831196
     1197            setModified(IsModified_MachineData);
    11841198            mHWData.backup();
    11851199        }
     
    12231237    if (FAILED(rc)) return rc;
    12241238
     1239    setModified(IsModified_MachineData);
    12251240    mHWData.backup();
    12261241    mHWData->mVRAMSize = memorySize;
     
    12621277    if (FAILED(rc)) return rc;
    12631278
     1279    setModified(IsModified_MachineData);
    12641280    mHWData.backup();
    12651281    mHWData->mMemoryBalloonSize = memoryBalloonSize;
     
    12951311    if (FAILED(rc)) return rc;
    12961312
     1313    setModified(IsModified_MachineData);
    12971314    mHWData.backup();
    12981315    mHWData->mStatisticsUpdateInterval = statisticsUpdateInterval;
     
    13291346    /** @todo check validity! */
    13301347
     1348    setModified(IsModified_MachineData);
    13311349    mHWData.backup();
    13321350    mHWData->mAccelerate3DEnabled = enable;
     
    13631381    /** @todo check validity! */
    13641382
     1383    setModified(IsModified_MachineData);
    13651384    mHWData.backup();
    13661385    mHWData->mAccelerate2DVideoEnabled = enable;
     
    14001419    if (FAILED(rc)) return rc;
    14011420
     1421    setModified(IsModified_MachineData);
    14021422    mHWData.backup();
    14031423    mHWData->mMonitorCount = monitorCount;
     
    17071727    if (FAILED(rc)) return rc;
    17081728
     1729    BOOL *pb;
     1730
    17091731    switch(property)
    17101732    {
    1711     case HWVirtExPropertyType_Enabled:
     1733        case HWVirtExPropertyType_Enabled:
     1734            pb = &mHWData->mHWVirtExEnabled;
     1735        break;
     1736
     1737        case HWVirtExPropertyType_Exclusive:
     1738            pb = &mHWData->mHWVirtExExclusive;
     1739        break;
     1740
     1741        case HWVirtExPropertyType_VPID:
     1742            pb = &mHWData->mHWVirtExVPIDEnabled;
     1743        break;
     1744
     1745        case HWVirtExPropertyType_NestedPaging:
     1746            pb = &mHWData->mHWVirtExNestedPagingEnabled;
     1747        break;
     1748
     1749        default:
     1750            return E_INVALIDARG;
     1751    }
     1752
     1753    if (*pb != !!aVal)
     1754    {
     1755        setModified(IsModified_MachineData);
    17121756        mHWData.backup();
    1713         mHWData->mHWVirtExEnabled = !!aVal;
    1714         break;
    1715 
    1716     case HWVirtExPropertyType_Exclusive:
    1717         mHWData.backup();
    1718         mHWData->mHWVirtExExclusive = !!aVal;
    1719         break;
    1720 
    1721     case HWVirtExPropertyType_VPID:
    1722         mHWData.backup();
    1723         mHWData->mHWVirtExVPIDEnabled = !!aVal;
    1724         break;
    1725 
    1726     case HWVirtExPropertyType_NestedPaging:
    1727         mHWData.backup();
    1728         mHWData->mHWVirtExNestedPagingEnabled = !!aVal;
    1729         break;
    1730 
    1731     default:
    1732         return E_INVALIDARG;
     1757        *pb = !!aVal;
    17331758    }
    17341759    return S_OK;
     
    17781803        {
    17791804            /* the default snapshots folder is 'Snapshots' in the machine dir */
    1780             snapshotFolder = Utf8Str ("Snapshots");
     1805            snapshotFolder = "Snapshots";
    17811806        }
    17821807        else
     
    17841809            /* the default snapshots folder is {UUID}, for backwards
    17851810             * compatibility and to resolve conflicts */
    1786             snapshotFolder = Utf8StrFmt ("{%RTuuid}", mData->mUuid.raw());
     1811            snapshotFolder = Utf8StrFmt("{%RTuuid}", mData->mUuid.raw());
    17871812        }
    17881813    }
     
    17941819                        aSnapshotFolder, vrc);
    17951820
     1821    setModified(IsModified_MachineData);
    17961822    mUserData.backup();
    17971823    mUserData->mSnapshotFolder = aSnapshotFolder;
     
    18951921    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    18961922
    1897     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1923    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    18981924
    18991925    HRESULT rc = checkStateDependency(MutableStateDep);
     
    19061932        *aModified = TRUE;
    19071933    else
    1908         *aModified = isModified();
     1934        *aModified = (m_flModifications != 0);
    19091935
    19101936    return S_OK;
     
    21092135    if (FAILED(rc)) return rc;
    21102136
     2137    setModified(IsModified_MachineData);
    21112138    mHWData.backup();
    21122139    mHWData->mClipboardMode = aClipboardMode;
     
    21492176    if (FAILED(rc)) return rc;
    21502177
    2151     try
    2152     {
    2153         mHWData.backup();
    2154         mHWData->mGuestPropertyNotificationPatterns = aPatterns;
    2155     }
    2156     catch (...)
    2157     {
    2158         rc = VirtualBox::handleUnexpectedExceptions(RT_SRC_POS);
    2159     }
     2178    setModified(IsModified_MachineData);
     2179    mHWData.backup();
     2180    mHWData->mGuestPropertyNotificationPatterns = aPatterns;
    21602181    return rc;
    21612182}
     
    21922213}
    21932214
    2194 STDMETHODIMP
    2195 Machine::COMSETTER(TeleporterEnabled)(BOOL aEnabled)
     2215STDMETHODIMP Machine::COMSETTER(TeleporterEnabled)(BOOL aEnabled)
    21962216{
    21972217    AutoCaller autoCaller(this);
     
    22152235                        Global::stringifyMachineState(mData->mMachineState));
    22162236
     2237    setModified(IsModified_MachineData);
    22172238    mUserData.backup();
    22182239    mUserData->mTeleporterEnabled = aEnabled;
     
    22212242}
    22222243
    2223 STDMETHODIMP
    2224 Machine::COMGETTER(TeleporterPort)(ULONG *aPort)
     2244STDMETHODIMP Machine::COMGETTER(TeleporterPort)(ULONG *aPort)
    22252245{
    22262246    CheckComArgOutPointerValid(aPort);
     
    22362256}
    22372257
    2238 STDMETHODIMP
    2239 Machine::COMSETTER(TeleporterPort)(ULONG aPort)
     2258STDMETHODIMP Machine::COMSETTER(TeleporterPort)(ULONG aPort)
    22402259{
    22412260    if (aPort >= _64K)
     
    22502269    if (FAILED(rc)) return rc;
    22512270
     2271    setModified(IsModified_MachineData);
    22522272    mUserData.backup();
    22532273    mUserData->mTeleporterPort = aPort;
     
    22562276}
    22572277
    2258 STDMETHODIMP
    2259 Machine::COMGETTER(TeleporterAddress)(BSTR *aAddress)
     2278STDMETHODIMP Machine::COMGETTER(TeleporterAddress)(BSTR *aAddress)
    22602279{
    22612280    CheckComArgOutPointerValid(aAddress);
     
    22712290}
    22722291
    2273 STDMETHODIMP
    2274 Machine::COMSETTER(TeleporterAddress)(IN_BSTR aAddress)
     2292STDMETHODIMP Machine::COMSETTER(TeleporterAddress)(IN_BSTR aAddress)
    22752293{
    22762294    AutoCaller autoCaller(this);
     
    22822300    if (FAILED(rc)) return rc;
    22832301
     2302    setModified(IsModified_MachineData);
    22842303    mUserData.backup();
    22852304    mUserData->mTeleporterAddress = aAddress;
     
    22882307}
    22892308
    2290 STDMETHODIMP
    2291 Machine::COMGETTER(TeleporterPassword)(BSTR *aPassword)
     2309STDMETHODIMP Machine::COMGETTER(TeleporterPassword)(BSTR *aPassword)
    22922310{
    22932311    CheckComArgOutPointerValid(aPassword);
     
    23032321}
    23042322
    2305 STDMETHODIMP
    2306 Machine::COMSETTER(TeleporterPassword)(IN_BSTR aPassword)
     2323STDMETHODIMP Machine::COMSETTER(TeleporterPassword)(IN_BSTR aPassword)
    23072324{
    23082325    AutoCaller autoCaller(this);
     
    23142331    if (FAILED(rc)) return rc;
    23152332
     2333    setModified(IsModified_MachineData);
    23162334    mUserData.backup();
    23172335    mUserData->mTeleporterPassword = aPassword;
     
    23202338}
    23212339
    2322 STDMETHODIMP
    2323 Machine::COMGETTER(RTCUseUTC)(BOOL *aEnabled)
     2340STDMETHODIMP Machine::COMGETTER(RTCUseUTC)(BOOL *aEnabled)
    23242341{
    23252342    CheckComArgOutPointerValid(aEnabled);
     
    23352352}
    23362353
    2337 STDMETHODIMP
    2338 Machine::COMSETTER(RTCUseUTC)(BOOL aEnabled)
     2354STDMETHODIMP Machine::COMSETTER(RTCUseUTC)(BOOL aEnabled)
    23392355{
    23402356    AutoCaller autoCaller(this);
     
    23582374                        Global::stringifyMachineState(mData->mMachineState));
    23592375
     2376    setModified(IsModified_MachineData);
    23602377    mUserData.backup();
    23612378    mUserData->mRTCUseUTC = aEnabled;
     
    23642381}
    23652382
    2366 
    2367 // IMachine methods
    2368 /////////////////////////////////////////////////////////////////////////////
    2369 
    2370 STDMETHODIMP Machine::SetBootOrder (ULONG aPosition, DeviceType_T aDevice)
     2383STDMETHODIMP Machine::SetBootOrder(ULONG aPosition, DeviceType_T aDevice)
    23712384{
    23722385    if (aPosition < 1 || aPosition > SchemaDefs::MaxBootPosition)
     
    23872400    if (FAILED(rc)) return rc;
    23882401
     2402    setModified(IsModified_MachineData);
    23892403    mHWData.backup();
    23902404    mHWData->mBootOrder [aPosition - 1] = aDevice;
     
    28232837
    28242838    /* success: finally remember the attachment */
     2839    setModified(IsModified_Storage);
    28252840    mMediaData.backup();
    28262841    mMediaData->mAttachments.push_back(attachment);
     
    29012916    }
    29022917
     2918    setModified(IsModified_Storage);
    29032919    mMediaData.backup();
    29042920
     
    29552971
    29562972
     2973    setModified(IsModified_Storage);
    29572974    mMediaData.backup();
    29582975
     
    30663083    if (SUCCEEDED(rc))
    30673084    {
    3068 
     3085        setModified(IsModified_Storage);
    30693086        mMediaData.backup();
     3087
    30703088        /* The backup operation makes the pAttach reference point to the
    30713089         * old settings. Re-get the correct reference. */
     
    35143532    if (FAILED(rc)) return rc;
    35153533
     3534    setModified(IsModified_SharedFolders);
    35163535    mHWData.backup();
    35173536    mHWData->mSharedFolders.push_back (sharedFolder);
     
    35403559    if (FAILED(rc)) return rc;
    35413560
     3561    setModified(IsModified_SharedFolders);
    35423562    mHWData.backup();
    35433563    mHWData->mSharedFolders.remove (sharedFolder);
     
    37433763                    else
    37443764                    {
    3745                         mHWData.backup();
     3765                        setModified(IsModified_MachineData);
     3766                        mHWData.backup();           // @todo r=dj backup in a loop?!?
     3767
    37463768                        /* The backup() operation invalidates our iterator, so
    37473769                        * get a new one. */
     
    37503772                             ++it)
    37513773                            ;
    3752                         mHWData->mGuestProperties.erase (it);
     3774                        mHWData->mGuestProperties.erase(it);
    37533775                    }
    37543776                    found = true;
     
    37703792            {
    37713793                RTTIMESPEC time;
     3794                setModified(IsModified_MachineData);
    37723795                mHWData.backup();
    37733796                property.strName = aName;
     
    40084031    if (FAILED(rc)) return rc;
    40094032
     4033    setModified(IsModified_Storage);
    40104034    mStorageControllers.backup();
    40114035    mStorageControllers->push_back (ctrl);
     
    40924116
    40934117    /* We can remove it now. */
     4118    setModified(IsModified_Storage);
    40944119    mStorageControllers.backup();
    40954120
     
    44094434    if (FAILED(rc)) return rc;
    44104435
     4436    setModified(IsModified_MachineData);
    44114437    mHWData.backup();
    44124438    mHWData->mCPUAttached[aCpu] = true;
     
    44494475    if (FAILED(rc)) return rc;
    44504476
     4477    setModified(IsModified_MachineData);
    44514478    mHWData.backup();
    44524479    mHWData->mCPUAttached[aCpu] = false;
     
    44894516// public methods for internal purposes
    44904517/////////////////////////////////////////////////////////////////////////////
     4518
     4519/**
     4520 * Adds the given IsModified_* flag to the dirty flags of the machine.
     4521 * This must be called either during loadSettings or under the machine write lock.
     4522 * @param fl
     4523 */
     4524void Machine::setModified(uint32_t fl)
     4525{
     4526    m_flModifications |= fl;
     4527}
    44914528
    44924529/**
     
    54395476    HRESULT rc = S_OK;
    54405477
    5441     /* Ensure the settings are saved. If we are going to be registered and
    5442      * isConfigLocked() is FALSE then it means that no config file exists yet,
    5443      * so create it by calling saveSettings() too. */
    5444     if (    isModified()
     5478    // Ensure the settings are saved. If we are going to be registered and
     5479    // no config file exists yet, create it by calling saveSettings() too.
     5480    if (    (m_flModifications)
    54455481         || (argNewRegistered && !mData->m_pMachineConfigFile->fileExists())
    54465482       )
     
    60896125            mData->mMachineState = MachineState_Saved;
    60906126        }
     6127
     6128        // after loading settings, we are no longer different from the XML on disk
     6129        m_flModifications = 0;
    60916130    }
    60926131    catch (HRESULT err)
     
    66596698        /* back up mMediaData to let registeredInit() properly rollback on failure
    66606699         * (= limited accessibility) */
     6700        setModified(IsModified_Storage);
    66616701        mMediaData.backup();
    66626702        mMediaData->mAttachments.push_back(pAttachment);
     
    71457185            // now spit it all out!
    71467186            mData->m_pMachineConfigFile->write(mData->m_strConfigFileFull);
     7187
     7188        // after saving settings, we are no longer different from the XML on disk
     7189        m_flModifications = 0;
    71477190    }
    71487191    catch (HRESULT err)
     
    82168259
    82178260/**
    8218  *  @note Locks objects for reading!
    8219  */
    8220 bool Machine::isModified()
    8221 {
    8222     AutoCaller autoCaller(this);
    8223     AssertComRCReturn (autoCaller.rc(), false);
    8224 
    8225     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    8226 
    8227     for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot ++)
    8228         if (mNetworkAdapters [slot] && mNetworkAdapters [slot]->isModified())
    8229             return true;
    8230 
    8231     for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot ++)
    8232         if (mSerialPorts [slot] && mSerialPorts [slot]->isModified())
    8233             return true;
    8234 
    8235     for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot ++)
    8236         if (mParallelPorts [slot] && mParallelPorts [slot]->isModified())
    8237             return true;
    8238 
    8239     if (!mStorageControllers.isNull())
    8240     {
    8241         for (StorageControllerList::const_iterator it =
    8242                     mStorageControllers->begin();
    8243                 it != mStorageControllers->end();
    8244                 ++it)
    8245         {
    8246             if ((*it)->isModified())
    8247                 return true;
    8248         }
    8249     }
    8250 
    8251     return
    8252         mUserData.isBackedUp() ||
    8253         mHWData.isBackedUp() ||
    8254         mMediaData.isBackedUp() ||
    8255         mStorageControllers.isBackedUp() ||
    8256 #ifdef VBOX_WITH_VRDP
    8257         (mVRDPServer && mVRDPServer->isModified()) ||
    8258 #endif
    8259         (mAudioAdapter && mAudioAdapter->isModified()) ||
    8260         (mUSBController && mUSBController->isModified()) ||
    8261         (mBIOSSettings && mBIOSSettings->isModified());
    8262 }
    8263 
    8264 /**
    82658261 * Discards all changes to machine settings.
    82668262 *
     
    82758271
    82768272    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    8277 
    8278     /* check for changes in own data */
    8279 
    8280     bool sharedFoldersChanged = false, storageChanged = false;
    8281 
    8282     if (aNotify && mHWData.isBackedUp())
    8283     {
    8284         if (mHWData->mSharedFolders.size() != mHWData.backedUpData()->mSharedFolders.size())
    8285             sharedFoldersChanged = true;
    8286         else
    8287         {
    8288             for (HWData::SharedFolderList::iterator rit = mHWData->mSharedFolders.begin();
    8289                  rit != mHWData->mSharedFolders.end() && !sharedFoldersChanged;
    8290                  ++rit)
    8291             {
    8292                 for (HWData::SharedFolderList::iterator cit = mHWData.backedUpData()->mSharedFolders.begin();
    8293                      cit != mHWData.backedUpData()->mSharedFolders.end();
    8294                      ++cit)
    8295                 {
    8296                     if (    (*cit)->getName() != (*rit)->getName()
    8297                          || (*cit)->getHostPath() != (*rit)->getHostPath()
    8298                        )
    8299                     {
    8300                         sharedFoldersChanged = true;
    8301                         break;
    8302                     }
    8303                 }
    8304             }
    8305         }
    8306     }
    83078273
    83088274    if (!mStorageControllers.isNull())
     
    83298295
    83308296        /* rollback any changes to devices after restoring the list */
    8331         StorageControllerList::const_iterator it = mStorageControllers->begin();
    8332         while (it != mStorageControllers->end())
    8333         {
    8334             if ((*it)->isModified())
     8297        if (m_flModifications & IsModified_Storage)
     8298        {
     8299            StorageControllerList::const_iterator it = mStorageControllers->begin();
     8300            while (it != mStorageControllers->end())
     8301            {
    83358302                (*it)->rollback();
    8336 
    8337             ++it;
     8303                ++it;
     8304            }
    83388305        }
    83398306    }
     
    83438310    mHWData.rollback();
    83448311
    8345     if (mMediaData.isBackedUp())
     8312    if (m_flModifications & IsModified_Storage)
    83468313        rollbackMedia();
    83478314
    8348     /* check for changes in child objects */
    8349     bool vrdpChanged = false, usbChanged = false;
     8315    if (mBIOSSettings)
     8316        mBIOSSettings->rollback();
     8317
     8318#ifdef VBOX_WITH_VRDP
     8319    if (mVRDPServer && (m_flModifications & IsModified_VRDPServer))
     8320        mVRDPServer->rollback();
     8321#endif
     8322
     8323    if (mAudioAdapter)
     8324        mAudioAdapter->rollback();
     8325
     8326    if (mUSBController && (m_flModifications & IsModified_USB))
     8327        mUSBController->rollback();
    83508328
    83518329    ComPtr<INetworkAdapter> networkAdapters[RT_ELEMENTS(mNetworkAdapters)];
     
    83538331    ComPtr<IParallelPort> parallelPorts[RT_ELEMENTS(mParallelPorts)];
    83548332
    8355     if (mBIOSSettings)
    8356         mBIOSSettings->rollback();
    8357 
    8358 #ifdef VBOX_WITH_VRDP
    8359     if (mVRDPServer)
    8360         vrdpChanged = mVRDPServer->rollback();
    8361 #endif
    8362 
    8363     if (mAudioAdapter)
    8364         mAudioAdapter->rollback();
    8365 
    8366     if (mUSBController)
    8367         usbChanged = mUSBController->rollback();
    8368 
    8369     for (ULONG slot = 0; slot < RT_ELEMENTS(mNetworkAdapters); slot++)
    8370         if (mNetworkAdapters[slot])
    8371             if (mNetworkAdapters[slot]->rollback())
    8372                 networkAdapters[slot] = mNetworkAdapters[slot];
    8373 
    8374     for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++)
    8375         if (mSerialPorts[slot])
    8376             if (mSerialPorts[slot]->rollback())
    8377                 serialPorts[slot] = mSerialPorts[slot];
    8378 
    8379     for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); slot++)
    8380         if (mParallelPorts[slot])
    8381             if (mParallelPorts[slot]->rollback())
    8382                 parallelPorts[slot] = mParallelPorts[slot];
     8333    if (m_flModifications & IsModified_NetworkAdapters)
     8334        for (ULONG slot = 0; slot < RT_ELEMENTS(mNetworkAdapters); slot++)
     8335            if (mNetworkAdapters[slot])
     8336                if (mNetworkAdapters[slot]->rollback())
     8337                    networkAdapters[slot] = mNetworkAdapters[slot];
     8338
     8339    if (m_flModifications & IsModified_SerialPorts)
     8340        for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++)
     8341            if (mSerialPorts[slot])
     8342                if (mSerialPorts[slot]->rollback())
     8343                    serialPorts[slot] = mSerialPorts[slot];
     8344
     8345    if (m_flModifications & IsModified_ParallelPorts)
     8346        for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); slot++)
     8347            if (mParallelPorts[slot])
     8348                if (mParallelPorts[slot]->rollback())
     8349                    parallelPorts[slot] = mParallelPorts[slot];
    83838350
    83848351    if (aNotify)
     
    83878354
    83888355        ComObjPtr<Machine> that = this;
     8356        uint32_t flModifications = m_flModifications;
    83898357        alock.leave();
    83908358
    8391         if (sharedFoldersChanged)
     8359        if (flModifications & IsModified_SharedFolders)
    83928360            that->onSharedFolderChange();
    83938361
    8394         if (vrdpChanged)
     8362        if (flModifications & IsModified_VRDPServer)
    83958363            that->onVRDPServerChange();
    8396         if (usbChanged)
     8364        if (flModifications & IsModified_USB)
    83978365            that->onUSBControllerChange();
    83988366
     
    84078375                that->onParallelPortChange(parallelPorts[slot]);
    84088376
    8409         if (storageChanged)
     8377        if (flModifications & IsModified_Storage)
    84108378            that->onStorageControllerChange();
    84118379    }
     
    85938561
    85948562    for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot ++)
    8595         mNetworkAdapters [slot]->copyFrom (aThat->mNetworkAdapters [slot]);
     8563        mNetworkAdapters[slot]->copyFrom (aThat->mNetworkAdapters [slot]);
    85968564    for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot ++)
    8597         mSerialPorts [slot]->copyFrom (aThat->mSerialPorts [slot]);
     8565        mSerialPorts[slot]->copyFrom (aThat->mSerialPorts [slot]);
    85988566    for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot ++)
    8599         mParallelPorts [slot]->copyFrom (aThat->mParallelPorts [slot]);
     8567        mParallelPorts[slot]->copyFrom (aThat->mParallelPorts [slot]);
    86008568}
    86018569
     
    89198887    /* We need to lock this object in uninit() because the lock is shared
    89208888     * with mPeer (as well as data we modify below). mParent->addProcessToReap()
    8921      * and others need mParent lock. */
    8922     AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
     8889     * and others need mParent lock, and USB needs host lock. */
     8890    AutoMultiWriteLock3 alock(mParent, mParent->host(), this COMMA_LOCKVAL_SRC_POS);
    89238891
    89248892#ifdef VBOX_WITH_RESOURCE_USAGE_API
    8925     unregisterMetrics (mParent->performanceCollector(), mPeer);
     8893    unregisterMetrics(mParent->performanceCollector(), mPeer);
    89268894#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    89278895
     
    89368904        /* reset the state to Aborted */
    89378905        if (mData->mMachineState != MachineState_Aborted)
    8938             setMachineState (MachineState_Aborted);
    8939     }
    8940 
    8941     if (isModified())
     8906            setMachineState(MachineState_Aborted);
     8907    }
     8908
     8909    // any machine settings modified?
     8910    if (m_flModifications)
    89428911    {
    89438912        LogWarningThisFunc(("Discarding unsaved settings changes!\n"));
     
    95939562
    95949563    DiscardSettings();
     9564    setModified(IsModified_MachineData);
    95959565    mHWData.backup();
    95969566
     
    96729642        }
    96739643
     9644        setModified(IsModified_MachineData);
    96749645        mHWData.backup();
    96759646
     
    98699840
    98709841    AutoCaller autoCaller(this);
    9871     AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
     9842    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    98729843
    98739844    ComPtr<IInternalSessionControl> directControl;
     
    98819852        return S_OK;
    98829853
    9883     return directControl->OnParallelPortChange (parallelPort);
     9854    return directControl->OnParallelPortChange(parallelPort);
    98849855}
    98859856
  • trunk/src/VBox/Main/MediumAttachmentImpl.cpp

    r25860 r26167  
    373373}
    374374
    375 /** Must be called from under this object's write lock. */
     375/** Must be called from under this object's AND the machine's write lock. */
    376376void MediumAttachment::updateMedium(const ComObjPtr<Medium> &aMedium, bool aImplicit)
    377377{
     378    Assert(m->pMachine->isWriteLockOnCurrentThread());
     379    Assert(isWriteLockOnCurrentThread());
     380
    378381    m->bd.backup();
    379382    m->bd->pMedium = aMedium;
    380383    m->bd->fImplicit = aImplicit;
    381 }
    382 
    383 /** Must be called from under this object's write lock. */
     384
     385    m->pMachine->setModified(Machine::IsModified_Storage);
     386}
     387
     388/** Must be called from under this object's AND the machine's write lock. */
    384389void MediumAttachment::updatePassthrough(bool aPassthrough)
    385390{
     391    Assert(m->pMachine->isWriteLockOnCurrentThread());
     392    Assert(isWriteLockOnCurrentThread());
     393
    386394    m->bd.backup();
    387395    m->bd->fPassthrough = aPassthrough;
    388 }
    389 
     396
     397    m->pMachine->setModified(Machine::IsModified_Storage);
     398}
     399
  • trunk/src/VBox/Main/NetworkAdapterImpl.cpp

    r26046 r26167  
    4646void NetworkAdapter::FinalRelease()
    4747{
    48     uninit ();
     48    uninit();
    4949}
    5050
     
    5757 *  @param aParent  Handle of the parent object.
    5858 */
    59 HRESULT NetworkAdapter::init (Machine *aParent, ULONG aSlot)
     59HRESULT NetworkAdapter::init(Machine *aParent, ULONG aSlot)
    6060{
    6161    LogFlowThisFunc(("aParent=%p, aSlot=%d\n", aParent, aSlot));
     
    7070    unconst(mParent) = aParent;
    7171    /* mPeer is left null */
     72
     73    m_fModified = false;
    7274
    7375    mData.allocate();
     
    100102 *  @note Locks @a aThat object for reading.
    101103 */
    102 HRESULT NetworkAdapter::init (Machine *aParent, NetworkAdapter *aThat)
     104HRESULT NetworkAdapter::init(Machine *aParent, NetworkAdapter *aThat)
    103105{
    104106    LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
     
    132134 *  @note Locks @a aThat object for reading.
    133135 */
    134 HRESULT NetworkAdapter::initCopy (Machine *aParent, NetworkAdapter *aThat)
     136HRESULT NetworkAdapter::initCopy(Machine *aParent, NetworkAdapter *aThat)
    135137{
    136138    LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
     
    229231        mData->mAdapterType = aAdapterType;
    230232
    231         /* leave the lock before informing callbacks */
    232         alock.release();
     233        m_fModified = true;
     234        // leave the lock before informing callbacks
     235        alock.release();
     236
     237        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     238        mParent->setModified(Machine::IsModified_NetworkAdapters);
     239        mlock.release();
    233240
    234241        mParent->onNetworkAdapterChange (this, FALSE);
     
    282289        mData->mEnabled = aEnabled;
    283290
    284         /* leave the lock before informing callbacks */
    285         alock.release();
     291        m_fModified = true;
     292        // leave the lock before informing callbacks
     293        alock.release();
     294
     295        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     296        mParent->setModified(Machine::IsModified_NetworkAdapters);
     297        mlock.release();
    286298
    287299        mParent->onNetworkAdapterChange (this, FALSE);
     
    315327    AutoMutableStateDependency adep(mParent);
    316328    if (FAILED(adep.rc())) return adep.rc();
    317 
    318     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    319329
    320330    HRESULT rc = S_OK;
     
    326336    if (!aMACAddress || !*aMACAddress)
    327337    {
     338        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    328339        mData.backup();
    329340
    330341        generateMACAddress();
    331342        emitChangeEvent = true;
     343
     344        m_fModified = true;
     345        // leave the lock before informing callbacks
     346        alock.release();
     347
     348        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     349        mParent->setModified(Machine::IsModified_NetworkAdapters);
     350        mlock.release();
    332351    }
    333352    else
    334353    {
     354        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    335355        if (mData->mMACAddress != aMACAddress)
    336356        {
     
    371391
    372392                mData->mMACAddress = macAddressUtf;
     393
    373394                emitChangeEvent = true;
     395
     396                m_fModified = true;
     397                // leave the lock before informing callbacks
     398                alock.release();
     399
     400                AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     401                mParent->setModified(Machine::IsModified_NetworkAdapters);
     402                mlock.release();
    374403            }
    375404        }
    376405    }
    377406
     407    // we have left the lock in any case at this point
     408
    378409    if (emitChangeEvent)
    379     {
    380         /* leave the lock before informing callbacks */
    381         alock.release();
    382 
    383410        mParent->onNetworkAdapterChange (this, FALSE);
    384     }
    385411
    386412    return rc;
     
    436462        mData->mHostInterface = aHostInterface;
    437463
    438         /* leave the lock before informing callbacks */
    439         alock.release();
    440 
    441         mParent->onNetworkAdapterChange (this, FALSE);
     464        m_fModified = true;
     465        // leave the lock before informing callbacks
     466        alock.release();
     467
     468        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     469        mParent->setModified(Machine::IsModified_NetworkAdapters);
     470        mlock.release();
     471
     472        mParent->onNetworkAdapterChange(this, FALSE);
    442473    }
    443474
     
    484515        mData->mInternalNetwork = aInternalNetwork;
    485516
    486         /* leave the lock before informing callbacks */
    487         alock.release();
    488 
    489         mParent->onNetworkAdapterChange (this, FALSE);
     517        m_fModified = true;
     518        // leave the lock before informing callbacks
     519        alock.release();
     520
     521        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     522        mParent->setModified(Machine::IsModified_NetworkAdapters);
     523        mlock.release();
     524
     525        mParent->onNetworkAdapterChange(this, FALSE);
    490526    }
    491527
     
    527563        mData->mNATNetwork = aNATNetwork;
    528564
    529         /* leave the lock before informing callbacks */
    530         alock.release();
    531 
    532         mParent->onNetworkAdapterChange (this, FALSE);
     565        m_fModified = true;
     566        // leave the lock before informing callbacks
     567        alock.release();
     568
     569        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     570        mParent->setModified(Machine::IsModified_NetworkAdapters);
     571        mlock.release();
     572
     573        mParent->onNetworkAdapterChange(this, FALSE);
    533574    }
    534575
     
    566607        mData->mCableConnected = aConnected;
    567608
    568         /* leave the lock before informing callbacks */
    569         alock.release();
    570 
    571         mParent->onNetworkAdapterChange (this, FALSE);
     609        m_fModified = true;
     610        // leave the lock before informing callbacks
     611        alock.release();
     612
     613        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     614        mParent->setModified(Machine::IsModified_NetworkAdapters);
     615        mlock.release();
     616
     617        mParent->onNetworkAdapterChange(this, FALSE);
    572618    }
    573619
     
    605651        mData->mLineSpeed = aSpeed;
    606652
    607         /* leave the lock before informing callbacks */
    608         alock.release();
    609 
    610         mParent->onNetworkAdapterChange (this, FALSE);
     653        m_fModified = true;
     654        // leave the lock before informing callbacks
     655        alock.release();
     656
     657        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     658        mParent->setModified(Machine::IsModified_NetworkAdapters);
     659        mlock.release();
     660
     661        mParent->onNetworkAdapterChange(this, FALSE);
    611662    }
    612663
     
    643694        mData->mTraceEnabled = aEnabled;
    644695
    645         /* leave the lock before informing callbacks */
    646         alock.release();
    647 
    648         mParent->onNetworkAdapterChange (this, TRUE);
     696        m_fModified = true;
     697        // leave the lock before informing callbacks
     698        alock.release();
     699
     700        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     701        mParent->setModified(Machine::IsModified_NetworkAdapters);
     702        mlock.release();
     703
     704        mParent->onNetworkAdapterChange(this, TRUE);
    649705    }
    650706
     
    682738        mData->mTraceFile = aTraceFile;
    683739
    684         /* leave the lock before informing callbacks */
    685         alock.release();
    686 
    687         mParent->onNetworkAdapterChange (this, FALSE);
     740        m_fModified = true;
     741        // leave the lock before informing callbacks
     742        alock.release();
     743
     744        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     745        mParent->setModified(Machine::IsModified_NetworkAdapters);
     746        mlock.release();
     747
     748        mParent->onNetworkAdapterChange(this, FALSE);
    688749    }
    689750
     
    715776        mData->mAttachmentType = NetworkAttachmentType_NAT;
    716777
    717         /* leave the lock before informing callbacks */
    718         alock.release();
     778        m_fModified = true;
     779        // leave the lock before informing callbacks
     780        alock.release();
     781
     782        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     783        mParent->setModified(Machine::IsModified_NetworkAdapters);
     784        mlock.release();
    719785
    720786        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     
    757823        mData->mAttachmentType = NetworkAttachmentType_Bridged;
    758824
    759         /* leave the lock before informing callbacks */
    760         alock.release();
     825        m_fModified = true;
     826        // leave the lock before informing callbacks
     827        alock.release();
     828
     829        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     830        mParent->setModified(Machine::IsModified_NetworkAdapters);
     831        mlock.release();
    761832
    762833        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     
    807878        mData->mAttachmentType = NetworkAttachmentType_Internal;
    808879
    809         /* leave the lock before informing callbacks */
    810         alock.release();
     880        m_fModified = true;
     881        // leave the lock before informing callbacks
     882        alock.release();
     883
     884        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     885        mParent->setModified(Machine::IsModified_NetworkAdapters);
     886        mlock.release();
    811887
    812888        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     
    849925        mData->mAttachmentType = NetworkAttachmentType_HostOnly;
    850926
    851         /* leave the lock before informing callbacks */
    852         alock.release();
     927        m_fModified = true;
     928        // leave the lock before informing callbacks
     929        alock.release();
     930
     931        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     932        mParent->setModified(Machine::IsModified_NetworkAdapters);
     933        mlock.release();
    853934
    854935        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     
    885966        detach();
    886967
    887         /* leave the lock before informing callbacks */
    888         alock.release();
     968        m_fModified = true;
     969        // leave the lock before informing callbacks
     970        alock.release();
     971
     972        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     973        mParent->setModified(Machine::IsModified_NetworkAdapters);
     974        mlock.release();
    889975
    890976        mParent->onNetworkAdapterChange (this, TRUE);
     
    9761062    }
    9771063
     1064    // after loading settings, we are no longer different from the XML on disk
     1065    m_fModified = false;
     1066
    9781067    return S_OK;
    9791068}
     
    10291118        break;
    10301119    }
     1120
     1121    // after saving settings, we are no longer different from the XML on disk
     1122    m_fModified = false;
    10311123
    10321124    return S_OK;
  • trunk/src/VBox/Main/ParallelPortImpl.cpp

    r26156 r26167  
    4242{
    4343    Data()
     44        : fModified(false)
    4445    { }
     46
     47    bool                                    fModified;
    4548
    4649    const ComObjPtr<Machine, ComWeakRef>    pMachine;
     
    232235        m->bd->fEnabled = aEnabled;
    233236
    234         /* leave the lock before informing callbacks */
     237        m->fModified = true;
     238        // leave the lock before informing callbacks
    235239        alock.release();
    236240
    237         m->pMachine->onParallelPortChange (this);
     241        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     242        m->pMachine->setModified(Machine::IsModified_ParallelPorts);
     243        mlock.release();
     244
     245        m->pMachine->onParallelPortChange(this);
    238246    }
    239247
     
    288296    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    289297
    290     HRESULT rc = S_OK;
    291     bool emitChangeEvent = false;
    292 
    293298    if (m->bd->ulIRQ != aIRQ)
    294299    {
    295300        m->bd.backup();
    296301        m->bd->ulIRQ = aIRQ;
    297         emitChangeEvent = true;
     302
     303        m->fModified = true;
     304        // leave the lock before informing callbacks
     305        alock.release();
     306
     307        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     308        m->pMachine->setModified(Machine::IsModified_ParallelPorts);
     309        mlock.release();
     310
     311        m->pMachine->onParallelPortChange(this);
    298312    }
    299313
    300     if (emitChangeEvent)
    301     {
    302         /* leave the lock before informing callbacks */
    303         alock.release();
    304 
    305         m->pMachine->onParallelPortChange (this);
    306     }
    307 
    308     return rc;
     314    return S_OK;
    309315}
    310316
     
    342348    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    343349
    344     HRESULT rc = S_OK;
    345     bool emitChangeEvent = false;
    346 
    347350    if (m->bd->ulIOBase != aIOBase)
    348351    {
    349352        m->bd.backup();
    350353        m->bd->ulIOBase = aIOBase;
    351         emitChangeEvent = true;
     354
     355        m->fModified = true;
     356        // leave the lock before informing callbacks
     357        alock.release();
     358
     359        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     360        m->pMachine->setModified(Machine::IsModified_ParallelPorts);
     361        mlock.release();
     362
     363        m->pMachine->onParallelPortChange(this);
    352364    }
    353365
    354     if (emitChangeEvent)
    355     {
    356         /* leave the lock before informing callbacks */
    357         alock.release();
    358 
    359         m->pMachine->onParallelPortChange (this);
    360     }
    361 
    362     return rc;
     366    return S_OK;
    363367}
    364368
     
    397401        m->bd->strPath = str;
    398402
    399         /* leave the lock before informing callbacks */
     403        m->fModified = true;
     404        // leave the lock before informing callbacks
    400405        alock.release();
     406
     407        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     408        m->pMachine->setModified(Machine::IsModified_ParallelPorts);
     409        mlock.release();
    401410
    402411        return m->pMachine->onParallelPortChange(this);
     
    450459
    451460    return S_OK;
    452 }
    453 
    454 bool ParallelPort::isModified()
    455 {
    456     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    457     return m->bd.isBackedUp();
    458461}
    459462
  • trunk/src/VBox/Main/SerialPortImpl.cpp

    r26156 r26167  
    4343{
    4444    Data()
     45        : fModified(false)
    4546    { }
     47
     48    bool                                    fModified;
    4649
    4750    const ComObjPtr<Machine, ComWeakRef>    pMachine;
     
    228231        m->bd->fEnabled = aEnabled;
    229232
    230         /* leave the lock before informing callbacks */
     233        m->fModified = true;
     234        // leave the lock before informing callbacks
    231235        alock.release();
    232236
    233         m->pMachine->onSerialPortChange (this);
     237        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     238        m->pMachine->setModified(Machine::IsModified_SerialPorts);
     239        mlock.release();
     240
     241        m->pMachine->onSerialPortChange(this);
    234242    }
    235243
     
    261269
    262270    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    263 
    264     HRESULT rc = S_OK;
    265     bool emitChangeEvent = false;
    266271
    267272    if (m->bd->portMode != aHostMode)
     
    271276            case PortMode_RawFile:
    272277                if (m->bd->strPath.isEmpty())
    273                     return setError (E_INVALIDARG,
    274                         tr ("Cannot set the raw file mode of the serial port %d "
    275                             "because the file path is empty or null"),
    276                         m->bd->ulSlot);
     278                    return setError(E_INVALIDARG,
     279                                    tr("Cannot set the raw file mode of the serial port %d "
     280                                       "because the file path is empty or null"),
     281                                    m->bd->ulSlot);
    277282                break;
    278283            case PortMode_HostPipe:
    279284                if (m->bd->strPath.isEmpty())
    280                     return setError (E_INVALIDARG,
    281                         tr ("Cannot set the host pipe mode of the serial port %d "
    282                             "because the pipe path is empty or null"),
    283                         m->bd->ulSlot);
     285                    return setError(E_INVALIDARG,
     286                                    tr("Cannot set the host pipe mode of the serial port %d "
     287                                       "because the pipe path is empty or null"),
     288                                    m->bd->ulSlot);
    284289                break;
    285290            case PortMode_HostDevice:
    286291                if (m->bd->strPath.isEmpty())
    287                     return setError (E_INVALIDARG,
    288                         tr ("Cannot set the host device mode of the serial port %d "
    289                             "because the device path is empty or null"),
    290                         m->bd->ulSlot);
     292                    return setError(E_INVALIDARG,
     293                                    tr("Cannot set the host device mode of the serial port %d "
     294                                       "because the device path is empty or null"),
     295                                    m->bd->ulSlot);
    291296                break;
    292297            case PortMode_Disconnected:
     
    297302        m->bd->portMode = aHostMode;
    298303
    299         emitChangeEvent = true;
    300     }
    301 
    302     if (emitChangeEvent)
    303     {
    304         /* leave the lock before informing callbacks */
     304        m->fModified = true;
     305        // leave the lock before informing callbacks
    305306        alock.release();
    306307
    307         m->pMachine->onSerialPortChange (this);
    308     }
    309 
    310     return rc;
     308        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     309        m->pMachine->setModified(Machine::IsModified_SerialPorts);
     310        mlock.release();
     311
     312        m->pMachine->onSerialPortChange(this);
     313    }
     314
     315    return S_OK;
    311316}
    312317
     
    358363    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    359364
    360     HRESULT rc = S_OK;
    361     bool emitChangeEvent = false;
    362 
    363365    if (m->bd->ulIRQ != aIRQ)
    364366    {
    365367        m->bd.backup();
    366368        m->bd->ulIRQ = aIRQ;
    367         emitChangeEvent = true;
    368     }
    369 
    370     if (emitChangeEvent)
    371     {
    372         /* leave the lock before informing callbacks */
     369
     370        m->fModified = true;
     371        // leave the lock before informing callbacks
    373372        alock.release();
    374373
    375         m->pMachine->onSerialPortChange (this);
    376     }
    377 
    378     return rc;
     374        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     375        m->pMachine->setModified(Machine::IsModified_SerialPorts);
     376        mlock.release();
     377
     378        m->pMachine->onSerialPortChange(this);
     379    }
     380
     381    return S_OK;
    379382}
    380383
     
    413416
    414417    HRESULT rc = S_OK;
    415     bool emitChangeEvent = false;
    416418
    417419    if (m->bd->ulIOBase != aIOBase)
     
    419421        m->bd.backup();
    420422        m->bd->ulIOBase = aIOBase;
    421         emitChangeEvent = true;
    422     }
    423 
    424     if (emitChangeEvent)
    425     {
    426         /* leave the lock before informing callbacks */
     423
     424        m->fModified = true;
     425        // leave the lock before informing callbacks
    427426        alock.release();
    428427
    429         m->pMachine->onSerialPortChange (this);
     428        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     429        m->pMachine->setModified(Machine::IsModified_SerialPorts);
     430        mlock.release();
     431
     432        m->pMachine->onSerialPortChange(this);
    430433    }
    431434
     
    471474        m->bd->strPath = str;
    472475
    473         /* leave the lock before informing callbacks */
     476        m->fModified = true;
     477        // leave the lock before informing callbacks
    474478        alock.release();
    475479
    476         return m->pMachine->onSerialPortChange(this);
     480        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     481        m->pMachine->setModified(Machine::IsModified_SerialPorts);
     482        mlock.release();
     483
     484        m->pMachine->onSerialPortChange(this);
    477485    }
    478486
     
    510518        m->bd->fServer = aServer;
    511519
    512         /* leave the lock before informing callbacks */
     520        m->fModified = true;
     521        // leave the lock before informing callbacks
    513522        alock.release();
    514523
    515         m->pMachine->onSerialPortChange (this);
     524        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     525        m->pMachine->setModified(Machine::IsModified_SerialPorts);
     526        mlock.release();
     527
     528        m->pMachine->onSerialPortChange(this);
    516529    }
    517530
     
    563576
    564577    return S_OK;
    565 }
    566 
    567 bool SerialPort::isModified()
    568 {
    569     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    570     return m->bd.isBackedUp();
    571578}
    572579
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r26088 r26167  
    13191319        // backup the media data so we can recover if things goes wrong along the day;
    13201320        // the matching commit() is in fixupMedia() during endSnapshot()
     1321        setModified(IsModified_Storage);
    13211322        mMediaData.backup();
    13221323
     
    16691670     * the machine is powered off, so there is no need to inform the direct
    16701671     * session) */
    1671     if (isModified())
     1672    if (m_flModifications)
    16721673        rollback(false /* aNotify */);
    16731674
     
    17071708            LogFlowThisFunc(("Restoring hard disks from the snapshot...\n"));
    17081709
    1709             /* restore the attachments from the snapshot */
     1710            // restore the attachments from the snapshot
     1711            setModified(IsModified_Storage);
    17101712            mMediaData.backup();
    17111713            mMediaData->mAttachments = pSnapshotMachine->mMediaData->mAttachments;
     
    19771979    if (pSnapshot == mData->mCurrentSnapshot)
    19781980    {
    1979         if (isModified())
     1981        if (m_flModifications)
    19801982        {
    19811983            rc = saveSettings();
  • trunk/src/VBox/Main/StorageControllerImpl.cpp

    r26156 r26167  
    577577        m->bd->mPortCount = aPortCount;
    578578
    579         /* leave the lock for safety */
    580         alock.leave();
    581 
    582         m->pParent->onStorageControllerChange ();
     579        alock.release();
     580        AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);        // m->pParent is const, needs no locking
     581        m->pParent->setModified(Machine::IsModified_Storage);
     582        mlock.release();
     583
     584        m->pParent->onStorageControllerChange();
    583585    }
    584586
     
    713715{
    714716    return m->bd->mInstance;
    715 }
    716 
    717 bool StorageController::isModified()
    718 {
    719     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    720     return m->bd.isBackedUp();
    721717}
    722718
  • trunk/src/VBox/Main/USBControllerImpl.cpp

    r26156 r26167  
    299299        m->bd->fEnabled = aEnabled;
    300300
    301         /* leave the lock for safety */
    302         alock.leave();
     301        // leave the lock for safety
     302        alock.release();
     303
     304        AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
     305        m->pParent->setModified(Machine::IsModified_USB);
     306        mlock.release();
    303307
    304308        m->pParent->onUSBControllerChange();
     
    340344        m->bd->fEnabledEHCI = aEnabled;
    341345
    342         /* leave the lock for safety */
    343         alock.leave();
     346        // leave the lock for safety
     347        alock.release();
     348
     349        AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
     350        m->pParent->setModified(Machine::IsModified_USB);
     351        mlock.release();
    344352
    345353        m->pParent->onUSBControllerChange();
     
    470478}
    471479
    472 STDMETHODIMP USBController::InsertDeviceFilter (ULONG aPosition,
    473                                                 IUSBDeviceFilter *aFilter)
     480STDMETHODIMP USBController::InsertDeviceFilter(ULONG aPosition,
     481                                               IUSBDeviceFilter *aFilter)
    474482{
    475483#ifdef VBOX_WITH_USB
     
    495503
    496504    if (filter->mInList)
    497         return setError (VBOX_E_INVALID_OBJECT_STATE,
    498             tr ("The given USB device filter is already in the list"));
     505        return setError(VBOX_E_INVALID_OBJECT_STATE,
     506                        tr("The given USB device filter is already in the list"));
    499507
    500508    /* backup the list before modification */
     
    523531        filter->getId() = service->insertFilter (&filter->getData().mUSBFilter);
    524532    }
     533
     534    alock.release();
     535    AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
     536    m->pParent->setModified(Machine::IsModified_USB);
     537    mlock.release();
    525538
    526539    return S_OK;
     
    590603        filter->getId() = NULL;
    591604    }
     605
     606    alock.release();
     607    AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
     608    m->pParent->setModified(Machine::IsModified_USB);
     609    mlock.release();
    592610
    593611    return S_OK;
     
    706724
    707725    return S_OK;
    708 }
    709 
    710 /** @note Locks objects for reading! */
    711 bool USBController::isModified()
    712 {
    713     AutoCaller autoCaller(this);
    714     AssertComRCReturn (autoCaller.rc(), false);
    715 
    716     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    717 
    718     if (m->bd.isBackedUp()
    719 #ifdef VBOX_WITH_USB
    720         || m->llDeviceFilters.isBackedUp()
    721 #endif
    722         )
    723         return true;
    724 
    725 #ifdef VBOX_WITH_USB
    726     /* see whether any of filters has changed its data */
    727     for (DeviceFilterList::const_iterator
    728          it = m->llDeviceFilters->begin();
    729          it != m->llDeviceFilters->end();
    730          ++ it)
    731     {
    732         if ((*it)->isModified())
    733             return true;
    734     }
    735 #endif /* VBOX_WITH_USB */
    736 
    737     return false;
    738726}
    739727
  • trunk/src/VBox/Main/include/AudioAdapterImpl.h

    r26156 r26167  
    9292    HRESULT saveSettings(settings::AudioAdapter &data);
    9393
    94     bool isModified();
    9594    bool rollback();
    9695    void commit();
  • trunk/src/VBox/Main/include/BIOSSettingsImpl.h

    r26156 r26167  
    8484    HRESULT saveSettings(settings::BIOSSettings &data);
    8585
    86     bool isModified();
    8786    void rollback();
    8887    void commit();
  • trunk/src/VBox/Main/include/MachineImpl.h

    r26156 r26167  
    575575    const Bstr& getName() const { return mUserData->mName; }
    576576
     577    enum
     578    {
     579        IsModified_MachineData          = 0x0001,
     580        IsModified_Storage              = 0x0002,
     581        IsModified_NetworkAdapters      = 0x0008,
     582        IsModified_SerialPorts          = 0x0010,
     583        IsModified_ParallelPorts        = 0x0020,
     584        IsModified_VRDPServer           = 0x0040,
     585        IsModified_AudioAdapter         = 0x0080,
     586        IsModified_USB                  = 0x0100,
     587        IsModified_BIOS                 = 0x0200,
     588        IsModified_SharedFolders        = 0x0400
     589    };
     590
     591    void setModified(uint32_t fl);
     592
    577593    // callback handlers
    578594    virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
     
    745761    bool isInOwnDir(Utf8Str *aSettingsDir = NULL);
    746762
    747     bool isModified();
    748763    void rollback(bool aNotify);
    749764    void commit();
     
    759774    const ComObjPtr<VirtualBox, ComWeakRef> mParent;
    760775
    761     Shareable<Data> mData;
    762     Shareable<SSData> mSSData;
    763 
    764     Backupable<UserData> mUserData;
    765     Backupable<HWData> mHWData;
    766     Backupable<MediaData> mMediaData;
     776    uint32_t                m_flModifications;
     777
     778    Shareable<Data>         mData;
     779    Shareable<SSData>       mSSData;
     780
     781    Backupable<UserData>    mUserData;
     782    Backupable<HWData>      mHWData;
     783    Backupable<MediaData>   mMediaData;
    767784
    768785    // the following fields need special backup/rollback/commit handling,
  • trunk/src/VBox/Main/include/NetworkAdapterImpl.h

    r26156 r26167  
    139139    HRESULT saveSettings(settings::NetworkAdapter &data);
    140140
    141     bool isModified() { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); return mData.isBackedUp(); }
    142141    bool rollback();
    143142    void commit();
     
    156155    const ComObjPtr<NetworkAdapter> mPeer;
    157156
     157    bool m_fModified;
    158158    Backupable<Data> mData;
    159159};
  • trunk/src/VBox/Main/include/ParallelPortImpl.h

    r26156 r26167  
    7878    HRESULT saveSettings(settings::ParallelPort &data);
    7979
    80     bool isModified();
    8180    bool rollback();
    8281    void commit();
  • trunk/src/VBox/Main/include/SerialPortImpl.h

    r26156 r26167  
    8484    HRESULT saveSettings(settings::SerialPort &data);
    8585
    86     bool isModified();
    8786    bool rollback();
    8887    void commit();
  • trunk/src/VBox/Main/include/StorageControllerImpl.h

    r26156 r26167  
    8989    ULONG getInstance() const;
    9090
    91     bool isModified();
    9291    bool rollback();
    9392    void commit();
  • trunk/src/VBox/Main/include/USBControllerImpl.h

    r26156 r26167  
    8383    HRESULT saveSettings(settings::USBController &data);
    8484
    85     bool isModified();
    8685    bool rollback();
    8786    void commit();
  • trunk/src/VBox/Main/include/VRDPServerImpl.h

    r26156 r26167  
    111111    HRESULT saveSettings(settings::VRDPSettings &data);
    112112
    113     bool isModified() { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); return mData.isBackedUp(); }
    114113    bool rollback();
    115114    void commit();
Note: See TracChangeset for help on using the changeset viewer.

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