VirtualBox

Changeset 34642 in vbox for trunk/src


Ignore:
Timestamp:
Dec 2, 2010 6:16:04 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
68444
Message:

Main/VirtualBoxClient: Don't use the singleton factory, as the destruction of the objects is done too late (process termination). Use an instance counter approach, and make sure that only the first instance is actually working.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/VirtualBoxClientImpl.cpp

    r34424 r34642  
    2222#include "Logging.h"
    2323
     24#include <iprt/asm.h>
    2425#include <iprt/thread.h>
    2526#include <iprt/critsect.h>
     
    3233
    3334
     35/** Initialize instance counter class variable */
     36uint32_t VirtualBoxClient::g_cInstances = 0;
     37
     38
    3439// constructor / destructor
    3540/////////////////////////////////////////////////////////////////////////////
     
    6267    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    6368
     69    mData.m_ThreadWatcher = NIL_RTTHREAD;
     70    mData.m_SemEvWatcher = NIL_RTSEMEVENT;
     71
     72    if (ASMAtomicIncU32(&g_cInstances) != 1)
     73        AssertFailedReturn(E_FAIL);
     74
    6475    rc = unconst(mData.m_pVirtualBox).createLocalObject(CLSID_VirtualBox);
    6576    AssertComRCReturnRC(rc);
     
    7384     * is not considered important enough to cause any sort of visible
    7485     * failure. The monitoring will not be done, but that's all. */
    75     mData.m_ThreadWatcher = NIL_RTTHREAD;
    7686    int vrc = RTSemEventCreate(&mData.m_SemEvWatcher);
    7787    AssertRC(vrc);
     
    107117    if (autoUninitSpan.uninitDone())
    108118        return;
    109 
    110     unconst(mData.m_pVirtualBox).setNull();
    111119
    112120    if (mData.m_ThreadWatcher != NIL_RTTHREAD)
     
    121129        mData.m_SemEvWatcher = NIL_RTSEMEVENT;
    122130    }
     131
     132    unconst(mData.m_pVirtualBox).setNull();
     133
     134    ASMAtomicDecU32(&g_cInstances);
    123135}
    124136
  • trunk/src/VBox/Main/include/VirtualBoxClientImpl.h

    r34424 r34642  
    3838    VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBoxClient, IVirtualBoxClient)
    3939
    40     DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxClient)
     40    DECLARE_CLASSFACTORY()
    4141
    4242    DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
     
    6464
    6565private:
     66    /** Instance counter for simulating something similar to a singleton.
     67     * Only the first instance will be a usable object, all additional
     68     * instances will return a failure at creation time and will not work. */
     69    static uint32_t g_cInstances;
    6670
    6771    static DECLCALLBACK(int) SVCWatcherThread(RTTHREAD ThreadSelf, void *pvUser);
Note: See TracChangeset for help on using the changeset viewer.

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