VirtualBox

Changeset 75539 in vbox for trunk/src/VBox/Main/include


Ignore:
Timestamp:
Nov 17, 2018 2:35:23 AM (6 years ago)
Author:
vboxsync
Message:

Main/HGCM: Skip the handle stuff for the HGCMThread class, it just add overhead. bugref:9172

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

Legend:

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

    r75535 r75539  
    4040} HGCMOBJ_TYPE;
    4141
    42 class HGCMObject
     42
     43/**
     44 * A referenced object.
     45 */
     46class HGCMReferencedObject
     47{
     48    private:
     49        int32_t volatile m_cRefs;
     50        HGCMOBJ_TYPE     m_enmObjType;
     51
     52    protected:
     53        virtual ~HGCMReferencedObject()
     54        {}
     55
     56    public:
     57        HGCMReferencedObject(HGCMOBJ_TYPE enmObjType)
     58            : m_cRefs(0)
     59            , m_enmObjType(enmObjType)
     60        {}
     61
     62        void Reference()
     63        {
     64            int32_t cRefs = ASMAtomicIncS32(&m_cRefs);
     65            NOREF(cRefs);
     66            Log(("Reference: cRefs = %d\n", cRefs));
     67        }
     68
     69        void Dereference()
     70        {
     71            int32_t cRefs = ASMAtomicDecS32(&m_cRefs);
     72            Log(("Dereference: cRefs = %d\n", cRefs));
     73            AssertRelease(cRefs >= 0);
     74
     75            if (cRefs)
     76            { /* likely */ }
     77            else
     78                delete this;
     79        }
     80
     81        HGCMOBJ_TYPE Type()
     82        {
     83            return m_enmObjType;
     84        }
     85};
     86
     87
     88class HGCMObject : public HGCMReferencedObject
    4389{
    4490    private:
    4591        friend uint32_t hgcmObjMake(HGCMObject *pObject, uint32_t u32HandleIn);
    46 
    47         int32_t volatile m_cRefs;
    48         HGCMOBJ_TYPE     m_enmObjType;
    4992
    5093        ObjectAVLCore   m_core;
     
    5699    public:
    57100        HGCMObject(HGCMOBJ_TYPE enmObjType)
    58             : m_cRefs(0)
    59         {
    60             this->m_enmObjType  = enmObjType;
    61         }
    62 
    63         void Reference()
    64         {
    65             int32_t refCnt = ASMAtomicIncS32(&m_cRefs);
    66             NOREF(refCnt);
    67             Log(("Reference: refCnt = %d\n", refCnt));
    68         }
    69 
    70         void Dereference()
    71         {
    72             int32_t refCnt = ASMAtomicDecS32(&m_cRefs);
    73 
    74             Log(("Dereference: refCnt = %d\n", refCnt));
    75 
    76             AssertRelease(refCnt >= 0);
    77 
    78             if (refCnt)
    79             {
    80                 return;
    81             }
    82 
    83             delete this;
    84         }
     101            : HGCMReferencedObject(enmObjType)
     102        {}
    85103
    86104        uint32_t Handle()
     
    88106            return (uint32_t)m_core.AvlCore.Key;
    89107        }
    90 
    91         HGCMOBJ_TYPE Type()
    92         {
    93             return m_enmObjType;
    94         }
    95108};
    96109
    97 int hgcmObjInit();
     110int         hgcmObjInit();
     111void        hgcmObjUninit();
    98112
    99 void hgcmObjUninit();
     113uint32_t    hgcmObjGenerateHandle(HGCMObject *pObject);
     114uint32_t    hgcmObjAssignHandle(HGCMObject *pObject, uint32_t u32Handle);
    100115
    101 uint32_t hgcmObjGenerateHandle(HGCMObject *pObject);
    102 uint32_t hgcmObjAssignHandle(HGCMObject *pObject, uint32_t u32Handle);
    103 
    104 void hgcmObjDeleteHandle(uint32_t handle);
     116void        hgcmObjDeleteHandle(uint32_t handle);
    105117
    106118HGCMObject *hgcmObjReference(uint32_t handle, HGCMOBJ_TYPE enmObjType);
     119void        hgcmObjDereference(HGCMReferencedObject *pObject);
    107120
    108 void hgcmObjDereference(HGCMObject *pObject);
     121uint32_t    hgcmObjQueryHandleCount();
     122void        hgcmObjSetHandleCount(uint32_t u32HandleCount);
    109123
    110 uint32_t hgcmObjQueryHandleCount();
    111 void     hgcmObjSetHandleCount(uint32_t u32HandleCount);
    112124
    113125#endif /* !___HGCMOBJECTS__H */
  • trunk/src/VBox/Main/include/HGCMThread.h

    r75503 r75539  
    2323#include "HGCMObjects.h"
    2424
     25/* Forward declaration of the worker thread class. */
     26class HGCMThread;
     27
    2528/** A handle for HGCM message. */
    2629typedef uint32_t HGCMMSGHANDLE;
    2730
    2831/** A handle for HGCM worker threads. */
    29 typedef uint32_t HGCMTHREADHANDLE;
     32typedef class HGCMThread *HGCMTHREADHANDLE;
    3033
    3134/* Forward declaration of message core class. */
     
    4548 * @param pMsgCore  Pointer to just processed message.
    4649 */
    47 typedef DECLCALLBACK(void) HGCMMSGCALLBACK (int32_t result, HGCMMsgCore *pMsgCore);
     50typedef DECLCALLBACK(void) HGCMMSGCALLBACK(int32_t result, HGCMMsgCore *pMsgCore);
    4851typedef HGCMMSGCALLBACK *PHGCMMSGCALLBACK;
    4952
    50 /* Forward declaration of the worker thread class. */
    51 class HGCMThread;
    5253
    5354/** HGCM core message. */
    54 class HGCMMsgCore: public HGCMObject
     55class HGCMMsgCore : public HGCMObject
    5556{
    5657    private:
     
    7172        /** Next element in a message queue. */
    7273        HGCMMsgCore *m_pNext;
    73         /** @todo seems not necessary. Previous element in a message queue. */
     74        /** Previous element in a message queue.
     75         *  @todo seems not necessary. */
    7476        HGCMMsgCore *m_pPrev;
    7577
     
    8082        int32_t m_rcSend;
    8183
    82         void InitializeCore (uint32_t u32MsgId, HGCMTHREADHANDLE hThread);
     84        void InitializeCore(uint32_t u32MsgId, HGCMThread * pThread);
    8385
    8486    protected:
    85         virtual ~HGCMMsgCore ();
     87        virtual ~HGCMMsgCore();
    8688
    8789    public:
    88         HGCMMsgCore () : HGCMObject(HGCMOBJ_MSG) {};
    89 
    90         uint32_t MsgId (void) { return m_u32Msg; };
    91 
    92         HGCMThread *Thread (void) { return m_pThread; };
     90        HGCMMsgCore() : HGCMObject(HGCMOBJ_MSG) {};
     91
     92        uint32_t MsgId(void) { return m_u32Msg; };
     93
     94        HGCMThread *Thread(void) { return m_pThread; };
    9395
    9496        /** Initialize message after it was allocated. */
    95         virtual void Initialize (void) {};
     97        virtual void Initialize(void) {};
    9698
    9799        /** Uninitialize message. */
    98         virtual void Uninitialize (void) {};
     100        virtual void Uninitialize(void) {};
    99101
    100102};
     
    103105/** HGCM worker thread function.
    104106 *
    105  *  @param ThreadHandle  Handle of the thread.
     107 *  @param pThread       The HGCM thread instance.
    106108 *  @param pvUser        User specified thread parameter.
    107109 */
    108 typedef DECLCALLBACK(void) FNHGCMTHREAD (HGCMTHREADHANDLE ThreadHandle, void *pvUser);
     110typedef DECLCALLBACK(void) FNHGCMTHREAD(HGCMThread *pThread, void *pvUser);
    109111typedef FNHGCMTHREAD *PFNHGCMTHREAD;
    110112
     
    119121 * @return VBox error code
    120122 */
    121 int hgcmThreadInit (void);
    122 void hgcmThreadUninit (void);
     123int hgcmThreadInit(void);
     124void hgcmThreadUninit(void);
    123125
    124126
    125127/** Create a HGCM worker thread.
    126128 *
    127  * @param pHandle           Where to store the returned worker thread handle.
     129 * @param ppThread          Where to return the pointer to the worker thread.
    128130 * @param pszThreadName     Name of the thread, needed by runtime.
    129131 * @param pfnThread         The worker thread function.
     
    137139 * @return VBox error code
    138140 */
    139 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser,
    140                       const char *pszStatsSubDir, PUVM pUVM);
     141int hgcmThreadCreate(HGCMThread **ppThread, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser,
     142                     const char *pszStatsSubDir, PUVM pUVM);
    141143
    142144/** Wait for termination of a HGCM worker thread.
    143145 *
    144  * @param handle The HGCM thread handle.
    145  *
    146  * @return VBox error code
    147  */
    148 int hgcmThreadWait (HGCMTHREADHANDLE handle);
     146 * @param pThread       The HGCM thread.  The passed in reference is always
     147 *                      consumed.
     148 *
     149 * @return VBox error code
     150 */
     151int hgcmThreadWait(HGCMThread *pThread);
    149152
    150153/** Allocate a message to be posted to HGCM worker thread.
    151154 *
    152  * @param hThread       Worker thread handle.
     155 * @param pThread       The HGCM worker thread.
    153156 * @param pHandle       Where to store the returned message handle.
    154157 * @param u32MsgId      Message identifier.
     
    157160 * @return VBox error code
    158161 */
    159 int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
     162int hgcmMsgAlloc(HGCMThread *pThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
    160163
    161164/** Post a message to HGCM worker thread.
     
    166169 * @return VBox error code
    167170 */
    168 int hgcmMsgPost (HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback);
     171int hgcmMsgPost(HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback);
    169172
    170173/** Send a message to HGCM worker thread.
     
    175178 * @return VBox error code
    176179 */
    177 int hgcmMsgSend (HGCMMSGHANDLE hMsg);
     180int hgcmMsgSend(HGCMMSGHANDLE hMsg);
    178181
    179182
    180183/* Wait for and get a message.
    181184 *
    182  * @param hThread       The thread handle.
     185 * @param pThread       The HGCM worker thread.
    183186 * @param ppMsg         Where to store returned message pointer.
    184187 *
     
    187190 * @thread worker thread
    188191 */
    189 int hgcmMsgGet (HGCMTHREADHANDLE hThread, HGCMMsgCore **ppMsg);
     192int hgcmMsgGet(HGCMThread *pThread, HGCMMsgCore **ppMsg);
    190193
    191194
     
    199202 * @thread worker thread
    200203 */
    201 void hgcmMsgComplete (HGCMMsgCore *pMsg, int32_t result);
     204void hgcmMsgComplete(HGCMMsgCore *pMsg, int32_t result);
    202205
    203206
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