Changeset 199 in vbox
- Timestamp:
- Jan 20, 2007 2:09:02 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 17675
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/darwin/semaphore-r0drv-darwin.cpp
r1 r199 36 36 * Structures and Typedefs * 37 37 *******************************************************************************/ 38 #if 0/* GRRR */39 38 #if 0 /** @todo */ 40 39 /** … … 53 52 #endif 54 53 55 54 #if 0 /** @todo */ 56 55 /** 57 56 * Darwin mutex semaphore. … … 67 66 /** Magic for the Darwin mutex semaphore structure. (Douglas Adams) */ 68 67 #define RTSEMMUTEX_MAGIC 0x19520311 68 #endif 69 69 70 70 … … 197 197 198 198 199 #if 0 /* need proper timeout lock function! */ 199 200 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem) 200 201 { … … 320 321 } 321 322 323 #endif /* later */ 324 322 325 323 326 … … 325 328 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem) 326 329 { 327 /* 328 * Allocate. 329 */ 330 PRTSEMFASTMUTEXINTERNAL pFastInt; 331 Assert(sizeof(*pFastInt) > sizeof(void *)); 332 pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt)); 333 if (!pFastInt) 334 return VERR_NO_MEMORY; 335 336 /* 337 * Initialize. 338 */ 339 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC; 340 ExInitializeFastMutex(&pFastInt->Mutex); 341 *pMutexSem = pFastInt; 342 return VINF_SUCCESS; 330 AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *)); 331 AssertPtrReturn(VALID_PTR(pMutexSem), VERR_INVALID_POINTER); 332 333 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt)); 334 if (pFastInt) 335 { 336 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC; 337 Assert(g_pDarwinLockGroup); 338 pFastInt->pMtx = lck_mtx_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL); 339 if (pFastInt->pMtx) 340 { 341 *pMutexSem = pFastInt; 342 return VINF_SUCCESS; 343 } 344 345 RTMemFree(pFastInt); 346 } 347 return VERR_NO_MEMORY; 343 348 } 344 349 … … 346 351 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem) 347 352 { 348 /* 349 * Validate. 350 */ 353 if (MutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */ 354 return VERR_INVALID_PARAMETER; 351 355 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 352 if (!pFastInt)353 return VERR_INVALID_PARAMETER;354 if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)355 {356 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt)); 357 return VERR_INVALID_PARAMETER;358 }359 360 ASMAtomicIncU32(&pFastInt->u32Magic);356 AssertPtrReturn(VALID_PTR(pFastInt), VERR_INVALID_POINTER); 357 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 358 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 359 VERR_INVALID_PARAMETER); 360 361 ASMAtomicIncU32(&pFastInt->u32Magic); /* make the handle invalid. */ 362 Assert(g_pDarwinLockGroup); 363 lck_mtx_free(pFastInt->pMtx, g_pDarwinLockGroup); 364 pFastInt->pMtx = NULL; 361 365 RTMemFree(pFastInt); 366 362 367 return VINF_SUCCESS; 363 368 } … … 366 371 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem) 367 372 { 368 /*369 * Validate.370 */371 373 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 372 if ( !pFastInt 373 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 374 { 375 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt)); 376 return VERR_INVALID_PARAMETER; 377 } 378 379 ExAcquireFastMutex(&pFastInt->Mutex); 374 AssertMsgReturn(VALID_PTR(pFastInt) && pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 375 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", VALID_PTR(pFastInt) ? pFastInt->u32Magic : 0, pFastInt), 376 VERR_INVALID_PARAMETER); 377 lck_mtx_lock(pFastInt->pMtx); 380 378 return VINF_SUCCESS; 381 379 } … … 384 382 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem) 385 383 { 386 /*387 * Validate.388 */389 384 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 390 if ( !pFastInt 391 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 392 { 393 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt)); 394 return VERR_INVALID_PARAMETER; 395 } 396 397 ExReleaseFastMutex(&pFastInt->Mutex); 398 return VINF_SUCCESS; 399 } 400 401 402 #endif 385 AssertMsgReturn(VALID_PTR(pFastInt) && pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 386 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", VALID_PTR(pFastInt) ? pFastInt->u32Magic : 0, pFastInt), 387 VERR_INVALID_PARAMETER); 388 lck_mtx_unlock(pFastInt->pMtx); 389 return VINF_SUCCESS; 390 } 391
Note:
See TracChangeset
for help on using the changeset viewer.