VirtualBox

Changeset 76066 in vbox


Ignore:
Timestamp:
Dec 7, 2018 10:17:39 PM (6 years ago)
Author:
vboxsync
Message:

VBoxSDS: updates

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxClientListImpl.h

    r71160 r76066  
     1/* $Id$ */
    12/** @file
    2 * VBox Global COM Class definition
    3 */
     3 * Main - VBoxSDS - VirtualBoxClientList.
     4 */
    45
    56/*
     
    2728#include "VirtualBoxClientListWrap.h"
    2829
    29 /**
    30 * The IVirtualBoxClientList implementation.
    31 *
    32 * This class provides COM interface to track and get list of
    33 * API client processes.
    34 *
    35 */
    36 
    3730typedef std::set<LONG> TClientSet;
    3831
    3932class CClientListWatcher;
    4033
     34/**
     35 * The IVirtualBoxClientList implementation.
     36 *
     37 * This class provides COM interface to track and get list of
     38 * API client processes.
     39 */
    4140class ATL_NO_VTABLE VirtualBoxClientList
    4241    : public VirtualBoxClientListWrap
     
    5150
    5251public:
    53     DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClientList)
     52    DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClientList) /**< r=bird: It is _NOT_ a singleton. */
    5453    DECLARE_NOT_AGGREGATABLE(VirtualBoxClientList)
    5554    VirtualBoxClientList() : m_pWatcher(NULL) {}
     
    6665    // Private members
    6766    // polling of unexpectedly finished api client processes
    68     CClientListWatcher* m_pWatcher;
     67    CClientListWatcher *m_pWatcher;
    6968};
    7069
     
    7271
    7372#endif // !____H_VIRTUALBOXCLIENTLISTIMPL
     73
  • trunk/src/VBox/Main/include/VirtualBoxSDSImpl.h

    r76065 r76066  
    7171private:
    7272
    73     // IVirtualBoxSDS methods
     73    /** @name IVirtualBoxSDS methods
     74     * @{ */
    7475    STDMETHOD(RegisterVBoxSVC)(IVBoxSVCRegistration *aVBoxSVC, LONG aPid, IUnknown **aExistingVirtualBox);
    7576    STDMETHOD(DeregisterVBoxSVC)(IVBoxSVCRegistration *aVBoxSVC, LONG aPid);
    76     STDMETHOD(NotifyClientsFinished)();
     77    STDMETHOD(NotifyClientsFinished)(); /**< @todo r=bird: Internal within SDS! Make private. */
     78    /** @} */
    7779
    7880
    79     // Private methods
    80 
     81    /** @name Private methods
     82     * @{ */
    8183    /**
    8284     * Gets the client user SID of the
     
    100102     */
    101103    VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername);
     104    /** @} */
    102105};
    103106
  • trunk/src/VBox/Main/src-global/VirtualBoxSDSImpl.cpp

    r76065 r76066  
    165165            {
    166166                /*
    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.
    169170                 */
    170171                if (pUserData->m_ptrTheChosenOne.isNotNull())
     
    181182                    if (FAILED_DEAD_INTERFACE(hrc))
    182183                    {
    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));
    184185                        pUserData->m_ptrTheChosenOne.setNull();
    185186
     
    201202                    try
    202203                    {
    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;
    210207                        if (SUCCEEDED(hrc))
    211208                        {
     
    238235}
    239236
     237
    240238STDMETHODIMP VirtualBoxSDS::DeregisterVBoxSVC(IVBoxSVCRegistration *aVBoxSVC, LONG aPid)
    241239{
    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));
    243241    HRESULT hrc;
    244242    if (RT_VALID_PTR(aVBoxSVC))
     
    257255                            pUserData->m_strUserSid.c_str(), pUserData->m_strUsername.c_str()));
    258256                    pUserData->m_ptrTheChosenOne.setNull();
    259                     /** @todo consider evicting the user from the table...   */
    260257                    /* Release the client list and stop client list watcher thread*/
    261258                    pUserData->m_ptrClientList.setNull();
     
    293290    if (RT_SUCCESS(vrc))
    294291    {
     292/** @todo r=bird: Why notify all VBoxSVC instances?  That makes zero sense!   */
    295293        for (UserDataMap_T::iterator it = m_UserDataMap.begin(); it != m_UserDataMap.end(); ++it)
    296294        {
     
    298296            if (pUserData && pUserData->m_ptrTheChosenOne)
    299297            {
     298                /*
     299                 * Notify VBoxSVC about finishing all API clients it should free
     300                 * references to VBoxSDS and clean up itself
     301                 */
    300302                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())
    304304                    pUserData->m_ptrClientList.setNull();
     305
    305306                pUserData->m_ptrTheChosenOne->NotifyClientsFinished();
    306307            }
  • trunk/src/VBox/Main/src-global/win/VirtualBoxClientListImpl.cpp

    r76064 r76066  
    1717
    1818
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
    1922#include "Logging.h"
    2023#include "VirtualBoxClientListImpl.h"
     
    2427
    2528
    26 ////////////////// CClientListWatcher implementation /////////////////
     29/*********************************************************************************************************************************
     30*   CClientListWatcher                                                                                                           *
     31*********************************************************************************************************************************/
    2732
    2833/**
     
    4146
    4247protected:
    43     static DECLCALLBACK(int) WatcherWorker(RTTHREAD ThreadSelf, void *pvUser);
     48    static DECLCALLBACK(int) WatcherThreadProc(RTTHREAD hThreadSelf, void *pvUser);
    4449    void NotifySDSAllClientsFinished();
    45     // s_WatcherThread is static to check that single watcher thread used only
    46     static volatile RTTHREAD    s_WatcherThread;
     50
    4751    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;
    5158};
    5259
    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
     61volatile RTTHREAD CClientListWatcher::s_hThreadWatcher = NIL_RTTHREAD;
     62
     63
     64CClientListWatcher::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)
    6170    {
    6271        LogRelFunc(("Error: Watcher thread already created!\n"));
     
    6473    }
    6574
    66     int rc = RTSemEventCreate(&m_wakeUpWatcherEvent);
     75    int rc = RTSemEventCreate(&m_hEvtWakeUpWatcher);
    6776    if (RT_FAILURE(rc))
    6877    {
     
    7180    }
    7281
    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,
    7686                        this, // pVUser
    7787                        0,    // cbStack
     
    8292    if (RT_SUCCESS(rc))
    8393    {
    84         ASMAtomicWritePtr((void* volatile*)&CClientListWatcher::s_WatcherThread, watcherThread);
     94        ASMAtomicWriteHandle(&CClientListWatcher::s_hThreadWatcher, hThreadWatcher);
    8595        LogRelFunc(("Created client list watcher thread.\n"));
    8696    }
    8797    else
     98    {
     99        ASMAtomicWriteBool(&m_fWatcherRunning, false);
    88100        LogRelFunc(("Failed to create client list watcher thread: %Rrs\n", rc));
     101    }
    89102}
    90103
     
    96109
    97110    // 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);
    102115    if (RT_FAILURE(rc))
    103116        LogRelFunc(("Error: watcher thread didn't finished. Possible thread leak. %Rrs\n", rc));
     
    105118        LogRelFunc(("Watcher thread finished.\n"));
    106119
    107     ASMAtomicWriteNullPtr((void* volatile*)&CClientListWatcher::s_WatcherThread);
    108 
    109     RTSemEventDestroy(m_wakeUpWatcherEvent);
     120    ASMAtomicWriteHandle(&CClientListWatcher::s_hThreadWatcher, NIL_RTTHREAD);
     121
     122    RTSemEventDestroy(m_hEvtWakeUpWatcher);
    110123}
    111124
     
    121134{
    122135    ComPtr<IVirtualBoxSDS> ptrVirtualBoxSDS;
     136
    123137    /*
    124     * Connect to VBoxSDS.
    125     */
     138     * Connect to VBoxSDS.
     139     */
    126140    HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxSDS, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxSDS,
    127141                                   (void **)ptrVirtualBoxSDS.asOutParam());
     
    136150/**
    137151 * Deregister all staled VBoxSVC through VBoxSDS and forcebly close VBoxSVC process
    138  * @param   ThreadSelf  current thread id
     152 * @param   hThreadSelf The thread handle.
    139153 * @param   pvUser      pointer to CClientListWatcher that created this thread.
    140154 */
    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 
     155DECLCALLBACK(int) CClientListWatcher::WatcherThreadProc(RTTHREAD hThreadSelf, void *pvUser)
     156{
     157    LogRelFunc(("Enter watcher thread (%p)\n", hThreadSelf)); NOREF(hThreadSelf);
    151158    CClientListWatcher *pThis = (CClientListWatcher *)pvUser;
    152159    Assert(pThis);
    153160
    154     ASMAtomicWriteBool(&pThis->m_fWatcherRunning, true);
    155 
    156161    while (ASMAtomicReadBool(&pThis->m_fWatcherRunning))
    157162    {
    158163        /* remove finished API clients from list */
    159         int rc = RTCritSectRwEnterShared(&pThis->m_clientListCritSect);
     164        int rc = RTCritSectRwEnterShared(&pThis->m_rClientListCritSect);
    160165        Assert(RT_SUCCESS(rc));
    161166        NOREF(rc);
     
    195200        }
    196201
    197         rc = RTCritSectRwLeaveShared(&pThis->m_clientListCritSect);
     202        rc = RTCritSectRwLeaveShared(&pThis->m_rClientListCritSect);
    198203        Assert(RT_SUCCESS(rc));
    199204
     
    205210 * you could wait on the first 63 client processes here in addition to the event.
    206211 * That would speed up the response time. */
    207         RTSemEventWait(pThis->m_wakeUpWatcherEvent, 2000);
     212        RTSemEventWait(pThis->m_hEvtWakeUpWatcher, 2000);
    208213    }
    209214    LogRelFunc(("Finish watcher thread.  Client list size: %d\n", pThis->m_clientList.size()));
    210215    return 0;
    211216}
     217
     218
     219
     220/*********************************************************************************************************************************
     221*   VirtualBoxClientList                                                                                                         *
     222*********************************************************************************************************************************/
    212223
    213224///////////////////////// VirtualBoxClientList implementation //////////////////////////
     
    300311            aPids.assign(m_ClientSet.begin(), m_ClientSet.end());
    301312        }
    302         catch (std::bad_alloc)
     313        catch (std::bad_alloc &)
    303314        {
    304315            RTCritSectRwLeaveShared(&m_MapCritSect);
  • trunk/src/VBox/Main/src-server/win/svcmain.cpp

    r73919 r76066  
    443443    {
    444444        LogRelFunc(("All clients gone - shutdown sequence initiated\n"));
    445         if(m_pFactory)
     445        if (m_pFactory)
    446446            m_pFactory->i_finishVBoxSvc();
    447447
    448448        // This is not enough to finish VBoxSvc such as reference to crashed client still is in action
    449449        // 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"));
    453456        return S_OK;
    454457    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette