Changeset 19865 in vbox
- Timestamp:
- May 20, 2009 1:33:14 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/common/misc
- Files:
-
- 2 edited
-
handletable.cpp (modified) (9 diffs)
-
handletablectx.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/handletable.cpp
r10789 r19865 48 48 PFNRTHANDLETABLERETAIN pfnRetain, void *pvUser) 49 49 { 50 PRTHANDLETABLEINT pThis; 51 uint32_t cLevel1; 52 size_t cb; 53 50 54 /* 51 55 * Validate input. … … 65 69 cMax = ((cMax + RTHT_LEVEL2_ENTRIES - 1) / RTHT_LEVEL2_ENTRIES) * RTHT_LEVEL2_ENTRIES; 66 70 67 uint32_t constcLevel1 = cMax / RTHT_LEVEL2_ENTRIES;71 cLevel1 = cMax / RTHT_LEVEL2_ENTRIES; 68 72 Assert(cLevel1 * RTHT_LEVEL2_ENTRIES == cMax); 69 73 … … 72 76 * if it's below the threshold size. 73 77 */ 74 size_tcb = sizeof(RTHANDLETABLEINT);78 cb = sizeof(RTHANDLETABLEINT); 75 79 if (cLevel1 < RTHT_LEVEL1_DYN_ALLOC_THRESHOLD) 76 80 cb = RT_ALIGN(cb, sizeof(void *)) + cLevel1 * sizeof(void *); 77 PRTHANDLETABLEINTpThis = (PRTHANDLETABLEINT)RTMemAllocZ(cb);81 pThis = (PRTHANDLETABLEINT)RTMemAllocZ(cb); 78 82 if (!pThis) 79 83 return VERR_NO_MEMORY; … … 121 125 RTDECL(int) RTHandleTableDestroy(RTHANDLETABLE hHandleTable, PFNRTHANDLETABLEDELETE pfnDelete, void *pvUser) 122 126 { 127 PRTHANDLETABLEINT pThis; 128 RTSPINLOCKTMP Tmp; 129 uint32_t i1; 130 uint32_t i; 131 123 132 /* 124 133 * Validate input, quitely ignore the NIL handle. … … 126 135 if (hHandleTable == NIL_RTHANDLETABLE) 127 136 return VINF_SUCCESS; 128 PRTHANDLETABLEINTpThis = (PRTHANDLETABLEINT)hHandleTable;137 pThis = (PRTHANDLETABLEINT)hHandleTable; 129 138 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 130 139 AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, VERR_INVALID_HANDLE); … … 135 144 * Then kill the lock. 136 145 */ 137 RTSPINLOCKTMP Tmp;138 146 rtHandleTableLock(pThis, &Tmp); 139 147 ASMAtomicWriteU32(&pThis->u32Magic, ~RTHANDLETABLE_MAGIC); … … 157 165 if (pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT) 158 166 { 159 for ( uint32_ti1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++)167 for (i1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++) 160 168 { 161 169 PRTHTENTRYCTX paTable = (PRTHTENTRYCTX)pThis->papvLevel1[i1]; 162 170 if (paTable) 163 for ( uint32_ti = 0; i < RTHT_LEVEL2_ENTRIES; i++)171 for (i = 0; i < RTHT_LEVEL2_ENTRIES; i++) 164 172 if (!RTHT_IS_FREE(paTable[i].pvObj)) 165 173 { … … 173 181 else 174 182 { 175 for ( uint32_ti1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++)183 for (i1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++) 176 184 { 177 185 PRTHTENTRY paTable = (PRTHTENTRY)pThis->papvLevel1[i1]; 178 186 if (paTable) 179 for ( uint32_ti = 0; i < RTHT_LEVEL2_ENTRIES; i++)187 for (i = 0; i < RTHT_LEVEL2_ENTRIES; i++) 180 188 if (!RTHT_IS_FREE(paTable[i].pvObj)) 181 189 { … … 193 201 * Free the memory. 194 202 */ 195 for ( uint32_ti1 = 0; i1 < pThis->cLevel1; i1++)203 for (i1 = 0; i1 < pThis->cLevel1; i1++) 196 204 if (pThis->papvLevel1[i1]) 197 205 { -
trunk/src/VBox/Runtime/common/misc/handletablectx.cpp
r10790 r19865 46 46 RTDECL(int) RTHandleTableAllocWithCtx(RTHANDLETABLE hHandleTable, void *pvObj, void *pvCtx, uint32_t *ph) 47 47 { 48 PRTHANDLETABLEINT pThis; 49 RTSPINLOCKTMP Tmp; 50 int rc; 51 48 52 /* validate the input */ 49 PRTHANDLETABLEINTpThis = (PRTHANDLETABLEINT)hHandleTable;53 pThis = (PRTHANDLETABLEINT)hHandleTable; 50 54 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 51 55 AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, VERR_INVALID_HANDLE); … … 58 62 * Allocation loop. 59 63 */ 60 RTSPINLOCKTMP Tmp;61 64 rtHandleTableLock(pThis, &Tmp); 62 65 63 int rc;64 66 do 65 67 { … … 70 72 if (i != NIL_RTHT_INDEX) 71 73 { 72 PRTHTENTRYFREE pFree = (PRTHTENTRYFREE)rtHandleTableLookupWithCtxIdx(pThis, i); 74 PRTHTENTRYCTX pEntry; 75 PRTHTENTRYFREE pFree = (PRTHTENTRYFREE)rtHandleTableLookupWithCtxIdx(pThis, i); 73 76 Assert(pFree); 74 77 if (i == pThis->iFreeTail) … … 82 85 * Setup the entry and return. 83 86 */ 84 PRTHTENTRYCTXpEntry = (PRTHTENTRYCTX)pFree;87 pEntry = (PRTHTENTRYCTX)pFree; 85 88 pEntry->pvObj = pvObj; 86 89 pEntry->pvCtx = pvCtx; … … 98 101 else 99 102 { 103 void **papvLevel1; 104 uint32_t iLevel1New; 105 PRTHTENTRYCTX paTable; 106 100 107 /* 101 108 * Do we have to expand the 1st level table too? 102 109 */ 103 uint32_t const iLevel1 = pThis->cCur / RTHT_LEVEL2_ENTRIES;104 uint32_t cLevel1 = iLevel1 >= pThis->cLevel1105 ? pThis->cLevel1 + PAGE_SIZE / sizeof(void *)106 : 0;110 uint32_t const iLevel1 = pThis->cCur / RTHT_LEVEL2_ENTRIES; 111 uint32_t cLevel1 = iLevel1 >= pThis->cLevel1 112 ? pThis->cLevel1 + PAGE_SIZE / sizeof(void *) 113 : 0; 107 114 if (cLevel1 > pThis->cMax / RTHT_LEVEL2_ENTRIES) 108 115 cLevel1 = pThis->cMax / RTHT_LEVEL2_ENTRIES; … … 116 123 */ 117 124 rc = VERR_TRY_AGAIN; 118 void **papvLevel1 = NULL;125 papvLevel1 = NULL; 119 126 if (cLevel1) 120 127 { … … 124 131 } 125 132 126 PRTHTENTRYCTXpaTable = (PRTHTENTRYCTX)RTMemAlloc(sizeof(*paTable) * RTHT_LEVEL2_ENTRIES);133 paTable = (PRTHTENTRYCTX)RTMemAlloc(sizeof(*paTable) * RTHT_LEVEL2_ENTRIES); 127 134 if (!paTable) 128 135 { … … 144 151 if (cLevel1 > pThis->cLevel1) 145 152 { 153 void **papvTmp; 154 146 155 /* Replace the 1st level table. */ 147 156 memcpy(papvLevel1, pThis->papvLevel1, sizeof(void *) * pThis->cLevel1); 148 157 memset(&papvLevel1[pThis->cLevel1], 0, sizeof(void *) * (cLevel1 - pThis->cLevel1)); 149 158 pThis->cLevel1 = cLevel1; 150 void **papvTmp = pThis->papvLevel1;159 papvTmp = pThis->papvLevel1; 151 160 pThis->papvLevel1 = papvLevel1; 152 161 papvLevel1 = papvTmp; … … 160 169 161 170 /* insert the table we allocated. */ 162 uint32_tiLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES;171 iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES; 163 172 if ( iLevel1New < pThis->cLevel1 164 173 && pThis->cCur < pThis->cMax) 165 174 { 175 uint32_t i; 176 166 177 pThis->papvLevel1[iLevel1New] = paTable; 167 178 168 179 /* link all entries into a free list. */ 169 180 Assert(!(pThis->cCur % RTHT_LEVEL2_ENTRIES)); 170 for ( uint32_ti = 0; i < RTHT_LEVEL2_ENTRIES - 1; i++)181 for (i = 0; i < RTHT_LEVEL2_ENTRIES - 1; i++) 171 182 { 172 183 RTHT_SET_FREE_IDX((PRTHTENTRYFREE)&paTable[i], i + 1 + pThis->cCur); … … 209 220 RTDECL(void *) RTHandleTableLookupWithCtx(RTHANDLETABLE hHandleTable, uint32_t h, void *pvCtx) 210 221 { 222 void *pvObj = NULL; 223 PRTHTENTRYCTX pEntry; 224 PRTHANDLETABLEINT pThis; 225 RTSPINLOCKTMP Tmp; 226 211 227 /* validate the input */ 212 PRTHANDLETABLEINTpThis = (PRTHANDLETABLEINT)hHandleTable;228 pThis = (PRTHANDLETABLEINT)hHandleTable; 213 229 AssertPtrReturn(pThis, NULL); 214 230 AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, NULL); 215 231 AssertReturn(pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT, NULL); 216 232 217 void *pvObj = NULL;218 233 219 234 /* acquire the lock */ 220 RTSPINLOCKTMP Tmp;221 235 rtHandleTableLock(pThis, &Tmp); 222 236 … … 224 238 * Perform the lookup and retaining. 225 239 */ 226 PRTHTENTRYCTXpEntry = rtHandleTableLookupWithCtx(pThis, h);240 pEntry = rtHandleTableLookupWithCtx(pThis, h); 227 241 if (pEntry && pEntry->pvCtx == pvCtx) 228 242 { … … 249 263 RTDECL(void *) RTHandleTableFreeWithCtx(RTHANDLETABLE hHandleTable, uint32_t h, void *pvCtx) 250 264 { 265 void *pvObj = NULL; 266 PRTHTENTRYCTX pEntry; 267 PRTHANDLETABLEINT pThis; 268 RTSPINLOCKTMP Tmp; 269 251 270 /* validate the input */ 252 PRTHANDLETABLEINTpThis = (PRTHANDLETABLEINT)hHandleTable;271 pThis = (PRTHANDLETABLEINT)hHandleTable; 253 272 AssertPtrReturn(pThis, NULL); 254 273 AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, NULL); 255 274 AssertReturn(pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT, NULL); 256 275 257 void *pvObj = NULL;258 276 259 277 /* acquire the lock */ 260 RTSPINLOCKTMP Tmp;261 278 rtHandleTableLock(pThis, &Tmp); 262 279 … … 264 281 * Perform the lookup and retaining. 265 282 */ 266 PRTHTENTRYCTXpEntry = rtHandleTableLookupWithCtx(pThis, h);283 pEntry = rtHandleTableLookupWithCtx(pThis, h); 267 284 if (pEntry && pEntry->pvCtx == pvCtx) 268 285 { … … 282 299 if (pvObj) 283 300 { 301 PRTHTENTRYFREE pFree; 302 uint32_t i; 303 284 304 pEntry->pvCtx = (void *)~(uintptr_t)7; 285 305 286 PRTHTENTRYFREEpFree = (PRTHTENTRYFREE)pEntry;306 pFree = (PRTHTENTRYFREE)pEntry; 287 307 RTHT_SET_FREE_IDX(pFree, NIL_RTHT_INDEX); 288 308 289 uint32_t consti = h - pThis->uBase;309 i = h - pThis->uBase; 290 310 if (pThis->iFreeTail == NIL_RTHT_INDEX) 291 311 pThis->iFreeHead = pThis->iFreeTail = i;
Note:
See TracChangeset
for help on using the changeset viewer.

