VirtualBox

Changeset 63183 in vbox for trunk/src


Ignore:
Timestamp:
Aug 8, 2016 4:37:26 PM (8 years ago)
Author:
vboxsync
Message:

ThreadTask: Dealt with totally misguided m_pThread member. Started cleaning up handler() methods.

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

Legend:

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

    r62485 r63183  
    2727#include "GuestDnDPrivate.h"
    2828
     29class RecvDataTask;
    2930struct RECVDATACTX;
    3031typedef struct RECVDATACTX *PRECVDATACTX;
     
    8384    static Utf8Str i_hostErrorToString(int hostRc);
    8485
    85     /** @name Thread callbacks.
     86    /** @name Thread task .
    8687     * @{ */
    87     static DECLCALLBACK(int) i_receiveDataThread(RTTHREAD Thread, void *pvUser);
     88    static void i_receiveDataThreadTask(RecvDataTask *pTask);
    8889    /** @}  */
    8990
  • trunk/src/VBox/Main/include/GuestDnDTargetImpl.h

    r62485 r63183  
    2727struct SENDDATACTX;
    2828typedef struct SENDDATACTX *PSENDDATACTX;
     29class SendDataTask;
    2930
    3031class ATL_NO_VTABLE GuestDnDTarget :
     
    7172    static Utf8Str i_hostErrorToString(int hostRc);
    7273
    73     /** @name Thread callbacks.
     74    /** @name Thread task workers.
    7475     * @{ */
    75     static DECLCALLBACK(int) i_sendDataThread(RTTHREAD Thread, void *pvUser);
     76    static void i_sendDataThreadTask(SendDataTask *pTask);
    7677    /** @}  */
    7778
  • trunk/src/VBox/Main/include/ThreadTask.h

    r63182 r63183  
    2020#include "VBox/com/string.h"
    2121
     22/**
     23 * The class ThreadVoidData is used as a base class for any data which we want to pass into a thread
     24 */
    2225struct ThreadVoidData
    2326{
    24 /*
    25  * The class ThreadVoidData is used as a base class for any data which we want to pass into a thread
    26  */
    2727public:
    28     ThreadVoidData(){};
    29     virtual ~ThreadVoidData(){};
     28    ThreadVoidData() { }
     29    virtual ~ThreadVoidData() { }
    3030};
     31
    3132
    3233class ThreadTask
    3334{
    3435public:
    35     ThreadTask(const Utf8Str &t) : m_pThread(NULL), m_strTaskName(t)
    36     { };
     36    ThreadTask(const Utf8Str &t) : m_hThread(NIL_RTTHREAD), m_strTaskName(t)
     37    { }
    3738
    3839    virtual ~ThreadTask()
    39     { };
     40    { }
    4041
    4142    HRESULT createThread(void);
     
    4445
    4546    virtual void handler() = 0;
    46     inline Utf8Str getTaskName() const {return m_strTaskName;};
     47    inline Utf8Str getTaskName() const { return m_strTaskName; }
    4748
    4849protected:
     
    5051    static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser);
    5152
    52     ThreadTask():m_pThread(NULL), m_strTaskName("GenericTask"){};
     53    ThreadTask() : m_hThread(NIL_RTTHREAD), m_strTaskName("GenericTask")
     54    { }
    5355
    54     PRTTHREAD m_pThread;
     56    /** The worker thread handle (may be invalid if the thread has shut down). */
     57    RTTHREAD m_hThread;
    5558    Utf8Str m_strTaskName;
    5659};
  • trunk/src/VBox/Main/src-all/ThreadTask.cpp

    r63182 r63183  
    5151HRESULT ThreadTask::createThread(void)
    5252{
    53     return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, NULL /*pThread*/);
     53    return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, NULL /*phThread*/);
    5454}
    5555
     
    6262HRESULT ThreadTask::createThreadWithType(RTTHREADTYPE enmType)
    6363{
    64     return createThreadInternal(enmType, NULL /*pThread*/);
     64    return createThreadInternal(enmType, NULL /*phThread*/);
    6565}
    6666
     
    7272 * completion and termination of the task thread!  Use with care!
    7373 *
    74  * @param   pThread     Handle of the worker thread.
     74 * @param   phThread    Handle of the worker thread.
    7575 */
    76 HRESULT ThreadTask::createThreadWithRaceCondition(PRTTHREAD pThread)
     76HRESULT ThreadTask::createThreadWithRaceCondition(PRTTHREAD phThread)
    7777{
    78     return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, pThread);
     78    return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, phThread);
    7979}
    8080
     
    8686 * @note Always consumes @a this!
    8787 */
    88 HRESULT ThreadTask::createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread)
     88HRESULT ThreadTask::createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD phThread)
    8989{
    90     m_pThread = pThread; /** @todo this is utter non-sense! */
    91     int vrc = RTThreadCreate(m_pThread,
     90    int vrc = RTThreadCreate(&m_hThread,
    9291                             taskHandlerThreadProc,
    9392                             (void *)this,
     
    9796                             this->getTaskName().c_str());
    9897    if (RT_SUCCESS(vrc))
     98    {
     99        if (phThread)
     100            *phThread = m_hThread;
    99101        return S_OK;
     102    }
    100103
    101104    delete this;
     
    116119
    117120    /*
    118     *  handler shall catch and process all possible cases as errors and exceptions.
    119     */
     121     *  handler shall catch and process all possible cases as errors and exceptions.
     122     */
    120123    pTask->handler();
    121124
     125    pTask->m_hThread = NIL_RTTHREAD; /* unnecessary, but whatever. */
    122126    delete pTask;
    123127    return VINF_SUCCESS;
  • trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp

    r63182 r63183  
    8686    void handler()
    8787    {
    88         int vrc = GuestDnDSource::i_receiveDataThread(*m_pThread, this);
     88        GuestDnDSource::i_receiveDataThreadTask(this);
    8989    }
    9090
     
    962962#endif /* VBOX_WITH_DRAG_AND_DROP_GH */
    963963
     964/**
     965 * @returns VBox status code that the caller ignores. Not sure if that's
     966 *          intentional or not.
     967 */
    964968int GuestDnDSource::i_receiveData(PRECVDATACTX pCtx, RTMSINTERVAL msTimeout)
    965969{
     
    10621066
    10631067/* static */
    1064 DECLCALLBACK(int) GuestDnDSource::i_receiveDataThread(RTTHREAD Thread, void *pvUser)
    1065 {
    1066     LogFlowFunc(("pvUser=%p\n", pvUser));
    1067 
    1068     RecvDataTask *pTask = (RecvDataTask *)pvUser;
    1069     AssertPtrReturn(pTask, VERR_INVALID_POINTER);
     1068DECLCALLBACK(void) GuestDnDSource::i_receiveDataThreadTask(RecvDataTask *pTask)
     1069{
     1070    LogFlowFunc(("pTask=%p\n", pTask));
     1071    AssertPtrReturnVoid(pTask);
    10701072
    10711073    const ComObjPtr<GuestDnDSource> pThis(pTask->getSource());
     
    10731075
    10741076    AutoCaller autoCaller(pThis);
    1075     if (FAILED(autoCaller.rc())) return VERR_COM_INVALID_OBJECT_STATE;
    1076 
    1077     int rc = RTThreadUserSignal(Thread);
    1078     AssertRC(rc);
    1079 
    1080     rc = pThis->i_receiveData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */);
     1077    if (FAILED(autoCaller.rc()))
     1078        return;
     1079
     1080    int vrc = RTThreadUserSignal(RTThreadSelf());
     1081    AssertRC(vrc);
     1082
     1083    vrc = pThis->i_receiveData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */);
     1084/** @todo
     1085 *
     1086 *  r=bird: What happens with @a vrc?
     1087 *
     1088 */
    10811089
    10821090    AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
     
    10851093    pThis->mDataBase.m_cTransfersPending--;
    10861094
    1087     LogFlowFunc(("pSource=%p returning rc=%Rrc\n", (GuestDnDSource *)pThis, rc));
    1088     return rc;
     1095    LogFlowFunc(("pSource=%p vrc=%Rrc (ignored)\n", (GuestDnDSource *)pThis, vrc));
    10891096}
    10901097
  • trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp

    r63182 r63183  
    9090    void handler()
    9191    {
    92         int vrc = GuestDnDTarget::i_sendDataThread(*m_pThread, this);
    93         NOREF(vrc);
     92        GuestDnDTarget::i_sendDataThreadTask(this);
    9493    }
    9594
     
    558557
    559558/* static */
    560 DECLCALLBACK(int) GuestDnDTarget::i_sendDataThread(RTTHREAD Thread, void *pvUser)
    561 {
    562     LogFlowFunc(("pvUser=%p\n", pvUser));
    563 
    564     SendDataTask *pTask = (SendDataTask *)pvUser;
    565     AssertPtrReturn(pTask, VERR_INVALID_POINTER);
     559void GuestDnDTarget::i_sendDataThreadTask(SendDataTask *pTask)
     560{
     561    LogFlowFunc(("pTask=%p\n", pTask));
     562
     563    AssertPtrReturnVoid(pTask);
    566564
    567565    const ComObjPtr<GuestDnDTarget> pThis(pTask->getTarget());
     
    569567
    570568    AutoCaller autoCaller(pThis);
    571     if (FAILED(autoCaller.rc())) return VERR_COM_INVALID_OBJECT_STATE;
    572 
    573     int rc = RTThreadUserSignal(Thread);
    574     AssertRC(rc);
    575 
    576     rc = pThis->i_sendData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */);
     569    if (FAILED(autoCaller.rc()))
     570        return;
     571
     572    int vrc = RTThreadUserSignal(RTThreadSelf());
     573    AssertRC(vrc);
     574
     575    vrc = pThis->i_sendData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */);
     576/** @todo
     577 *
     578 *  r=bird: What happens with @a vrc?
     579 *
     580 */
    577581
    578582    AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
     
    581585    pThis->mDataBase.m_cTransfersPending--;
    582586
    583     LogFlowFunc(("pTarget=%p returning rc=%Rrc\n", (GuestDnDTarget *)pThis, rc));
    584     return rc;
     587    LogFlowFunc(("pTarget=%p vrc=%Rrc (ignored)\n", (GuestDnDTarget *)pThis, vrc));
    585588}
    586589
     
    779782}
    780783
     784/**
     785 * @returns VBox status code that the caller ignores. Not sure if that's
     786 *          intentional or not.
     787 */
    781788int GuestDnDTarget::i_sendData(PSENDDATACTX pCtx, RTMSINTERVAL msTimeout)
    782789{
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