Changeset 76066 in vbox
- Timestamp:
- Dec 7, 2018 10:17:39 PM (6 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
-
include/VirtualBoxClientListImpl.h (modified) (5 diffs)
-
include/VirtualBoxSDSImpl.h (modified) (2 diffs)
-
src-global/VirtualBoxSDSImpl.cpp (modified) (7 diffs)
-
src-global/win/VirtualBoxClientListImpl.cpp (modified) (13 diffs)
-
src-server/win/svcmain.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/VirtualBoxClientListImpl.h
r71160 r76066 1 /* $Id$ */ 1 2 /** @file 2 * VBox Global COM Class definition 3 */3 * Main - VBoxSDS - VirtualBoxClientList. 4 */ 4 5 5 6 /* … … 27 28 #include "VirtualBoxClientListWrap.h" 28 29 29 /**30 * The IVirtualBoxClientList implementation.31 *32 * This class provides COM interface to track and get list of33 * API client processes.34 *35 */36 37 30 typedef std::set<LONG> TClientSet; 38 31 39 32 class CClientListWatcher; 40 33 34 /** 35 * The IVirtualBoxClientList implementation. 36 * 37 * This class provides COM interface to track and get list of 38 * API client processes. 39 */ 41 40 class ATL_NO_VTABLE VirtualBoxClientList 42 41 : public VirtualBoxClientListWrap … … 51 50 52 51 public: 53 DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClientList) 52 DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClientList) /**< r=bird: It is _NOT_ a singleton. */ 54 53 DECLARE_NOT_AGGREGATABLE(VirtualBoxClientList) 55 54 VirtualBoxClientList() : m_pWatcher(NULL) {} … … 66 65 // Private members 67 66 // polling of unexpectedly finished api client processes 68 CClientListWatcher *m_pWatcher;67 CClientListWatcher *m_pWatcher; 69 68 }; 70 69 … … 72 71 73 72 #endif // !____H_VIRTUALBOXCLIENTLISTIMPL 73 -
trunk/src/VBox/Main/include/VirtualBoxSDSImpl.h
r76065 r76066 71 71 private: 72 72 73 // IVirtualBoxSDS methods 73 /** @name IVirtualBoxSDS methods 74 * @{ */ 74 75 STDMETHOD(RegisterVBoxSVC)(IVBoxSVCRegistration *aVBoxSVC, LONG aPid, IUnknown **aExistingVirtualBox); 75 76 STDMETHOD(DeregisterVBoxSVC)(IVBoxSVCRegistration *aVBoxSVC, LONG aPid); 76 STDMETHOD(NotifyClientsFinished)(); 77 STDMETHOD(NotifyClientsFinished)(); /**< @todo r=bird: Internal within SDS! Make private. */ 78 /** @} */ 77 79 78 80 79 / /Private methods80 81 /** @name Private methods 82 * @{ */ 81 83 /** 82 84 * Gets the client user SID of the … … 100 102 */ 101 103 VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername); 104 /** @} */ 102 105 }; 103 106 -
trunk/src/VBox/Main/src-global/VirtualBoxSDSImpl.cpp
r76065 r76066 165 165 { 166 166 /* 167 * If there already is a chosen one, check that it is still around, 168 * replace it with the caller if no response. 167 * If there already is a chosen one, ask it for a IVirtualBox instance 168 * to return to the caller. Should it be dead or unresponsive, the caller 169 * takes its place. 169 170 */ 170 171 if (pUserData->m_ptrTheChosenOne.isNotNull()) … … 181 182 if (FAILED_DEAD_INTERFACE(hrc)) 182 183 { 183 LogRel(("VirtualBoxSDS::registerVBoxSVC: Seems VBoxSVC instance died. Dropping it and letting caller take over. \n"));184 LogRel(("VirtualBoxSDS::registerVBoxSVC: Seems VBoxSVC instance died. Dropping it and letting caller take over. (hrc=%Rhrc)\n", hrc)); 184 185 pUserData->m_ptrTheChosenOne.setNull(); 185 186 … … 201 202 try 202 203 { 203 #if 1 204 hrc = pUserData->m_ptrClientList.createLocalObject(CLSID_VirtualBoxClientList); 205 #else 206 hrc = CoCreateInstance(CLSID_VirtualBoxClientList, NULL, CLSCTX_LOCAL_SERVER, 207 IID_IVirtualBoxClientList, 208 (void **)pUserData->m_ptrClientList.asOutParam()); 209 #endif 204 /// @todo r=bird: Enable when design has been corrected. 205 ///hrc = pUserData->m_ptrClientList.createLocalObject(CLSID_VirtualBoxClientList); 206 hrc = S_OK; 210 207 if (SUCCEEDED(hrc)) 211 208 { … … 238 235 } 239 236 237 240 238 STDMETHODIMP VirtualBoxSDS::DeregisterVBoxSVC(IVBoxSVCRegistration *aVBoxSVC, LONG aPid) 241 239 { 242 LogRel(("VirtualBoxSDS::deregisterVBoxSVC: aVBoxSVC=%p aPid=%u \n", (IVBoxSVCRegistration *)aVBoxSVC, aPid));240 LogRel(("VirtualBoxSDS::deregisterVBoxSVC: aVBoxSVC=%p aPid=%u (%#x)\n", (IVBoxSVCRegistration *)aVBoxSVC, aPid, aPid)); 243 241 HRESULT hrc; 244 242 if (RT_VALID_PTR(aVBoxSVC)) … … 257 255 pUserData->m_strUserSid.c_str(), pUserData->m_strUsername.c_str())); 258 256 pUserData->m_ptrTheChosenOne.setNull(); 259 /** @todo consider evicting the user from the table... */260 257 /* Release the client list and stop client list watcher thread*/ 261 258 pUserData->m_ptrClientList.setNull(); … … 293 290 if (RT_SUCCESS(vrc)) 294 291 { 292 /** @todo r=bird: Why notify all VBoxSVC instances? That makes zero sense! */ 295 293 for (UserDataMap_T::iterator it = m_UserDataMap.begin(); it != m_UserDataMap.end(); ++it) 296 294 { … … 298 296 if (pUserData && pUserData->m_ptrTheChosenOne) 299 297 { 298 /* 299 * Notify VBoxSVC about finishing all API clients it should free 300 * references to VBoxSDS and clean up itself 301 */ 300 302 LogRelFunc(("Notify VBoxSVC that all clients finished\n")); 301 /* Notify VBoxSVC about finishing all API clients it should free references to VBoxSDS 302 and clean up itself */ 303 if (pUserData->m_ptrClientList) 303 if (pUserData->m_ptrClientList.isNotNull()) 304 304 pUserData->m_ptrClientList.setNull(); 305 305 306 pUserData->m_ptrTheChosenOne->NotifyClientsFinished(); 306 307 } -
trunk/src/VBox/Main/src-global/win/VirtualBoxClientListImpl.cpp
r76064 r76066 17 17 18 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 19 22 #include "Logging.h" 20 23 #include "VirtualBoxClientListImpl.h" … … 24 27 25 28 26 ////////////////// CClientListWatcher implementation ///////////////// 29 /********************************************************************************************************************************* 30 * CClientListWatcher * 31 *********************************************************************************************************************************/ 27 32 28 33 /** … … 41 46 42 47 protected: 43 static DECLCALLBACK(int) Watcher Worker(RTTHREADThreadSelf, void *pvUser);48 static DECLCALLBACK(int) WatcherThreadProc(RTTHREAD hThreadSelf, void *pvUser); 44 49 void NotifySDSAllClientsFinished(); 45 // s_WatcherThread is static to check that single watcher thread used only 46 static volatile RTTHREAD s_WatcherThread; 50 47 51 volatile bool m_fWatcherRunning; 48 TClientSet& m_clientList; 49 RTCRITSECTRW& m_clientListCritSect; 50 RTSEMEVENT m_wakeUpWatcherEvent; 52 TClientSet &m_clientList; 53 RTCRITSECTRW &m_rClientListCritSect; 54 RTSEMEVENT m_hEvtWakeUpWatcher; 55 56 /** There is a single watcher thread. */ 57 static volatile RTTHREAD s_hThreadWatcher; 51 58 }; 52 59 53 volatile RTTHREAD CClientListWatcher::s_WatcherThread = NULL; 54 55 CClientListWatcher::CClientListWatcher(TClientSet& list, RTCRITSECTRW& clientListCritSect) 56 : m_clientList(list), m_clientListCritSect(clientListCritSect) 57 { 58 Assert(ASMAtomicReadPtr((void* volatile*)&CClientListWatcher::s_WatcherThread) == NULL); 59 60 if (ASMAtomicReadPtr((void* volatile*)&CClientListWatcher::s_WatcherThread) != NULL) 60 61 volatile RTTHREAD CClientListWatcher::s_hThreadWatcher = NIL_RTTHREAD; 62 63 64 CClientListWatcher::CClientListWatcher(TClientSet &list, RTCRITSECTRW &rClientListCritSect) 65 : m_clientList(list), m_rClientListCritSect(rClientListCritSect) 66 { 67 Assert(ASMAtomicReadPtr((void * volatile *)&CClientListWatcher::s_hThreadWatcher) == NULL); 68 69 if (ASMAtomicReadPtr((void * volatile *)&CClientListWatcher::s_hThreadWatcher) != NULL) 61 70 { 62 71 LogRelFunc(("Error: Watcher thread already created!\n")); … … 64 73 } 65 74 66 int rc = RTSemEventCreate(&m_ wakeUpWatcherEvent);75 int rc = RTSemEventCreate(&m_hEvtWakeUpWatcher); 67 76 if (RT_FAILURE(rc)) 68 77 { … … 71 80 } 72 81 73 RTTHREAD watcherThread; 74 rc = RTThreadCreate(&watcherThread, 75 (PFNRTTHREAD)CClientListWatcher::WatcherWorker, 82 ASMAtomicWriteBool(&m_fWatcherRunning, true); 83 RTTHREAD hThreadWatcher; 84 rc = RTThreadCreate(&hThreadWatcher, 85 (PFNRTTHREAD)CClientListWatcher::WatcherThreadProc, 76 86 this, // pVUser 77 87 0, // cbStack … … 82 92 if (RT_SUCCESS(rc)) 83 93 { 84 ASMAtomicWrite Ptr((void* volatile*)&CClientListWatcher::s_WatcherThread, watcherThread);94 ASMAtomicWriteHandle(&CClientListWatcher::s_hThreadWatcher, hThreadWatcher); 85 95 LogRelFunc(("Created client list watcher thread.\n")); 86 96 } 87 97 else 98 { 99 ASMAtomicWriteBool(&m_fWatcherRunning, false); 88 100 LogRelFunc(("Failed to create client list watcher thread: %Rrs\n", rc)); 101 } 89 102 } 90 103 … … 96 109 97 110 // Wake up watcher thread to finish it faster 98 int rc = RTSemEventSignal(m_ wakeUpWatcherEvent);99 Assert (RT_SUCCESS(rc));100 101 rc = RTThreadWait(CClientListWatcher::s_ WatcherThread, RT_INDEFINITE_WAIT, NULL);111 int rc = RTSemEventSignal(m_hEvtWakeUpWatcher); 112 AssertRC(rc); 113 114 rc = RTThreadWait(CClientListWatcher::s_hThreadWatcher, RT_INDEFINITE_WAIT, NULL); 102 115 if (RT_FAILURE(rc)) 103 116 LogRelFunc(("Error: watcher thread didn't finished. Possible thread leak. %Rrs\n", rc)); … … 105 118 LogRelFunc(("Watcher thread finished.\n")); 106 119 107 ASMAtomicWrite NullPtr((void* volatile*)&CClientListWatcher::s_WatcherThread);108 109 RTSemEventDestroy(m_ wakeUpWatcherEvent);120 ASMAtomicWriteHandle(&CClientListWatcher::s_hThreadWatcher, NIL_RTTHREAD); 121 122 RTSemEventDestroy(m_hEvtWakeUpWatcher); 110 123 } 111 124 … … 121 134 { 122 135 ComPtr<IVirtualBoxSDS> ptrVirtualBoxSDS; 136 123 137 /* 124 * Connect to VBoxSDS.125 */138 * Connect to VBoxSDS. 139 */ 126 140 HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxSDS, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxSDS, 127 141 (void **)ptrVirtualBoxSDS.asOutParam()); … … 136 150 /** 137 151 * Deregister all staled VBoxSVC through VBoxSDS and forcebly close VBoxSVC process 138 * @param ThreadSelf current thread id152 * @param hThreadSelf The thread handle. 139 153 * @param pvUser pointer to CClientListWatcher that created this thread. 140 154 */ 141 DECLCALLBACK(int) CClientListWatcher::WatcherWorker(RTTHREAD ThreadSelf, void *pvUser) 142 { 143 NOREF(ThreadSelf); 144 /** @todo r=bird: This will fail once in a while because you don't know 145 * for sure how the scheduling is going to be. So, RTThreadCreate 146 * may return and set g_hWatcherThread after the thread started 147 * executing and got here! */ 148 Assert(ASMAtomicReadPtr((void* volatile*)&CClientListWatcher::s_WatcherThread)); 149 LogRelFunc(("Enter watcher thread\n")); 150 155 DECLCALLBACK(int) CClientListWatcher::WatcherThreadProc(RTTHREAD hThreadSelf, void *pvUser) 156 { 157 LogRelFunc(("Enter watcher thread (%p)\n", hThreadSelf)); NOREF(hThreadSelf); 151 158 CClientListWatcher *pThis = (CClientListWatcher *)pvUser; 152 159 Assert(pThis); 153 160 154 ASMAtomicWriteBool(&pThis->m_fWatcherRunning, true);155 156 161 while (ASMAtomicReadBool(&pThis->m_fWatcherRunning)) 157 162 { 158 163 /* remove finished API clients from list */ 159 int rc = RTCritSectRwEnterShared(&pThis->m_ clientListCritSect);164 int rc = RTCritSectRwEnterShared(&pThis->m_rClientListCritSect); 160 165 Assert(RT_SUCCESS(rc)); 161 166 NOREF(rc); … … 195 200 } 196 201 197 rc = RTCritSectRwLeaveShared(&pThis->m_ clientListCritSect);202 rc = RTCritSectRwLeaveShared(&pThis->m_rClientListCritSect); 198 203 Assert(RT_SUCCESS(rc)); 199 204 … … 205 210 * you could wait on the first 63 client processes here in addition to the event. 206 211 * That would speed up the response time. */ 207 RTSemEventWait(pThis->m_ wakeUpWatcherEvent, 2000);212 RTSemEventWait(pThis->m_hEvtWakeUpWatcher, 2000); 208 213 } 209 214 LogRelFunc(("Finish watcher thread. Client list size: %d\n", pThis->m_clientList.size())); 210 215 return 0; 211 216 } 217 218 219 220 /********************************************************************************************************************************* 221 * VirtualBoxClientList * 222 *********************************************************************************************************************************/ 212 223 213 224 ///////////////////////// VirtualBoxClientList implementation ////////////////////////// … … 300 311 aPids.assign(m_ClientSet.begin(), m_ClientSet.end()); 301 312 } 302 catch (std::bad_alloc )313 catch (std::bad_alloc &) 303 314 { 304 315 RTCritSectRwLeaveShared(&m_MapCritSect); -
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r73919 r76066 443 443 { 444 444 LogRelFunc(("All clients gone - shutdown sequence initiated\n")); 445 if (m_pFactory)445 if (m_pFactory) 446 446 m_pFactory->i_finishVBoxSvc(); 447 447 448 448 // This is not enough to finish VBoxSvc such as reference to crashed client still is in action 449 449 // So I forcebly shutdown VBoxSvc 450 while (g_pModule->Unlock() > 0) 451 {}; 452 450 LONG cLocks = g_pModule->Unlock(); 451 LogRelFunc(("Unlock -> %d\n", cLocks)); 452 while (cLocks > 0) 453 cLocks = g_pModule->Unlock(); 454 455 LogRelFunc(("returns\n")); 453 456 return S_OK; 454 457 }
Note:
See TracChangeset
for help on using the changeset viewer.

