VirtualBox

Changeset 58002 in vbox


Ignore:
Timestamp:
Oct 2, 2015 10:21:51 AM (9 years ago)
Author:
vboxsync
Message:

Revert 103021 because it's needed to split one commit up on to 3 separate commits

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r57996 r58002  
    359359        src-all/SharedFolderImpl.cpp \
    360360        src-all/AutoCaller.cpp \
    361         src-all/ThreadTask.cpp \
    362361        src-all/VirtualBoxBase.cpp \
    363362        src-all/VirtualBoxErrorInfoImpl.cpp \
     
    738737        src-all/SharedFolderImpl.cpp \
    739738        src-all/AutoCaller.cpp \
    740         src-all/ThreadTask.cpp \
    741739        src-all/VirtualBoxBase.cpp \
    742740        src-all/VirtualBoxErrorInfoImpl.cpp \
     
    859857        src-all/Global.cpp \
    860858        src-all/AutoCaller.cpp \
    861         src-all/ThreadTask.cpp \
    862859        src-all/VirtualBoxBase.cpp \
    863860        src-all/VirtualBoxErrorInfoImpl.cpp \
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r57996 r58002  
    114114
    115115    struct ImportStack;
    116     class TaskOVF;
     116    struct TaskOVF;
    117117    struct Data;            // opaque, defined in ApplianceImpl.cpp
    118118    Data *m;
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r57996 r58002  
    2323#include "ovfreader.h"
    2424#include "SecretKeyStore.h"
    25 #include "ThreadTask.h"
    2625#include <map>
    2726#include <vector>
     
    123122};
    124123
    125 class Appliance::TaskOVF: public ThreadTask
    126 {
    127 public:
     124struct Appliance::TaskOVF
     125{
    128126    enum TaskType
    129127    {
     
    137135            LocationInfo aLocInfo,
    138136            ComObjPtr<Progress> &aProgress)
    139       : ThreadTask("TaskOVF"),
    140         pAppliance(aThat),
     137      : pAppliance(aThat),
    141138        taskType(aType),
    142139        locInfo(aLocInfo),
     
    144141        enFormat(ovf::OVFVersion_unknown),
    145142        rc(S_OK)
    146     {
    147         switch (taskType)
    148         {
    149             case TaskOVF::Read:     m_strTaskName = "ApplRead"; break;
    150             case TaskOVF::Import:   m_strTaskName = "ApplImp"; break;
    151             case TaskOVF::Write:    m_strTaskName = "ApplWrit"; break;
    152             default:                m_strTaskName = "ApplTask"; break;
    153         }
    154     }
     143    {}
    155144
    156145    static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
     146
     147    HRESULT startThread();
    157148
    158149    Appliance *pAppliance;
     
    164155
    165156    HRESULT rc;
    166 
    167     void handler()
    168     {
    169         int vrc = Appliance::i_taskThreadImportOrExport(NULL, this);
    170     }
    171157};
    172158
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r57996 r58002  
    563563    typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
    564564    typedef std::list <USBStorageDevice> USBStorageDeviceList;
    565 
    566     static DECLCALLBACK(int)    i_powerUpThread(RTTHREAD Thread, void *pvUser);
    567     static DECLCALLBACK(int)    i_powerDownThread(RTTHREAD Thread, void *pvUser);
    568565
    569566private:
     
    742739    void                        i_detachAllUSBDevices(bool aDone);
    743740
     741    static DECLCALLBACK(int)    i_powerUpThread(RTTHREAD Thread, void *pvUser);
     742    static DECLCALLBACK(int)    i_powerDownThread(RTTHREAD Thread, void *pvUser);
    744743
    745744    static DECLCALLBACK(int)    i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r57996 r58002  
    7373#include "AutoCaller.h"
    7474#include "Logging.h"
    75 #include "ThreadTask.h"
    7675
    7776#include <VBox/com/array.h>
     
    151150 * Console::addVMCaller() for more info.
    152151 */
    153 class VMTask: public ThreadTask
    154 {
    155 public:
     152struct VMTask
     153{
    156154    VMTask(Console *aConsole,
    157155           Progress *aProgress,
    158156           const ComPtr<IProgress> &aServerProgress,
    159157           bool aUsesVMPtr)
    160         : ThreadTask("GenericVMTask"),
    161           mConsole(aConsole),
     158        : mConsole(aConsole),
    162159          mConsoleCaller(aConsole),
    163160          mProgress(aProgress),
     
    178175    }
    179176
    180     virtual ~VMTask()
     177    ~VMTask()
    181178    {
    182179        releaseVMCaller();
     
    208205
    209206
    210 class VMPowerUpTask : public VMTask
    211 {
    212 public:
     207struct VMPowerUpTask : public VMTask
     208{
    213209    VMPowerUpTask(Console *aConsole,
    214210                  Progress *aProgress)
     
    219215          mTeleporterEnabled(FALSE),
    220216          mEnmFaultToleranceState(FaultToleranceState_Inactive)
    221     {
    222         m_strTaskName = "VMPwrUp";
    223     }
     217    {}
    224218
    225219    PFNCFGMCONSTRUCTOR mConfigConstructor;
     
    233227    typedef std::list<ComPtr<IProgress> > ProgressList;
    234228    ProgressList hardDiskProgresses;
    235 
    236     void handler()
    237     {
    238         int vrc = Console::i_powerUpThread(NULL, this);
    239     }
    240 
    241229};
    242230
    243 class VMPowerDownTask : public VMTask
    244 {
    245 public:
     231struct VMPowerDownTask : public VMTask
     232{
    246233    VMPowerDownTask(Console *aConsole,
    247234                    const ComPtr<IProgress> &aServerProgress)
    248235        : VMTask(aConsole, NULL /* aProgress */, aServerProgress,
    249236                 true /* aUsesVMPtr */)
    250     {
    251         m_strTaskName = "VMPwrDwn";
    252     }
    253 
    254     void handler()
    255     {
    256         int vrc = Console::i_powerDownThread(NULL, this);
    257     }
     237    {}
    258238};
    259239
     
    21562136        try
    21572137        {
     2138            /* Setup task object and thread to carry out the operation asynchronously.
     2139             * We are going to pass ownership of task pointer to another thread.
     2140             * So we are in charge of deletion this task pointer in case if RTThreadCreate
     2141             * returns not successful result or in case of any exception
     2142             */
     2143           
    21582144            task = new VMPowerDownTask(this, pProgress);
    2159             if (!task->isOk())
     2145            AssertBreakStmt(task->isOk(), rc = E_FAIL);
     2146            int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
     2147                                     (void *) task, 0,
     2148                                     RTTHREADTYPE_MAIN_WORKER, 0,
     2149                                     "VMPwrDwn");
     2150            if (RT_FAILURE(vrc))
    21602151            {
    2161                 throw E_FAIL;
     2152                rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
     2153                break;
    21622154            }
    2163         }
    2164         catch(...)
    2165         {
    2166             delete task;
    2167             rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n");
     2155            /* task is now owned by powerDownThread(), so release it */
     2156            //task.release();
     2157        }
     2158        catch(const std::exception &e)
     2159        {
     2160            rc = setError(E_FAIL, "Cought exception! Could not create VMPowerDown thread (%s)", e.what());
    21682161            break;
    21692162        }
    2170 
    2171         rc = task->createThread();
    21722163
    21732164        /* pass the progress to the caller */
     
    21782169    if (FAILED(rc))
    21792170    {
     2171        if (task != NULL)
     2172        {
     2173            //we can delete this pointer because something
     2174            //was wrong and we hadn't passed pointer to another thread
     2175            LogFlowFunc(("Delete task VMPowerDownTask from Console::powerDown()\n"));
     2176            delete task;
     2177        }
    21802178        /* preserve existing error info */
    21812179        ErrorInfoKeeper eik;
     
    69806978HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused)
    69816979{
     6980
    69826981    LogFlowThisFuncEnter();
    69836982
     
    69966995    LONG cOperations = 1;
    69976996    LONG ulTotalOperationsWeight = 1;
    6998     VMPowerUpTask* task = NULL;
    69996997
    70006998    try
     
    71127110        }
    71137111
     7112
    71147113        /* Setup task object and thread to carry out the operation
    71157114         * asynchronously */
    7116         try
    7117         {
    7118             task = new VMPowerUpTask(this, pPowerupProgress);
    7119             if (!task->isOk())
    7120             {
    7121                 throw E_FAIL;
    7122             }
    7123         }
    7124         catch(...)
    7125         {
    7126             delete task;
    7127             rc = setError(E_FAIL, "Could not create VMPowerUpTask object \n");
    7128             throw rc;
    7129         }
     7115        std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
     7116        ComAssertComRCRetRC(task->rc());
    71307117
    71317118        task->mConfigConstructor = i_configConstructor;
     
    73857372#endif // 0
    73867373
    7387        
    73887374        /* setup task object and thread to carry out the operation
    73897375         * asynchronously */
     
    73937379        }
    73947380
    7395         rc = task->createThread();
    7396 
    7397         if (FAILED(rc))
    7398             throw rc;
     7381        int vrc = RTThreadCreate(NULL, Console::i_powerUpThread,
     7382                                 (void *)task.get(), 0,
     7383                                 RTTHREADTYPE_MAIN_WORKER, 0, "VMPwrUp");
     7384        if (RT_FAILURE(vrc))
     7385            throw setError(E_FAIL, "Could not create VMPowerUp thread (%Rrc)", vrc);
     7386
     7387        /* task is now owned by powerUpThread(), so release it */
     7388        task.release();
    73997389
    74007390        /* finally, set the state: no right to fail in this method afterwards
     
    82638253                    if (!task->isOk())
    82648254                    {
    8265                         LogFlowFunc(("Console is already being uninitialized. \n"));
    8266                         throw E_FAIL;
     8255                        LogFlowFunc(("Console is already being uninitialized.\n"));
     8256                    }
     8257                    else
     8258                    {
     8259                        /*
     8260                         * We are going to pass ownership of task pointer to another thread.
     8261                         * So we are in charge of deletion this task pointer in case if RTThreadCreate
     8262                         * returns not successful result or in case of any exception
     8263                         */
     8264                        int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
     8265                                                 (void *) task, 0,
     8266                                                 RTTHREADTYPE_MAIN_WORKER, 0,
     8267                                                 "VMPwrDwn");
     8268                        if (RT_FAILURE(vrc))
     8269                        {
     8270                            rc = E_FAIL;
     8271                            LogFlowFunc(("Could not create VMPowerDown thread (%Rrc)\n", vrc));
     8272                        }
    82678273                    }
    82688274                }
    8269                 catch(...)
     8275                catch(const std::exception &e)
    82708276                {
     8277                    rc = E_FAIL;
     8278                    LogFlowFunc(("Cought exception! Could not create VMPowerDown thread (%s)\n", e.what()));
     8279                }
     8280
     8281                if(FAILED(rc) || !task->isOk())
     8282                {
     8283                    LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n"));
    82718284                    delete task;
    8272                     LogFlowFunc(("Problem with creating VMPowerDownTask object. \n"));
    82738285                }
    8274 
    8275                 rc = task->createThread();
    8276 
    8277                 if (FAILED(rc))
    8278                 {
    8279                     LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n"));
    8280                 }
    8281 
    82828286            }
    82838287            break;
     
    94379441    LogFlowFuncEnter();
    94389442
    9439     VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser);
    9440     AssertReturn(task, VERR_INVALID_PARAMETER);
     9443    std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser));
     9444    AssertReturn(task.get(), VERR_INVALID_PARAMETER);
    94419445
    94429446    AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER);
     
    1000310007    }
    1000410008
     10009    LogFlowFunc(("Delete task VMPowerDownTask from Console::i_powerDownThread()\n"));
     10010    delete task;
    1000510011    LogFlowFuncLeave();
    1000610012    return rc;
    1000710013}
     10014
    1000810015
    1000910016/**
  • trunk/src/VBox/Main/src-server/ApplianceImpl.cpp

    r57996 r58002  
    11851185
    11861186/**
     1187 * Starts the worker thread for the task.
     1188 *
     1189 * @return COM status code.
     1190 */
     1191HRESULT Appliance::TaskOVF::startThread()
     1192{
     1193    /* Pick a thread name suitable for logging (<= 8 chars). */
     1194    const char *pszTaskNm;
     1195    switch (taskType)
     1196    {
     1197        case TaskOVF::Read:     pszTaskNm = "ApplRead"; break;
     1198        case TaskOVF::Import:   pszTaskNm = "ApplImp"; break;
     1199        case TaskOVF::Write:    pszTaskNm = "ApplWrit"; break;
     1200        default:                pszTaskNm = "ApplTask"; break;
     1201    }
     1202
     1203    int vrc = RTThreadCreate(NULL, Appliance::i_taskThreadImportOrExport, this,
     1204                             0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, pszTaskNm);
     1205    if (RT_SUCCESS(vrc))
     1206        return S_OK;
     1207    return Appliance::i_setErrorStatic(E_FAIL, Utf8StrFmt("Could not create OVF task thread (%Rrc)\n", vrc));
     1208}
     1209
     1210/**
    11871211 * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl()
    11881212 * and Appliance::writeImpl().
     
    11961220DECLCALLBACK(int) Appliance::i_taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser)
    11971221{
    1198     TaskOVF* task = static_cast<TaskOVF*>(pvUser);
    1199     AssertReturn(task, VERR_GENERAL_FAILURE);
     1222    std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser));
     1223    AssertReturn(task.get(), VERR_GENERAL_FAILURE);
    12001224
    12011225    Appliance *pAppliance = task->pAppliance;
     
    12101234        case TaskOVF::Read:
    12111235            if (task->locInfo.storageType == VFSType_File)
    1212                 taskrc = pAppliance->i_readFS(task);
     1236                taskrc = pAppliance->i_readFS(task.get());
    12131237            else if (task->locInfo.storageType == VFSType_S3)
    12141238#ifdef VBOX_WITH_S3
    1215                 taskrc = pAppliance->i_readS3(task);
     1239                taskrc = pAppliance->i_readS3(task.get());
    12161240#else
    12171241                taskrc = VERR_NOT_IMPLEMENTED;
     
    12211245        case TaskOVF::Import:
    12221246            if (task->locInfo.storageType == VFSType_File)
    1223                 taskrc = pAppliance->i_importFS(task);
     1247                taskrc = pAppliance->i_importFS(task.get());
    12241248            else if (task->locInfo.storageType == VFSType_S3)
    12251249#ifdef VBOX_WITH_S3
    1226                 taskrc = pAppliance->i_importS3(task);
     1250                taskrc = pAppliance->i_importS3(task.get());
    12271251#else
    12281252                taskrc = VERR_NOT_IMPLEMENTED;
     
    12321256        case TaskOVF::Write:
    12331257            if (task->locInfo.storageType == VFSType_File)
    1234                 taskrc = pAppliance->i_writeFS(task);
     1258                taskrc = pAppliance->i_writeFS(task.get());
    12351259            else if (task->locInfo.storageType == VFSType_S3)
    12361260#ifdef VBOX_WITH_S3
    1237                 taskrc = pAppliance->i_writeS3(task);
     1261                taskrc = pAppliance->i_writeS3(task.get());
    12381262#else
    12391263                taskrc = VERR_NOT_IMPLEMENTED;
  • trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp

    r57997 r58002  
    2828#include "ApplianceImpl.h"
    2929#include "VirtualBoxImpl.h"
     30
    3031#include "ProgressImpl.h"
    3132#include "MachineImpl.h"
     
    753754
    754755        /* Initialize our worker task */
    755         TaskOVF* task = NULL;
    756         try
    757         {
    758             task = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress);
    759         }
    760         catch(...)
    761         {
    762             delete task;
    763             throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    764                                 tr("Could not create TaskOVF object for for writing out the OVF to disk"));
    765         }
    766 
     756        std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress));
    767757        /* The OVF version to write */
    768758        task->enFormat = aFormat;
    769759
    770         rc = task->createThread();
     760        rc = task->startThread();
    771761        if (FAILED(rc)) throw rc;
    772762
     763        /* Don't destruct on success */
     764        task.release();
    773765    }
    774766    catch (HRESULT aRC)
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r57996 r58002  
    874874
    875875    /* Initialize our worker task */
    876     TaskOVF* task = NULL;
    877     try
    878     {
    879         task = new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress);
    880     }
    881     catch(...)
    882     {
    883         delete task;
    884         throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    885                             tr("Could not create TaskOVF object for reading the OVF from disk"));
    886     }
    887 
    888     rc = task->createThread();
     876    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress));
     877
     878    rc = task->startThread();
    889879    if (FAILED(rc)) throw rc;
     880
     881    /* Don't destruct on success */
     882    task.release();
    890883
    891884    return rc;
     
    13781371
    13791372    /* Initialize our worker task */
    1380     TaskOVF* task = NULL;
    1381     try
    1382     {
    1383         task = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
    1384     }
    1385     catch(...)
    1386     {
    1387         delete task;
    1388         throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    1389                             tr("Could not create TaskOVF object for importing OVF data into VirtualBox"));
    1390     }
    1391 
    1392     rc = task->createThread();
     1373    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, locInfo, progress));
     1374
     1375    rc = task->startThread();
    13931376    if (FAILED(rc)) throw rc;
     1377
     1378    /* Don't destruct on success */
     1379    task.release();
    13941380
    13951381    return rc;
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