Changeset 39507 in vbox for trunk/src/VBox/GuestHost/OpenGL
- Timestamp:
- Dec 2, 2011 7:44:16 AM (13 years ago)
- Location:
- trunk/src/VBox/GuestHost/OpenGL
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h
r37613 r39507 118 118 struct CRContext { 119 119 int id; 120 121 #ifdef CHROMIUM_THREADSAFE 122 /* we keep reference counting of context's makeCurrent for different threads 123 * this is primarily needed to avoid having an invalid memory reference in the TLS 124 * when the context is assigned to more than one threads and then destroyed from 125 * one of those, i.e. 126 * 1. Thread1 -> MakeCurrent(ctx1); 127 * 2. Thread2 -> MakeCurrent(ctx1); 128 * 3. Thread1 -> Destroy(ctx1); 129 * => Thread2 still refers to destroyed ctx1 130 * */ 131 /* number of threads that have context set as current */ 132 volatile int cRefs; 133 #endif 134 120 135 CRbitvalue bitid[CR_MAX_BITARRAY]; 121 136 CRbitvalue neg_bitid[CR_MAX_BITARRAY]; … … 181 196 DECLEXPORT(void) crStateInit(void); 182 197 DECLEXPORT(void) crStateDestroy(void); 198 DECLEXPORT(void) crStateOnThreadAttachDetach(GLboolean attach); 183 199 DECLEXPORT(CRContext *) crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share); 184 200 DECLEXPORT(CRContext *) crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID); -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state.h
r31808 r39507 11 11 #ifdef CHROMIUM_THREADSAFE 12 12 #include "cr_threads.h" 13 #include <iprt/asm.h> 13 14 #endif 14 15 … … 25 26 extern CRtsd __contextTSD; 26 27 #define GetCurrentContext() (CRContext *) crGetTSD(&__contextTSD) 28 29 /* NOTE: below ref & SetCurrentContext stuff is supposed to be used only internally!! 30 * it is placed here only to simplify things since some code besides state_init.c 31 * (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) 27 56 #else 28 57 extern CRContext *__currentContext; -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_glsl.c
r37773 r39507 174 174 as the current context isn't the one being destroyed*/ 175 175 #ifdef CHROMIUM_THREADSAFE 176 crSetTSD(&__contextTSD, ctx); 176 CRASSERT(g != ctx); 177 CRASSERT(!ctx->cRefs); 178 ++ctx->cRefs; /* <- this is a hack to avoid subsequent SetCurrentContext(g) do recursive Destroy for ctx */ 179 if (g) 180 CRCONTEXT_ADDREF(g); /* <- ensure the g is not destroyed by the following SetCurrentContext call */ 181 SetCurrentContext(ctx); 177 182 #else 178 183 __currentContext = ctx; … … 183 188 184 189 #ifdef CHROMIUM_THREADSAFE 185 crSetTSD(&__contextTSD, g); 190 SetCurrentContext(g); 191 if (g) 192 CRCONTEXT_RELEASE(g); 193 --ctx->cRefs; /* <- restore back the cRefs (see above) */ 186 194 #else 187 195 __currentContext = g; -
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c
r37613 r39507 158 158 159 159 ctx->id = i; 160 #ifdef CHROMIUM_THREADSAFE 161 ctx->cRefs = 1; 162 #endif 160 163 ctx->flush_func = NULL; 161 164 for (j=0;j<CR_MAX_BITARRAY;j++){ … … 258 261 259 262 /*@todo crStateAttribDestroy*/ 260 staticvoid263 void 261 264 crStateFreeContext(CRContext *ctx) 262 265 { … … 307 310 /* Free the default/NULL context. 308 311 * Ensures context bits are reset */ 312 #ifdef CHROMIUM_THREADSAFE 313 SetCurrentContext(NULL); 314 CRCONTEXT_RELEASE(defaultContext); 315 #else 309 316 crStateFreeContext(defaultContext); 310 #ifdef CHROMIUM_THREADSAFE311 crSetTSD(&__contextTSD, NULL);312 #else313 317 __currentContext = NULL; 314 318 #endif … … 324 328 325 329 #ifdef CHROMIUM_THREADSAFE 326 crSetTSD(&__contextTSD,defaultContext);330 SetCurrentContext(defaultContext); 327 331 #else 328 332 __currentContext = defaultContext; … … 434 438 crStateSwitchContext(current, defaultContext); 435 439 #ifdef CHROMIUM_THREADSAFE 436 crSetTSD(&__contextTSD,defaultContext);440 SetCurrentContext(defaultContext); 437 441 #else 438 442 __currentContext = defaultContext; … … 443 447 g_availableContexts[ctx->id] = 0; 444 448 449 #ifdef CHROMIUM_THREADSAFE 450 CRCONTEXT_RELEASE(ctx); 451 #else 445 452 crStateFreeContext(ctx); 453 #endif 446 454 } 447 455 … … 467 475 468 476 #ifdef CHROMIUM_THREADSAFE 469 crSetTSD(&__contextTSD,ctx);477 SetCurrentContext(ctx); 470 478 #else 471 479 __currentContext = ctx; … … 493 501 494 502 #ifdef CHROMIUM_THREADSAFE 495 crSetTSD(&__contextTSD,ctx);503 SetCurrentContext(ctx); 496 504 #else 497 505 __currentContext = ctx; … … 549 557 } 550 558 559 void crStateOnThreadAttachDetach(GLboolean attach) 560 { 561 if (attach) 562 return; 563 564 /* release the context ref so that it can be freed */ 565 SetCurrentContext(NULL); 566 }
Note:
See TracChangeset
for help on using the changeset viewer.