Changeset 63181 in vbox for trunk/src/VBox/Main
- Timestamp:
- Aug 8, 2016 3:56:30 PM (8 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ThreadTask.h
r60999 r63181 33 33 { 34 34 public: 35 ThreadTask(const Utf8Str &t) : m_pThread(NULL), m_strTaskName(t){}; 36 virtual ~ThreadTask(){}; 35 ThreadTask(const Utf8Str &t) : m_pThread(NULL), m_strTaskName(t) 36 { }; 37 38 virtual ~ThreadTask() 39 { }; 40 37 41 HRESULT createThread(PRTTHREAD pThread = NULL, RTTHREADTYPE enmType = RTTHREADTYPE_MAIN_WORKER); 42 38 43 virtual void handler() = 0; 39 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);40 41 44 inline Utf8Str getTaskName() const {return m_strTaskName;}; 42 45 43 46 protected: 47 static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser); 48 44 49 ThreadTask():m_pThread(NULL), m_strTaskName("GenericTask"){}; 50 45 51 PRTTHREAD m_pThread; 46 52 Utf8Str m_strTaskName; -
trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
r63148 r63181 660 660 { 661 661 ComPtr<Progress> ptrProgress = pTask->ptrProgress; 662 hrc = pTask->createThread(NULL , RTTHREADTYPE_DEFAULT);662 hrc = pTask->createThread(NULL /*phThread*/, RTTHREADTYPE_DEFAULT); 663 663 pTask = NULL; /* The _completely_ _undocumented_ createThread method always consumes pTask. */ 664 664 if (SUCCEEDED(hrc)) -
trunk/src/VBox/Main/src-all/ThreadTask.cpp
r60999 r63181 21 21 22 22 /** 23 * The function takes ownership of "this" instance (object 24 * instance which calls this function). 25 * And the function is responsible for deletion of "this" 26 * pointer in all cases. 27 * Possible way of usage: 23 * Starts the task (on separate thread), consuming @a this. 28 24 * 29 * int vrc = VINF_SUCCESS; 30 * HRESULT hr = S_OK; 25 * The function takes ownership of "this" instance (object instance which calls 26 * this function). And the function is responsible for deletion of "this" 27 * pointer in all cases. 31 28 * 32 * SomeTaskInheritedFromThreadTask* pTask = NULL; 33 * try 34 * { 35 * pTask = new SomeTaskInheritedFromThreadTask(this); 36 * if (!pTask->Init())//some init procedure 37 * { 38 * delete pTask; 39 * throw E_FAIL; 40 * } 41 * //this function delete pTask in case of exceptions, so 42 * there is no need the call of delete operator 29 * Possible way of usage: 43 30 * 44 * hr = pTask->createThread(); 45 * } 46 * catch(...) 47 * { 48 * vrc = E_FAIL; 49 * } 31 * @code{.cpp} 32 * int vrc = VINF_SUCCESS; 33 * HRESULT hr = S_OK; 34 * 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 46 * 47 * hr = pTask->createThread(); 48 * } 49 * catch(...) 50 * { 51 * vrc = E_FAIL; 52 * } 53 * @endcode 50 54 */ 51 HRESULT ThreadTask::createThread(PRTTHREAD pThread , RTTHREADTYPE enmType)55 HRESULT ThreadTask::createThread(PRTTHREAD pThread /*= NULL*/, RTTHREADTYPE enmType /*= RTTHREADTYPE_MAIN_WORKER*/) 52 56 { 53 HRESULT rc = S_OK;54 55 57 m_pThread = pThread; 56 58 int vrc = RTThreadCreate(m_pThread, 57 taskHandler ,59 taskHandlerThreadProc, 58 60 (void *)this, 59 61 0, … … 61 63 0, 62 64 this->getTaskName().c_str()); 65 if (RT_SUCCESS(vrc)) 66 return S_OK; 63 67 64 if (RT_FAILURE(vrc)) 65 { 66 delete this; 67 return E_FAIL; 68 } 69 70 return rc; 68 delete this; 69 return E_FAIL; 71 70 } 72 71 … … 75 74 * thread started for a Task. 76 75 */ 77 /* static */ DECLCALLBACK(int) ThreadTask::taskHandler (RTTHREAD /* thread */, void *pvUser)76 /* static */ DECLCALLBACK(int) ThreadTask::taskHandlerThreadProc(RTTHREAD /* thread */, void *pvUser) 78 77 { 79 78 if (pvUser == NULL) 80 return VERR_INVALID_POINTER; 79 return VERR_INVALID_POINTER; /* nobody cares */ 81 80 82 81 ThreadTask *pTask = static_cast<ThreadTask *>(pvUser); … … 88 87 89 88 delete pTask; 90 91 89 return VINF_SUCCESS; 92 90 } 91 -
trunk/src/VBox/Main/src-client/ClientTokenHolder.cpp
r62485 r63181 271 271 /* release the token */ 272 272 LogFlow(("ClientTokenHolderThread(): releasing token...\n")); 273 BOOL success= ::ReleaseMutex(mutex);274 AssertMsg( success, ("cannot release token, err=%d\n", ::GetLastError()));273 BOOL fRc = ::ReleaseMutex(mutex); 274 AssertMsg(fRc, ("cannot release token, err=%d\n", ::GetLastError())); NOREF(fRc); 275 275 ::CloseHandle(mutex); 276 276 ::CloseHandle(finishSem); -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r63178 r63181 2553 2553 HRESULT hr = S_OK; 2554 2554 StartSVCHelperClientData *pTask = NULL; 2555 RTTHREAD tid = NIL_RTTHREAD;2556 2555 try 2557 2556 { … … 2568 2567 2569 2568 //this function delete pTask in case of exceptions, so there is no need in the call of delete operator 2570 hr = pTask->createThread( &tid, RTTHREADTYPE_MAIN_WORKER);2569 hr = pTask->createThread(NULL, RTTHREADTYPE_MAIN_WORKER); 2571 2570 2572 2571 }
Note:
See TracChangeset
for help on using the changeset viewer.