VirtualBox

Changeset 60448 in vbox


Ignore:
Timestamp:
Apr 12, 2016 10:26:56 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106535
Message:

bugref:7179. Removed auto_ptr from VFSExplorerImpl.cpp

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VFSExplorerImpl.h

    r59577 r60448  
    7070    //////////////////////////////////////////////////////////////////////////////////
    7171    //
    72     struct TaskVFSExplorer;  /* Worker thread helper */
     72    class TaskVFSExplorer;  /* Worker thread helper */
    7373    struct Data;
    7474    Data *m;
  • trunk/src/VBox/Main/src-server/VFSExplorerImpl.cpp

    r59577 r60448  
    3333#include "AutoCaller.h"
    3434#include "Logging.h"
     35#include "ThreadTask.h"
    3536
    3637#include <memory>
     
    149150}
    150151
    151 struct VFSExplorer::TaskVFSExplorer
    152 {
     152class VFSExplorer::TaskVFSExplorer : public ThreadTask
     153{
     154public:
    153155    enum TaskType
    154156    {
     
    162164          progress(aProgress),
    163165          rc(S_OK)
    164     {}
     166    {
     167        m_strTaskName = "Explorer::Task";
     168    }
    165169    ~TaskVFSExplorer() {}
    166170
    167     int startThread();
     171private:
     172    void handler()
     173    {
     174        int vrc = taskThread(NULL, this);
     175    }
     176
    168177    static DECLCALLBACK(int) taskThread(RTTHREAD aThread, void *pvUser);
    169178    static DECLCALLBACK(int) uploadProgress(unsigned uPercent, void *pvUser);
     
    171180    TaskType taskType;
    172181    VFSExplorer *pVFSExplorer;
     182
    173183    ComObjPtr<Progress> progress;
    174184    HRESULT rc;
     
    176186    /* task data */
    177187    std::list<Utf8Str> filenames;
     188
     189    friend class VFSExplorer;
    178190};
    179 
    180 int VFSExplorer::TaskVFSExplorer::startThread()
    181 {
    182     int vrc = RTThreadCreate(NULL, VFSExplorer::TaskVFSExplorer::taskThread, this,
    183                              0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
    184                              "Explorer::Task");
    185 
    186     if (RT_FAILURE(vrc))
    187         return VFSExplorer::setErrorStatic(E_FAIL, Utf8StrFmt("Could not create taskThreadVFS (%Rrc)\n", vrc));
    188 
    189     return vrc;
    190 }
    191191
    192192/* static */
    193193DECLCALLBACK(int) VFSExplorer::TaskVFSExplorer::taskThread(RTTHREAD /* aThread */, void *pvUser)
    194194{
    195     std::auto_ptr<TaskVFSExplorer> task(static_cast<TaskVFSExplorer*>(pvUser));
    196     AssertReturn(task.get(), VERR_GENERAL_FAILURE);
    197 
    198     VFSExplorer *pVFSExplorer = task->pVFSExplorer;
     195    TaskVFSExplorer* pTask = static_cast<TaskVFSExplorer*>(pvUser);
     196    AssertReturn(pTask, VERR_GENERAL_FAILURE);
     197
     198    VFSExplorer *pVFSExplorer = pTask->pVFSExplorer;
    199199
    200200    LogFlowFuncEnter();
     
    203203    HRESULT rc = S_OK;
    204204
    205     switch(task->taskType)
     205    switch(pTask->taskType)
    206206    {
    207207        case TaskVFSExplorer::Update:
    208208        {
    209209            if (pVFSExplorer->m->storageType == VFSType_File)
    210                 rc = pVFSExplorer->i_updateFS(task.get());
     210                rc = pVFSExplorer->i_updateFS(pTask);
    211211            else if (pVFSExplorer->m->storageType == VFSType_S3)
    212212                rc = VERR_NOT_IMPLEMENTED;
     
    216216        {
    217217            if (pVFSExplorer->m->storageType == VFSType_File)
    218                 rc = pVFSExplorer->i_deleteFS(task.get());
     218                rc = pVFSExplorer->i_deleteFS(pTask);
    219219            else if (pVFSExplorer->m->storageType == VFSType_S3)
    220220                rc = VERR_NOT_IMPLEMENTED;
     
    222222        }
    223223        default:
    224             AssertMsgFailed(("Invalid task type %u specified!\n", task->taskType));
     224            AssertMsgFailed(("Invalid task type %u specified!\n", pTask->taskType));
    225225            break;
    226226    }
     
    409409
    410410        /* Initialize our worker task */
    411         std::auto_ptr<TaskVFSExplorer> task(new TaskVFSExplorer(TaskVFSExplorer::Update, this, progress));
    412 
    413         rc = task->startThread();
    414         if (FAILED(rc)) throw rc;
    415 
    416         /* Don't destruct on success */
    417         task.release();
     411        TaskVFSExplorer* pTask = new TaskVFSExplorer(TaskVFSExplorer::Update, this, progress);
     412
     413        //this function delete task in case of exceptions, so there is no need in the call of delete operator
     414        rc = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
    418415    }
    419416    catch (HRESULT aRC)
     
    526523
    527524        /* Initialize our worker task */
    528         std::auto_ptr<TaskVFSExplorer> task(new TaskVFSExplorer(TaskVFSExplorer::Delete, this, progress));
     525        TaskVFSExplorer* pTask = new TaskVFSExplorer(TaskVFSExplorer::Delete, this, progress);
    529526
    530527        /* Add all filenames to delete as task data */
    531528        for (size_t i = 0; i < aNames.size(); ++i)
    532             task->filenames.push_back(aNames[i]);
    533 
    534         rc = task->startThread();
    535         if (FAILED(rc)) throw rc;
    536 
    537         /* Don't destruct on success */
    538         task.release();
     529            pTask->filenames.push_back(aNames[i]);
     530
     531        //this function delete task in case of exceptions, so there is no need in the call of delete operator
     532        rc = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
    539533    }
    540534    catch (HRESULT aRC)
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