- Timestamp:
- Oct 30, 2015 8:17:19 AM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestDnDSourceImpl.h
r58212 r58519 110 110 RECVDATACTX mRecvCtx; 111 111 } mData; 112 113 friend class RecvDataTask; 112 114 }; 113 115 -
trunk/src/VBox/Main/include/GuestDnDTargetImpl.h
r58212 r58519 102 102 uint32_t mcbBlockSize; 103 103 } mData; 104 105 friend class SendDataTask; 104 106 }; 105 107 -
trunk/src/VBox/Main/include/ThreadTask.h
r58009 r58519 20 20 #include "VBox/com/string.h" 21 21 22 struct ThreadVoidData 23 { 24 public: 25 ThreadVoidData(){}; 26 virtual ~ThreadVoidData(){}; 27 }; 28 22 29 class ThreadTask 23 30 { 24 31 public: 25 ThreadTask(const Utf8Str &t) : m_ strTaskName(t){};32 ThreadTask(const Utf8Str &t) : m_pThread(NULL), m_strTaskName(t){}; 26 33 virtual ~ThreadTask(){}; 27 HRESULT createThread( );34 HRESULT createThread(PRTTHREAD pThread = NULL, RTTHREADTYPE enmType = RTTHREADTYPE_MAIN_WORKER); 28 35 virtual void handler() = 0; 29 36 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser); 30 static HRESULT i_setErrorStatic(HRESULT aResultCode, const Utf8Str &aText);37 static HRESULT setErrorStatic(HRESULT aResultCode, const Utf8Str &aText); 31 38 32 39 inline Utf8Str getTaskName() const {return m_strTaskName;}; … … 34 41 protected: 35 42 ThreadTask():m_strTaskName("GenericTask"){}; 43 PRTTHREAD m_pThread; 36 44 Utf8Str m_strTaskName; 37 45 }; -
trunk/src/VBox/Main/src-all/ThreadTask.cpp
r58009 r58519 20 20 #include "ThreadTask.h" 21 21 22 HRESULT ThreadTask::createThread( )22 HRESULT ThreadTask::createThread(PRTTHREAD pThread, RTTHREADTYPE enmType) 23 23 { 24 24 HRESULT rc = S_OK; 25 25 try 26 26 { 27 int vrc = RTThreadCreate(NULL, 27 m_pThread = pThread; 28 int vrc = RTThreadCreate(m_pThread, 28 29 taskHandler, 29 30 (void *)this, 30 31 0, 31 RTTHREADTYPE_MAIN_WORKER,32 enmType, 32 33 0, 33 34 this->getTaskName().c_str()); … … 89 90 } 90 91 91 /*static*/ HRESULT ThreadTask:: i_setErrorStatic(HRESULT aResultCode,92 /*static*/ HRESULT ThreadTask::setErrorStatic(HRESULT aResultCode, 92 93 const Utf8Str &aText) 93 94 { -
trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp
r58329 r58519 27 27 #include "Global.h" 28 28 #include "AutoCaller.h" 29 #include "ThreadTask.h" 29 30 30 31 #include <iprt/asm.h> … … 47 48 * Base class for a source task. 48 49 */ 49 class GuestDnDSourceTask 50 class GuestDnDSourceTask : public ThreadTask 50 51 { 51 52 public: 52 53 53 54 GuestDnDSourceTask(GuestDnDSource *pSource) 54 : mSource(pSource), 55 mRC(VINF_SUCCESS) { } 55 : ThreadTask("GenericGuestDnDSourceTask") 56 , mSource(pSource) 57 , mRC(VINF_SUCCESS) { } 56 58 57 59 virtual ~GuestDnDSourceTask(void) { } … … 77 79 RecvDataTask(GuestDnDSource *pSource, PRECVDATACTX pCtx) 78 80 : GuestDnDSourceTask(pSource) 79 , mpCtx(pCtx) { } 81 , mpCtx(pCtx) 82 { 83 m_strTaskName = "dndSrcRcvData"; 84 } 85 86 void handler() 87 { 88 int vrc = GuestDnDSource::i_receiveDataThread(*m_pThread, this); 89 } 80 90 81 91 virtual ~RecvDataTask(void) { } … … 347 357 return hr; 348 358 359 RecvDataTask *pTask = NULL; 360 RTTHREAD threadRcv; 361 int rc = S_OK; 362 349 363 try 350 364 { … … 357 371 LogRel2(("DnD: Requesting data from guest in format: %s\n", aFormat.c_str())); 358 372 359 RecvDataTask *pTask = new RecvDataTask(this, &mData.mRecvCtx); 360 AssertReturn(pTask->isOk(), pTask->getRC()); 361 362 LogFlowFunc(("Starting thread ...\n")); 363 364 RTTHREAD threadRcv; 365 int rc = RTThreadCreate(&threadRcv, GuestDnDSource::i_receiveDataThread, 366 (void *)pTask, 0, RTTHREADTYPE_MAIN_WORKER, 0, "dndSrcRcvData"); 373 pTask = new RecvDataTask(this, &mData.mRecvCtx); 374 if (!pTask->isOk()) 375 { 376 delete pTask; 377 LogRel2(("DnD: Could not create RecvDataTask object \n")); 378 throw hr = E_FAIL; 379 } 380 381 //this function delete pTask in case of exceptions, so there is no need in the call of delete operator 382 hr = pTask->createThread(&threadRcv); 383 384 } 385 catch(std::bad_alloc &) 386 { 387 hr = setError(E_OUTOFMEMORY); 388 } 389 catch(...) 390 { 391 LogRel2(("DnD: Could not create thread for RecvDataTask \n")); 392 hr = E_FAIL; 393 } 394 395 if (SUCCEEDED(hr)) 396 { 397 rc = RTThreadUserWait(threadRcv, 30 * 1000 /* 30s timeout */); 367 398 if (RT_SUCCESS(rc)) 368 399 { 369 rc = RTThreadUserWait(threadRcv, 30 * 1000 /* 30s timeout */); 370 if (RT_SUCCESS(rc)) 371 { 372 mDataBase.m_cTransfersPending++; 373 374 hr = pResp->queryProgressTo(aProgress.asOutParam()); 375 ComAssertComRC(hr); 376 377 /* Note: pTask is now owned by the worker thread. */ 378 } 379 else 380 hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for receiving thread failed (%Rrc)"), rc); 400 mDataBase.m_cTransfersPending++; 401 402 hr = pResp->queryProgressTo(aProgress.asOutParam()); 403 ComAssertComRC(hr); 404 405 /* Note: pTask is now owned by the worker thread. */ 381 406 } 382 407 else 383 hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread failed (%Rrc)"), rc); 384 385 if (FAILED(hr)) 386 delete pTask; 387 } 388 catch(std::bad_alloc &) 389 { 390 hr = setError(E_OUTOFMEMORY); 391 } 408 hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for receiving thread failed (%Rrc)"), rc); 409 } 410 else 411 hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread for GuestDnDSource::i_receiveDataThread failed (%Rrc)"), rc); 412 /* Note: mDataBase.mfTransferIsPending will be set to false again by i_receiveDataThread. */ 392 413 393 414 LogFlowFunc(("Returning hr=%Rhrc\n", hr)); … … 1005 1026 rc = pThis->i_receiveData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */); 1006 1027 1007 if (pTask)1008 delete pTask;1009 1010 1028 AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS); 1011 1029 -
trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp
r58370 r58519 26 26 #include "Global.h" 27 27 #include "AutoCaller.h" 28 #include "ThreadTask.h" 28 29 29 30 #include <algorithm> /* For std::find(). */ … … 51 52 * Base class for a target task. 52 53 */ 53 class GuestDnDTargetTask 54 class GuestDnDTargetTask : public ThreadTask 54 55 { 55 56 public: 56 57 57 58 GuestDnDTargetTask(GuestDnDTarget *pTarget) 58 : mTarget(pTarget), 59 mRC(VINF_SUCCESS) { } 59 : ThreadTask("GenericGuestDnDTargetTask") 60 , mTarget(pTarget) 61 , mRC(VINF_SUCCESS) { } 60 62 61 63 virtual ~GuestDnDTargetTask(void) { } … … 81 83 SendDataTask(GuestDnDTarget *pTarget, PSENDDATACTX pCtx) 82 84 : GuestDnDTargetTask(pTarget), 83 mpCtx(pCtx) { } 85 mpCtx(pCtx) 86 { 87 m_strTaskName = "dndTgtSndData"; 88 } 89 90 void handler() 91 { 92 int vrc = GuestDnDTarget::i_sendDataThread(*m_pThread, this); 93 } 84 94 85 95 virtual ~SendDataTask(void) … … 564 574 565 575 rc = pThis->i_sendData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */); 566 567 if (pTask)568 delete pTask;569 576 570 577 AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS); … … 617 624 return hr; 618 625 626 SendDataTask *pTask = NULL; 627 PSENDDATACTX pSendCtx = NULL; 628 RTTHREAD threadSnd; 629 int rc = S_OK; 630 619 631 try 620 632 { 621 PSENDDATACTX pSendCtx = new SENDDATACTX; 633 //pSendCtx is passed into SendDataTask where one is deleted in destructor 634 pSendCtx = new SENDDATACTX; 622 635 RT_BZERO(pSendCtx, sizeof(SENDDATACTX)); 623 636 … … 626 639 pSendCtx->mScreenID = aScreenId; 627 640 pSendCtx->mFmtReq = aFormat; 628 629 641 pSendCtx->mData.getMeta().add(aData); 630 642 631 SendDataTask *pTask = new SendDataTask(this, pSendCtx); 632 AssertReturn(pTask->isOk(), pTask->getRC()); 633 634 LogFlowFunc(("Starting thread ...\n")); 635 636 RTTHREAD threadSnd; 637 int rc = RTThreadCreate(&threadSnd, GuestDnDTarget::i_sendDataThread, 638 (void *)pTask, 0, RTTHREADTYPE_MAIN_WORKER, 0, "dndTgtSndData"); 643 /* pTask is responsible for deletion of pSendCtx after creating */ 644 pTask = new SendDataTask(this, pSendCtx); 645 if (!pTask->isOk()) 646 { 647 delete pTask; 648 LogRel2(("DnD: Could not create SendDataTask object \n")); 649 throw hr = E_FAIL; 650 } 651 652 //this function delete pTask in case of exceptions, so there is no need in the call of delete operator 653 //pSendCtx is deleted in the pTask destructor 654 hr = pTask->createThread(&threadSnd); 655 656 } 657 catch(std::bad_alloc &) 658 { 659 hr = setError(E_OUTOFMEMORY); 660 } 661 catch(...) 662 { 663 LogRel2(("DnD: Could not create thread for SendDataTask \n")); 664 hr = E_FAIL; 665 } 666 667 if (SUCCEEDED(hr)) 668 { 669 rc = RTThreadUserWait(threadSnd, 30 * 1000 /* 30s timeout */); 639 670 if (RT_SUCCESS(rc)) 640 671 { 641 rc = RTThreadUserWait(threadSnd, 30 * 1000 /* 30s timeout */); 642 if (RT_SUCCESS(rc)) 643 { 644 mDataBase.m_cTransfersPending++; 645 646 hr = pResp->queryProgressTo(aProgress.asOutParam()); 647 ComAssertComRC(hr); 648 649 /* Note: pTask is now owned by the worker thread. */ 650 } 651 else 652 hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for sending thread failed (%Rrc)"), rc); 672 mDataBase.m_cTransfersPending++; 673 674 hr = pResp->queryProgressTo(aProgress.asOutParam()); 675 ComAssertComRC(hr); 676 677 /* Note: pTask is now owned by the worker thread. */ 653 678 } 654 679 else 655 hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread failed (%Rrc)"), rc); 656 657 if (FAILED(hr)) 658 delete pSendCtx; 659 } 660 catch(std::bad_alloc &) 661 { 662 hr = setError(E_OUTOFMEMORY); 663 } 680 hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for sending thread failed (%Rrc)"), rc); 681 } 682 else 683 hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread for GuestDnDTarget::i_sendDataThread (%Rrc)"), rc); 664 684 665 685 LogFlowFunc(("Returning hr=%Rhrc\n", hr));
Note:
See TracChangeset
for help on using the changeset viewer.