Changeset 63182 in vbox for trunk/src/VBox
- Timestamp:
- Aug 8, 2016 4:16:42 PM (8 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ThreadTask.h
r63181 r63182 39 39 { }; 40 40 41 HRESULT createThread(PRTTHREAD pThread = NULL, RTTHREADTYPE enmType = RTTHREADTYPE_MAIN_WORKER); 41 HRESULT createThread(void); 42 HRESULT createThreadWithType(RTTHREADTYPE enmType); 43 HRESULT createThreadWithRaceCondition(PRTTHREAD pThread); 42 44 43 45 virtual void handler() = 0; … … 45 47 46 48 protected: 49 HRESULT createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread); 47 50 static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser); 48 51 -
trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
r63181 r63182 660 660 { 661 661 ComPtr<Progress> ptrProgress = pTask->ptrProgress; 662 hrc = pTask->createThread (NULL /*phThread*/,RTTHREADTYPE_DEFAULT);662 hrc = pTask->createThreadWithType(RTTHREADTYPE_DEFAULT); 663 663 pTask = NULL; /* The _completely_ _undocumented_ createThread method always consumes pTask. */ 664 664 if (SUCCEEDED(hrc)) … … 2088 2088 { 2089 2089 ComPtr<Progress> ptrProgress = pTask->ptrProgress; 2090 hrc = pTask->createThread (NULL,RTTHREADTYPE_DEFAULT);2090 hrc = pTask->createThreadWithType(RTTHREADTYPE_DEFAULT); 2091 2091 pTask = NULL; /* always consumed by createThread */ 2092 2092 if (SUCCEEDED(hrc)) -
trunk/src/VBox/Main/src-all/ThreadTask.cpp
r63181 r63182 20 20 #include "ThreadTask.h" 21 21 22 22 23 /** 23 24 * Starts the task (on separate thread), consuming @a this. … … 28 29 * 29 30 * Possible way of usage: 31 * @code{.cpp} 32 HRESULT hr; 33 SomeTaskInheritedFromThreadTask *pTask = NULL; 34 try 35 { 36 pTask = new SomeTaskInheritedFromThreadTask(this); 37 if (!pTask->Init()) // some init procedure 38 throw E_FAIL; 39 } 40 catch (...) 41 { 42 if (pTask); 43 delete pTask; 44 return E_FAIL; 45 } 46 return pTask->createThread(); // pTask is always consumed 47 @endcode 30 48 * 31 * @code{.cpp} 32 * int vrc = VINF_SUCCESS; 33 * HRESULT hr = S_OK; 49 * @sa createThreadWithType, createThreadWithRaceCondition 50 */ 51 HRESULT ThreadTask::createThread(void) 52 { 53 return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, NULL /*pThread*/); 54 } 55 56 57 /** 58 * Same ThreadTask::createThread(), except it takes a thread type parameter. 34 59 * 35 * SomeTaskInheritedFromThreadTask* pTask = NULL; 36 * try 37 * { 38 * pTask = new SomeTaskInheritedFromThreadTask(this); 39 * if (!pTask->Init())//some init procedure 40 * { 41 * delete pTask; 42 * throw E_FAIL; 43 * } 44 * //this function delete pTask in case of exceptions, so 45 * there is no need the call of delete operator 60 * @param enmType The thread type. 61 */ 62 HRESULT ThreadTask::createThreadWithType(RTTHREADTYPE enmType) 63 { 64 return createThreadInternal(enmType, NULL /*pThread*/); 65 } 66 67 68 /** 69 * Same ThreadTask::createThread(), except it returns a thread handle. 46 70 * 47 * hr = pTask->createThread(); 48 * } 49 * catch(...) 50 * { 51 * vrc = E_FAIL; 52 * } 53 * @endcode 71 * If the task thread is incorrectly mananged, the caller may easily race the 72 * completion and termination of the task thread! Use with care! 73 * 74 * @param pThread Handle of the worker thread. 54 75 */ 55 HRESULT ThreadTask::createThread (PRTTHREAD pThread /*= NULL*/, RTTHREADTYPE enmType /*= RTTHREADTYPE_MAIN_WORKER*/)76 HRESULT ThreadTask::createThreadWithRaceCondition(PRTTHREAD pThread) 56 77 { 57 m_pThread = pThread; 78 return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, pThread); 79 } 80 81 82 /** 83 * Internal worker for ThreadTask::createThread, 84 * ThreadTask::createThreadWithType, ThreadTask::createThreadwithRaceCondition. 85 * 86 * @note Always consumes @a this! 87 */ 88 HRESULT ThreadTask::createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread) 89 { 90 m_pThread = pThread; /** @todo this is utter non-sense! */ 58 91 int vrc = RTThreadCreate(m_pThread, 59 92 taskHandlerThreadProc, … … 69 102 return E_FAIL; 70 103 } 104 71 105 72 106 /** -
trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp
r60622 r63182 584 584 } 585 585 586 hr = pTask->createThread (NULL,RTTHREADTYPE_MAIN_HEAVY_WORKER);586 hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 587 587 588 588 if (SUCCEEDED(hr)) -
trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp
r63180 r63182 383 383 /** @todo r=bird: The code using hThreadRcv is racing the thread termination. Since the thread isn't 384 384 * created waitable, the handle goes away if we it terminates before our RTThreadUserWait call returns. */ 385 hr = pTask->createThread (&hThreadRcv);385 hr = pTask->createThreadWithRaceCondition(&hThreadRcv); 386 386 387 387 } -
trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp
r63180 r63182 655 655 /** @todo r=bird: The code using hThreadSend is racing the thread termination. Since the thread isn't 656 656 * created waitable, the handle goes away if we it terminates before our RTThreadUserWait call returns. */ 657 hr = pTask->createThread (&rcThreadSend);657 hr = pTask->createThreadWithRaceCondition(&rcThreadSend); 658 658 659 659 } -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r63157 r63182 2512 2512 } 2513 2513 2514 hr = pTask->createThread (NULL,RTTHREADTYPE_MAIN_HEAVY_WORKER);2514 hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 2515 2515 2516 2516 if (SUCCEEDED(hr)) … … 2585 2585 } 2586 2586 2587 hr = pTask->createThread (NULL,RTTHREADTYPE_MAIN_HEAVY_WORKER);2587 hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 2588 2588 2589 2589 if (SUCCEEDED(hr)) -
trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
r63152 r63182 1064 1064 } 1065 1065 1066 hr = pTask->createThread (NULL,RTTHREADTYPE_MAIN_HEAVY_WORKER);1066 hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 1067 1067 1068 1068 if (SUCCEEDED(hr)) -
trunk/src/VBox/Main/src-server/VFSExplorerImpl.cpp
r62485 r63182 413 413 414 414 //this function delete task in case of exceptions, so there is no need in the call of delete operator 415 rc = pTask->createThread (NULL,RTTHREADTYPE_MAIN_HEAVY_WORKER);415 rc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 416 416 } 417 417 catch (HRESULT aRC) … … 531 531 532 532 //this function delete task in case of exceptions, so there is no need in the call of delete operator 533 rc = pTask->createThread (NULL,RTTHREADTYPE_MAIN_HEAVY_WORKER);533 rc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 534 534 } 535 535 catch (HRESULT aRC) -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r63181 r63182 2567 2567 2568 2568 //this function delete pTask in case of exceptions, so there is no need in the call of delete operator 2569 hr = pTask->createThread (NULL,RTTHREADTYPE_MAIN_WORKER);2569 hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_WORKER); 2570 2570 2571 2571 }
Note:
See TracChangeset
for help on using the changeset viewer.