Changeset 58004 in vbox
- Timestamp:
- Oct 2, 2015 10:39:07 AM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ConsoleImpl.h
r58002 r58004 563 563 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap; 564 564 typedef std::list <USBStorageDevice> USBStorageDeviceList; 565 566 static DECLCALLBACK(int) i_powerUpThread(RTTHREAD Thread, void *pvUser); 567 static DECLCALLBACK(int) i_powerDownThread(RTTHREAD Thread, void *pvUser); 565 568 566 569 private: … … 739 742 void i_detachAllUSBDevices(bool aDone); 740 743 741 static DECLCALLBACK(int) i_powerUpThread(RTTHREAD Thread, void *pvUser);742 static DECLCALLBACK(int) i_powerDownThread(RTTHREAD Thread, void *pvUser);743 744 744 745 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM); -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r58002 r58004 73 73 #include "AutoCaller.h" 74 74 #include "Logging.h" 75 #include "ThreadTask.h" 75 76 76 77 #include <VBox/com/array.h> … … 150 151 * Console::addVMCaller() for more info. 151 152 */ 152 struct VMTask 153 { 153 class VMTask: public ThreadTask 154 { 155 public: 154 156 VMTask(Console *aConsole, 155 157 Progress *aProgress, 156 158 const ComPtr<IProgress> &aServerProgress, 157 159 bool aUsesVMPtr) 158 : mConsole(aConsole), 160 : ThreadTask("GenericVMTask"), 161 mConsole(aConsole), 159 162 mConsoleCaller(aConsole), 160 163 mProgress(aProgress), … … 175 178 } 176 179 177 ~VMTask()180 virtual ~VMTask() 178 181 { 179 182 releaseVMCaller(); … … 205 208 206 209 207 struct VMPowerUpTask : public VMTask 208 { 210 class VMPowerUpTask : public VMTask 211 { 212 public: 209 213 VMPowerUpTask(Console *aConsole, 210 214 Progress *aProgress) … … 215 219 mTeleporterEnabled(FALSE), 216 220 mEnmFaultToleranceState(FaultToleranceState_Inactive) 217 {} 221 { 222 m_strTaskName = "VMPwrUp"; 223 } 218 224 219 225 PFNCFGMCONSTRUCTOR mConfigConstructor; … … 227 233 typedef std::list<ComPtr<IProgress> > ProgressList; 228 234 ProgressList hardDiskProgresses; 235 236 void handler() 237 { 238 int vrc = Console::i_powerUpThread(NULL, this); 239 } 240 229 241 }; 230 242 231 struct VMPowerDownTask : public VMTask 232 { 243 class VMPowerDownTask : public VMTask 244 { 245 public: 233 246 VMPowerDownTask(Console *aConsole, 234 247 const ComPtr<IProgress> &aServerProgress) 235 248 : VMTask(aConsole, NULL /* aProgress */, aServerProgress, 236 249 true /* aUsesVMPtr */) 237 {} 250 { 251 m_strTaskName = "VMPwrDwn"; 252 } 253 254 void handler() 255 { 256 int vrc = Console::i_powerDownThread(NULL, this); 257 } 238 258 }; 239 259 … … 2093 2113 Global::stringifyMachineState(mMachineState)); 2094 2114 } 2095 2096 2115 LogFlowThisFunc(("Initiating SHUTDOWN request...\n")); 2097 2116 … … 2136 2155 try 2137 2156 { 2138 /* Setup task object and thread to carry out the operation asynchronously.2139 * We are going to pass ownership of task pointer to another thread.2140 * So we are in charge of deletion this task pointer in case if RTThreadCreate2141 * returns not successful result or in case of any exception2142 */2143 2144 2157 task = new VMPowerDownTask(this, pProgress); 2145 AssertBreakStmt(task->isOk(), rc = E_FAIL); 2146 int vrc = RTThreadCreate(NULL, Console::i_powerDownThread, 2147 (void *) task, 0, 2148 RTTHREADTYPE_MAIN_WORKER, 0, 2149 "VMPwrDwn"); 2150 if (RT_FAILURE(vrc)) 2158 if (!task->isOk()) 2151 2159 { 2152 rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc); 2153 break; 2160 throw E_FAIL; 2154 2161 } 2155 /* task is now owned by powerDownThread(), so release it */ 2156 //task.release(); 2157 } 2158 catch(const std::exception &e) 2159 { 2160 rc = setError(E_FAIL, "Cought exception! Could not create VMPowerDown thread (%s)", e.what()); 2162 } 2163 catch(...) 2164 { 2165 delete task; 2166 rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n"); 2161 2167 break; 2162 2168 } 2169 2170 rc = task->createThread(); 2163 2171 2164 2172 /* pass the progress to the caller */ … … 2169 2177 if (FAILED(rc)) 2170 2178 { 2171 if (task != NULL)2172 {2173 //we can delete this pointer because something2174 //was wrong and we hadn't passed pointer to another thread2175 LogFlowFunc(("Delete task VMPowerDownTask from Console::powerDown()\n"));2176 delete task;2177 }2178 2179 /* preserve existing error info */ 2179 2180 ErrorInfoKeeper eik; … … 6978 6979 HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused) 6979 6980 { 6980 6981 6981 LogFlowThisFuncEnter(); 6982 6982 … … 6995 6995 LONG cOperations = 1; 6996 6996 LONG ulTotalOperationsWeight = 1; 6997 VMPowerUpTask* task = NULL; 6997 6998 6998 6999 try … … 7113 7114 /* Setup task object and thread to carry out the operation 7114 7115 * asynchronously */ 7115 std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress)); 7116 ComAssertComRCRetRC(task->rc()); 7116 try 7117 { 7118 task = new VMPowerUpTask(this, pPowerupProgress); 7119 if (!task->isOk()) 7120 { 7121 throw E_FAIL; 7122 } 7123 } 7124 catch(...) 7125 { 7126 delete task; 7127 rc = setError(E_FAIL, "Could not create VMPowerUpTask object \n"); 7128 throw rc; 7129 } 7117 7130 7118 7131 task->mConfigConstructor = i_configConstructor; … … 7372 7385 #endif // 0 7373 7386 7387 7374 7388 /* setup task object and thread to carry out the operation 7375 7389 * asynchronously */ … … 7379 7393 } 7380 7394 7381 int vrc = RTThreadCreate(NULL, Console::i_powerUpThread, 7382 (void *)task.get(), 0, 7383 RTTHREADTYPE_MAIN_WORKER, 0, "VMPwrUp"); 7384 if (RT_FAILURE(vrc)) 7385 throw setError(E_FAIL, "Could not create VMPowerUp thread (%Rrc)", vrc); 7386 7387 /* task is now owned by powerUpThread(), so release it */ 7388 task.release(); 7395 rc = task->createThread(); 7396 7397 if (FAILED(rc)) 7398 throw rc; 7389 7399 7390 7400 /* finally, set the state: no right to fail in this method afterwards … … 8253 8263 if (!task->isOk()) 8254 8264 { 8255 LogFlowFunc(("Console is already being uninitialized.\n")); 8256 } 8257 else 8258 { 8259 /* 8260 * We are going to pass ownership of task pointer to another thread. 8261 * So we are in charge of deletion this task pointer in case if RTThreadCreate 8262 * returns not successful result or in case of any exception 8263 */ 8264 int vrc = RTThreadCreate(NULL, Console::i_powerDownThread, 8265 (void *) task, 0, 8266 RTTHREADTYPE_MAIN_WORKER, 0, 8267 "VMPwrDwn"); 8268 if (RT_FAILURE(vrc)) 8269 { 8270 rc = E_FAIL; 8271 LogFlowFunc(("Could not create VMPowerDown thread (%Rrc)\n", vrc)); 8272 } 8265 LogFlowFunc(("Console is already being uninitialized. \n")); 8266 throw E_FAIL; 8273 8267 } 8274 8268 } 8275 catch( const std::exception &e)8269 catch(...) 8276 8270 { 8277 rc = E_FAIL;8278 LogFlowFunc((" Cought exception! Could not create VMPowerDown thread (%s)\n", e.what()));8271 delete task; 8272 LogFlowFunc(("Problem with creating VMPowerDownTask object. \n")); 8279 8273 } 8280 8274 8281 if(FAILED(rc) || !task->isOk()) 8275 rc = task->createThread(); 8276 8277 if (FAILED(rc)) 8282 8278 { 8283 LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n")); 8284 delete task; 8279 LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n")); 8285 8280 } 8281 8286 8282 } 8287 8283 break; … … 9441 9437 LogFlowFuncEnter(); 9442 9438 9443 std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser));9444 AssertReturn(task .get(), VERR_INVALID_PARAMETER);9439 VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser); 9440 AssertReturn(task, VERR_INVALID_PARAMETER); 9445 9441 9446 9442 AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER); … … 10007 10003 } 10008 10004 10009 LogFlowFunc(("Delete task VMPowerDownTask from Console::i_powerDownThread()\n"));10010 delete task;10011 10005 LogFlowFuncLeave(); 10012 10006 return rc; 10013 10007 } 10014 10015 10008 10016 10009 /**
Note:
See TracChangeset
for help on using the changeset viewer.