VirtualBox

Changeset 39568 in vbox for trunk/src/VBox/GuestHost/OpenGL


Ignore:
Timestamp:
Dec 9, 2011 1:52:31 PM (13 years ago)
Author:
vboxsync
Message:

crOpenGL: more threading fixes

Location:
trunk/src/VBox/GuestHost/OpenGL
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h

    r39507 r39568  
    4646#include "spu_dispatch_table.h"
    4747
     48#ifdef CHROMIUM_THREADSAFE
     49#include "cr_threads.h"
     50#endif
     51
    4852#include <iprt/cdefs.h>
    4953
     
    129133     * => Thread2 still refers to destroyed ctx1
    130134     * */
    131     /* number of threads that have context set as current */
    132     volatile int cRefs;
     135    CRTSDREFDATA
    133136#endif
    134137
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_threads.h

    r15532 r39568  
    2525#endif
    2626
    27 
     27#include <iprt/asm.h>
    2828/*
    2929 * Handle for Thread-Specific Data
     
    101101extern DECLEXPORT(void) crSignalSemaphore(CRsemaphore *s);
    102102
     103typedef DECLCALLBACK(void) FNCRTSDREFDTOR(void*);
     104typedef FNCRTSDREFDTOR *PFNCRTSDREFDTOR;
    103105
     106typedef enum {
     107    CRTSDREFDATA_STATE_UNDEFINED = 0,
     108    CRTSDREFDATA_STATE_INITIALIZED,
     109    CRTSDREFDATA_STATE_TOBE_DESTROYED,
     110    CRTSDREFDATA_STATE_DESTROYING,
     111    CRTSDREFDATA_STATE_32BIT_HACK = 0x7fffffff
     112} CRTSDREFDATA_STATE;
     113
     114#define CRTSDREFDATA \
     115    volatile uint32_t cTsdRefs; \
     116    uint32_t enmTsdRefState; \
     117    PFNCRTSDREFDTOR pfnTsdRefDtor; \
     118
     119#define crTSDRefInit(_p, _pfnDtor) do { \
     120        (_p)->cTsdRefs = 1; \
     121        (_p)->enmTsdRefState = CRTSDREFDATA_STATE_INITIALIZED; \
     122        (_p)->pfnTsdRefDtor = (_pfnDtor); \
     123    } while (0)
     124
     125#define crTSDRefIsFunctional(_p) (!!((_p)->enmTsdRefState == CRTSDREFDATA_STATE_INITIALIZED))
     126
     127#define crTSDRefAddRef(_p) do { \
     128        int cRefs = ASMAtomicIncS32(&(_p)->cTsdRefs); \
     129        CRASSERT(cRefs > 1 || (_p)->enmTsdRefState == CRTSDREFDATA_STATE_DESTROYING); \
     130    } while (0)
     131
     132#define crTSDRefRelease(_p) do { \
     133        int cRefs = ASMAtomicDecS32(&(_p)->cTsdRefs); \
     134        CRASSERT(cRefs >= 0); \
     135        if (!cRefs && (_p)->enmTsdRefState != CRTSDREFDATA_STATE_DESTROYING /* <- avoid recursion if crTSDRefAddRef/Release is called from dtor */) { \
     136            (_p)->enmTsdRefState = CRTSDREFDATA_STATE_DESTROYING; \
     137            (_p)->pfnTsdRefDtor((_p)); \
     138        } \
     139    } while (0)
     140
     141#define crTSDRefReleaseMarkDestroy(_p) do { \
     142        (_p)->enmTsdRefState = CRTSDREFDATA_STATE_TOBE_DESTROYED; \
     143    } while (0)
     144
     145#define crTSDRefGetCurrent(_t, _pTsd) ((_t*) crGetTSD((_pTsd)))
     146
     147#define crTSDRefSetCurrent(_t, _pTsd, _p) do { \
     148        _t * oldCur = crTSDRefGetCurrent(_t, _pTsd); \
     149        if (oldCur != (_p)) { \
     150            crSetTSD((_pTsd), (_p)); \
     151            if (oldCur) { \
     152                crTSDRefRelease(oldCur); \
     153            } \
     154            if ((_p)) { \
     155                crTSDRefAddRef((_t*)(_p)); \
     156            } \
     157        } \
     158    } while (0)
    104159#ifdef __cplusplus
    105160}
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state.h

    r39507 r39568  
    1111#ifdef CHROMIUM_THREADSAFE
    1212#include "cr_threads.h"
    13 #include <iprt/asm.h>
    1413#endif
    1514
     
    2524#ifdef CHROMIUM_THREADSAFE
    2625extern CRtsd __contextTSD;
    27 #define GetCurrentContext() (CRContext *) crGetTSD(&__contextTSD)
     26#define GetCurrentContext() crTSDRefGetCurrent(CRContext, &__contextTSD)
    2827
    29 /* NOTE: below ref & SetCurrentContext stuff is supposed to be used only internally!!
     28/* NOTE: below SetCurrentContext stuff is supposed to be used only internally!!
    3029 * it is placed here only to simplify things since some code besides state_init.c
    3130 * (i.e. state_glsl.c) is using it */
    32 void crStateFreeContext(CRContext *ctx);
    33 #define CRCONTEXT_ADDREF(_ctx) do { \
    34         int cRefs = ASMAtomicIncS32(&((CRContext*)(_ctx))->cRefs); \
    35         CRASSERT(cRefs > 1); \
    36     } while (0)
    37 #define CRCONTEXT_RELEASE(_ctx) do { \
    38         int cRefs = ASMAtomicDecS32(&((CRContext*)(_ctx))->cRefs); \
    39         CRASSERT(cRefs >= 0); \
    40         if (!cRefs) { \
    41             crStateFreeContext((_ctx)); \
    42         } \
    43     } while (0)
    44 #define SetCurrentContext(_ctx) do { \
    45         CRContext * oldCur = GetCurrentContext(); \
    46         if (oldCur != (_ctx)) { \
    47             if (oldCur) { \
    48                 CRCONTEXT_RELEASE(oldCur); \
    49             } \
    50             if ((_ctx)) { \
    51                 CRCONTEXT_ADDREF(_ctx); \
    52             } \
    53             crSetTSD(&__contextTSD, _ctx); \
    54         } \
    55     } while (0)
     31#define SetCurrentContext(_ctx) crTSDRefSetCurrent(CRContext, &__contextTSD, _ctx)
    5632#else
    5733extern CRContext *__currentContext;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_glsl.c

    r39529 r39568  
    174174      as the current context isn't the one being destroyed*/
    175175#ifdef CHROMIUM_THREADSAFE
    176     CRASSERT(!ctx->cRefs);
    177     ++ctx->cRefs; /* <- this is a hack to avoid subsequent SetCurrentContext(g) do recursive Destroy for ctx */
     176    CRASSERT(g != ctx);
     177    crTSDRefAddRef(ctx); /* <- this is a hack to avoid subsequent SetCurrentContext(g) do recursive Destroy for ctx */
    178178    if (g)
    179         CRCONTEXT_ADDREF(g); /* <- ensure the g is not destroyed by the following SetCurrentContext call */
     179        crTSDRefAddRef(g); /* <- ensure the g is not destroyed by the following SetCurrentContext call */
    180180    SetCurrentContext(ctx);
    181181#else
     
    189189    SetCurrentContext(g);
    190190    if (g)
    191         CRCONTEXT_RELEASE(g);
    192     --ctx->cRefs; /* <- restore back the cRefs (see above) */
     191        crTSDRefRelease(g);
     192    crTSDRefRelease(ctx); /* <- restore back the cRefs (see above) */
    193193#else
    194194    __currentContext = g;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c

    r39507 r39568  
    145145}
    146146
     147#ifdef CHROMIUM_THREADSAFE
     148static void
     149crStateFreeContext(CRContext *ctx);
     150static DECLCALLBACK(void) crStateContextDtor(void *pvCtx)
     151{
     152    crStateFreeContext((CRContext*)pvCtx);
     153}
     154#endif
     155
    147156/*
    148157 * Helper for crStateCreateContext, below.
     
    159168    ctx->id = i;
    160169#ifdef CHROMIUM_THREADSAFE
    161     ctx->cRefs = 1;
     170    crTSDRefInit(ctx, crStateContextDtor);
    162171#endif
    163172    ctx->flush_func = NULL;
     
    261270
    262271/*@todo crStateAttribDestroy*/
    263 void
     272static void
    264273crStateFreeContext(CRContext *ctx)
    265274{
     
    312321#ifdef CHROMIUM_THREADSAFE
    313322        SetCurrentContext(NULL);
    314         CRCONTEXT_RELEASE(defaultContext);
     323        crTSDRefRelease(defaultContext);
    315324#else
    316325        crStateFreeContext(defaultContext);
     
    448457
    449458#ifdef CHROMIUM_THREADSAFE
    450     CRCONTEXT_RELEASE(ctx);
     459    crTSDRefRelease(ctx);
    451460#else
    452461    crStateFreeContext(ctx);
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