Changeset 27831 in vbox
- Timestamp:
- Mar 30, 2010 2:55:27 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 59506
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MediumImpl.cpp
r27824 r27831 407 407 * Thread function for time-consuming medium tasks. 408 408 * 409 * @param pvUser Pointer to the std::auto_ptr<Medium::Task>instance.409 * @param pvUser Pointer to the Medium::Task instance. 410 410 */ 411 411 /* static */ … … 413 413 { 414 414 LogFlowFuncEnter(); 415 /* pvUser is a pointer to a std::auto_ptr<Medium::Task>, which is so416 * hard to understand that we just clear this situation now by copying417 * it. This means the old object loses ownership, and task owns it. */418 415 AssertReturn(pvUser, (int)E_INVALIDARG); 419 std::auto_ptr<Medium::Task> *pTask = 420 static_cast<std::auto_ptr<Medium::Task> *>(pvUser); 421 std::auto_ptr<Medium::Task> task(pTask->release()); 422 AssertReturn(task.get(), (int)E_INVALIDARG); 423 424 task->mThread = aThread; 425 426 HRESULT rc = task->handler(); 416 Medium::Task *pTask = static_cast<Medium::Task *>(pvUser); 417 418 pTask->mThread = aThread; 419 420 HRESULT rc = pTask->handler(); 427 421 428 422 /* complete the progress if run asynchronously */ 429 if (task->isAsync()) 430 { 431 if (!task->mProgress.isNull()) 432 task->mProgress->notifyComplete(rc); 433 } 423 if (pTask->isAsync()) 424 { 425 if (!pTask->mProgress.isNull()) 426 pTask->mProgress->notifyComplete(rc); 427 } 428 429 /* pTask is no longer needed, delete it. */ 430 delete pTask; 434 431 435 432 LogFlowFunc(("rc=%Rhrc\n", rc)); … … 2469 2466 2470 2467 /* setup task object to carry out the operation asynchronously */ 2471 std::auto_ptr<Medium::Task> task(new CreateBaseTask(this, progress, 2472 aLogicalSize, 2473 aVariant)); 2474 AssertComRCReturnRC(task->rc()); 2475 2476 rc = startThread(task); 2468 Medium::Task *pTask(new Medium::CreateBaseTask(this, progress, 2469 aLogicalSize, aVariant)); 2470 rc = pTask->rc(); 2471 if (FAILED(rc)) 2472 { 2473 AssertComRC(rc); 2474 delete pTask; 2475 return rc; 2476 } 2477 2478 rc = startThread(pTask); 2477 2479 if (FAILED(rc)) return rc; 2478 2480 … … 2480 2482 m->state = MediumState_Creating; 2481 2483 2484 progress.queryInterfaceTo(aProgress); 2485 2482 2486 return S_OK; 2483 2487 } … … 2494 2498 HRESULT rc = deleteStorageNoWait(progress); 2495 2499 if (SUCCEEDED(rc)) 2496 {2497 /* return progress to the caller */2498 2500 progress.queryInterfaceTo(aProgress); 2499 }2500 2501 2501 2502 return rc; … … 2536 2537 } 2537 2538 else 2538 {2539 /* return progress to the caller */2540 2539 progress.queryInterfaceTo(aProgress); 2541 }2542 2540 2543 2541 return rc; … … 2632 2630 2633 2631 /* setup task object to carry out the operation asynchronously */ 2634 std::auto_ptr<Medium::Task> task(new CloneTask(this, progress, 2635 target, parent, 2636 sourceChain.release(), 2637 parentChain.release(), 2638 aVariant)); 2639 AssertComRCReturnRC(task->rc()); 2640 2641 rc = startThread(task); 2632 Medium::Task *pTask(new Medium::CloneTask(this, progress, target, 2633 parent, 2634 sourceChain.release(), 2635 parentChain.release(), 2636 aVariant)); 2637 rc = pTask->rc(); 2638 if (FAILED(rc)) 2639 { 2640 AssertComRC(rc); 2641 delete pTask; 2642 throw rc; 2643 } 2644 2645 rc = startThread(pTask); 2642 2646 if (FAILED(rc)) throw rc; 2643 2647 … … 2654 2658 2655 2659 if (SUCCEEDED(rc)) 2656 /* return progress to the caller */2657 2660 progress.queryInterfaceTo(aProgress); 2658 2661 … … 2702 2705 2703 2706 /* setup task object to carry out the operation asynchronously */ 2704 std::auto_ptr<Medium::Task> task(new CompactTask(this, progress, 2705 imgChain.release())); 2706 AssertComRCReturnRC(task->rc()); 2707 2708 rc = startThread(task); 2707 Medium::Task *pTask(new Medium::CompactTask(this, progress, 2708 imgChain.release())); 2709 rc = pTask->rc(); 2710 if (FAILED(rc)) 2711 { 2712 AssertComRC(rc); 2713 delete pTask; 2714 throw rc; 2715 } 2716 2717 rc = startThread(pTask); 2709 2718 if (FAILED(rc)) throw rc; 2710 2719 } … … 2715 2724 2716 2725 if (SUCCEEDED(rc)) 2717 {2718 /* return progress to the caller */2719 2726 progress.queryInterfaceTo(aProgress); 2720 }2721 2727 2722 2728 return rc; … … 2772 2778 2773 2779 /* setup task object to carry out the operation asynchronously */ 2774 std::auto_ptr<Medium::Task> task(new ResetTask(this, progress)); 2775 AssertComRCReturnRC(task->rc()); 2776 2777 rc = startThread(task); 2780 Medium::Task *pTask(new Medium::ResetTask(this, progress)); 2781 rc = pTask->rc(); 2782 if (FAILED(rc)) 2783 { 2784 AssertComRC(rc); 2785 delete pTask; 2786 throw rc; 2787 } 2788 2789 rc = startThread(pTask); 2778 2790 if (FAILED(rc)) throw rc; 2779 2791 } … … 2790 2802 } 2791 2803 else 2792 {2793 /* return progress to the caller */2794 2804 progress.queryInterfaceTo(aProgress); 2795 }2796 2805 2797 2806 LogFlowThisFunc(("LEAVE, rc=%Rhrc\n", rc)); … … 4331 4340 4332 4341 /* setup task object to carry out the operation asynchronously */ 4333 std::auto_ptr<Medium::Task> task(new DeleteTask(this, progress)); 4334 AssertComRCReturnRC(task->rc()); 4342 Medium::Task *pTask(new Medium::DeleteTask(this, progress)); 4343 rc = pTask->rc(); 4344 if (FAILED(rc)) 4345 { 4346 AssertComRC(rc); 4347 delete pTask; 4348 return rc; 4349 } 4335 4350 4336 4351 if (aWait) … … 4339 4354 m->state = MediumState_Deleting; 4340 4355 4341 rc = runNow(task, NULL /* pfNeedsSaveSettings*/ ); // there is no save settings to do in taskThreadDelete() 4356 rc = runNow(pTask, NULL /* pfNeedsSaveSettings*/ ); // there is no save settings to do in taskThreadDelete() 4357 if (FAILED(rc)) return rc; 4342 4358 } 4343 4359 else 4344 4360 { 4345 rc = startThread( task);4361 rc = startThread(pTask); 4346 4362 if (FAILED(rc)) return rc; 4347 4363 … … 4351 4367 4352 4368 if (aProgress != NULL) 4353 {4354 /* return progress to the caller */4355 4369 *aProgress = progress; 4356 }4357 4370 4358 4371 return rc; … … 4471 4484 4472 4485 /* setup task object to carry out the operation asynchronously */ 4473 std::auto_ptr<Medium::Task> task(new CreateDiffTask(this, progress, 4474 aTarget, aVariant)); 4475 AssertComRCReturnRC(task->rc()); 4486 Medium::Task *pTask(new Medium::CreateDiffTask(this, progress, aTarget, 4487 aVariant)); 4488 rc = pTask->rc(); 4489 if (FAILED(rc)) 4490 { 4491 AssertComRC(rc); 4492 delete pTask; 4493 return rc; 4494 } 4476 4495 4477 4496 /* register a task (it will deregister itself when done) */ … … 4489 4508 alock.release(); 4490 4509 4491 rc = runNow(task, pfNeedsSaveSettings); 4510 rc = runNow(pTask, pfNeedsSaveSettings); 4511 if (FAILED(rc)) return rc; 4492 4512 } 4493 4513 else 4494 4514 { 4495 rc = startThread( task);4515 rc = startThread(pTask); 4496 4516 if (FAILED(rc)) return rc; 4497 4517 … … 4501 4521 4502 4522 if (aProgress != NULL) 4503 {4504 /* return progress to the caller */4505 4523 *aProgress = progress; 4506 }4507 4524 4508 4525 return rc; … … 4722 4739 4723 4740 /* setup task object to carry out the operation asynchronously */ 4724 std::auto_ptr<Medium::Task> task(new MergeTask(this, progress, aChain)); 4725 AssertComRCReturnRC(task->rc()); 4741 Medium::Task *pTask(new Medium::MergeTask(this, progress, aChain)); 4742 rc = pTask->rc(); 4743 if (FAILED(rc)) 4744 { 4745 AssertComRC(rc); 4746 delete pTask; 4747 return rc; 4748 } 4726 4749 4727 4750 /* Note: task owns aChain (will delete it when not needed) in all cases … … 4732 4755 if (aWait) 4733 4756 { 4734 rc = runNow(task, pfNeedsSaveSettings); 4757 rc = runNow(pTask, pfNeedsSaveSettings); 4758 if (FAILED(rc)) return rc; 4735 4759 } 4736 4760 else 4737 4761 { 4738 rc = startThread( task);4762 rc = startThread(pTask); 4739 4763 if (FAILED(rc)) return rc; 4740 4764 } 4741 4765 4742 4766 if (aProgress != NULL) 4743 {4744 /* return progress to the caller */4745 4767 *aProgress = progress; 4746 }4747 4768 4748 4769 return rc; … … 5019 5040 * Starts a new thread driven by the appropriate Medium::Task::handler() method. 5020 5041 * 5021 * @note if this method returns success, this Medium::Task object becomes owned5022 * by the started thread and will be automatically deleted when the5023 * thread terminates.5024 *5025 5042 * @note When the task is executed by this method, IProgress::notifyComplete() 5026 5043 * is automatically called for the progress object associated with this … … 5028 5045 * other threads asynchronously waiting for it. 5029 5046 */ 5030 HRESULT Medium::startThread( std::auto_ptr<Medium::Task> task)5047 HRESULT Medium::startThread(Medium::Task *pTask) 5031 5048 { 5032 5049 /// @todo use a more descriptive task name 5033 int vrc = RTThreadCreate(NULL, Medium::Task::fntMediumTask, &task,5050 int vrc = RTThreadCreate(NULL, Medium::Task::fntMediumTask, pTask, 5034 5051 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, 5035 5052 "Medium::Task"); 5036 ComAssertMsgRCRet(vrc, 5037 ("Could not create Medium::Task thread (%Rrc)\n", vrc), 5038 E_FAIL); 5053 if (RT_FAILURE(vrc)) 5054 { 5055 delete pTask; 5056 ComAssertMsgRCRet(vrc, 5057 ("Could not create Medium::Task thread (%Rrc)\n", 5058 vrc), 5059 E_FAIL); 5060 } 5039 5061 5040 5062 return S_OK; … … 5049 5071 * operations are potentially lengthy and will block the calling thread in this 5050 5072 * case. 5051 *5052 * @note This Medium::Task object will be deleted when this method returns.5053 5073 * 5054 5074 * @note When the task is executed by this method, IProgress::notifyComplete() … … 5058 5078 * complete the progress object in this case. 5059 5079 */ 5060 HRESULT Medium::runNow( std::auto_ptr<Medium::Task> task,5080 HRESULT Medium::runNow(Medium::Task *pTask, 5061 5081 bool *pfNeedsSaveSettings) 5062 5082 { 5063 task->m_pfNeedsSaveSettings = pfNeedsSaveSettings;5083 pTask->m_pfNeedsSaveSettings = pfNeedsSaveSettings; 5064 5084 5065 5085 /* NIL_RTTHREAD indicates synchronous call. */ 5066 return (HRESULT)Medium::Task::fntMediumTask(NIL_RTTHREAD, &task);5086 return (HRESULT)Medium::Task::fntMediumTask(NIL_RTTHREAD, pTask); 5067 5087 } 5068 5088 … … 5077 5097 * @return 5078 5098 */ 5079 HRESULT Medium::taskThreadCreateBase( CreateBaseTask &task)5099 HRESULT Medium::taskThreadCreateBase(Medium::CreateBaseTask &task) 5080 5100 { 5081 5101 HRESULT rc = S_OK; … … 5202 5222 * @return 5203 5223 */ 5204 HRESULT Medium::taskThreadCreateDiff( CreateDiffTask &task)5224 HRESULT Medium::taskThreadCreateDiff(Medium::CreateDiffTask &task) 5205 5225 { 5206 5226 HRESULT rc = S_OK; … … 5385 5405 * @return 5386 5406 */ 5387 HRESULT Medium::taskThreadMerge(Me rgeTask &task)5407 HRESULT Medium::taskThreadMerge(Medium::MergeTask &task) 5388 5408 { 5389 5409 HRESULT rc = S_OK; … … 5657 5677 * @return 5658 5678 */ 5659 HRESULT Medium::taskThreadClone( CloneTask &task)5679 HRESULT Medium::taskThreadClone(Medium::CloneTask &task) 5660 5680 { 5661 5681 HRESULT rc = S_OK; … … 5875 5895 * @return 5876 5896 */ 5877 HRESULT Medium::taskThreadDelete(DeleteTask &task) 5878 { 5897 HRESULT Medium::taskThreadDelete(Medium::DeleteTask &task) 5898 { 5899 NOREF(task); 5879 5900 HRESULT rc = S_OK; 5880 5901 … … 5940 5961 * @return 5941 5962 */ 5942 HRESULT Medium::taskThreadReset( ResetTask &task)5963 HRESULT Medium::taskThreadReset(Medium::ResetTask &task) 5943 5964 { 5944 5965 HRESULT rc = S_OK; … … 6050 6071 * @return 6051 6072 */ 6052 HRESULT Medium::taskThreadCompact( CompactTask &task)6073 HRESULT Medium::taskThreadCompact(Medium::CompactTask &task) 6053 6074 { 6054 6075 HRESULT rc = S_OK; -
trunk/src/VBox/Main/include/MediumImpl.h
r27803 r27831 318 318 friend class MergeTask; 319 319 320 HRESULT startThread( std::auto_ptr<Task> task);321 HRESULT runNow( std::auto_ptr<Task> task, bool *pfNeedsSaveSettings);322 323 HRESULT taskThreadCreateBase( CreateBaseTask &task);324 HRESULT taskThreadCreateDiff( CreateDiffTask &task);325 HRESULT taskThreadMerge(Me rgeTask &task);326 HRESULT taskThreadClone( CloneTask &task);327 HRESULT taskThreadDelete( DeleteTask &task);328 HRESULT taskThreadReset( ResetTask &task);329 HRESULT taskThreadCompact( CompactTask &task);320 HRESULT startThread(Medium::Task *pTask); 321 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings); 322 323 HRESULT taskThreadCreateBase(Medium::CreateBaseTask &task); 324 HRESULT taskThreadCreateDiff(Medium::CreateDiffTask &task); 325 HRESULT taskThreadMerge(Medium::MergeTask &task); 326 HRESULT taskThreadClone(Medium::CloneTask &task); 327 HRESULT taskThreadDelete(Medium::DeleteTask &task); 328 HRESULT taskThreadReset(Medium::ResetTask &task); 329 HRESULT taskThreadCompact(Medium::CompactTask &task); 330 330 331 331 struct Data; // opaque data struct, defined in MediumImpl.cpp
Note:
See TracChangeset
for help on using the changeset viewer.