Changeset 5222 in vbox for trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp
- Timestamp:
- Oct 10, 2007 2:57:53 PM (17 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp
r5219 r5222 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Semaphores, Ring-0 Driver, NT.3 * innotek Portable Runtime - Mutex Semaphores, Ring-0 Driver, NT. 4 4 */ 5 5 … … 35 35 *******************************************************************************/ 36 36 /** 37 * NT event semaphore.38 */39 typedef struct RTSEMEVENTINTERNAL40 {41 /** Magic value (RTSEMEVENT_MAGIC). */42 uint32_t volatile u32Magic;43 /** The NT Event object. */44 KEVENT Event;45 } RTSEMEVENTINTERNAL, *PRTSEMEVENTINTERNAL;46 47 48 49 /**50 37 * NT mutex semaphore. 51 38 */ … … 63 50 } RTSEMMUTEXINTERNAL, *PRTSEMMUTEXINTERNAL; 64 51 65 66 67 /**68 * Wrapper for the linux semaphore structure.69 */70 typedef struct RTSEMFASTMUTEXINTERNAL71 {72 /** Magic value (RTSEMFASTMUTEX_MAGIC). */73 uint32_t u32Magic;74 /** the NT fast mutex. */75 FAST_MUTEX Mutex;76 } RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;77 78 79 80 81 RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem)82 {83 Assert(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));84 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt));85 if (pEventInt)86 {87 pEventInt->u32Magic = RTSEMEVENT_MAGIC;88 KeInitializeEvent(&pEventInt->Event, SynchronizationEvent, FALSE);89 *pEventSem = pEventInt;90 return VINF_SUCCESS;91 }92 return VERR_NO_MEMORY;93 }94 95 96 RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem)97 {98 /*99 * Validate input.100 */101 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;102 if (!pEventInt)103 return VERR_INVALID_PARAMETER;104 if (pEventInt->u32Magic != RTSEMEVENT_MAGIC)105 {106 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt->u32Magic, pEventInt));107 return VERR_INVALID_PARAMETER;108 }109 110 /*111 * Invalidate it and signal the object just in case.112 */113 ASMAtomicIncU32(&pEventInt->u32Magic);114 KeSetEvent(&pEventInt->Event, 0xfff, FALSE);115 RTMemFree(pEventInt);116 return VINF_SUCCESS;117 }118 119 120 RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem)121 {122 /*123 * Validate input.124 */125 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;126 if (!pEventInt)127 return VERR_INVALID_PARAMETER;128 if ( !pEventInt129 || pEventInt->u32Magic != RTSEMEVENT_MAGIC)130 {131 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));132 return VERR_INVALID_PARAMETER;133 }134 135 /*136 * Signal the event object.137 */138 KeSetEvent(&pEventInt->Event, 1, FALSE);139 return VINF_SUCCESS;140 }141 142 143 static int rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fInterruptible)144 {145 /*146 * Validate input.147 */148 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;149 if (!pEventInt)150 return VERR_INVALID_PARAMETER;151 if ( !pEventInt152 || pEventInt->u32Magic != RTSEMEVENT_MAGIC)153 {154 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));155 return VERR_INVALID_PARAMETER;156 }157 158 /*159 * Wait for it.160 */161 NTSTATUS rcNt;162 if (cMillies == RT_INDEFINITE_WAIT)163 rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, fInterruptible, NULL);164 else165 {166 LARGE_INTEGER Timeout;167 Timeout.QuadPart = -(int64_t)cMillies * 10000;168 rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, fInterruptible, &Timeout);169 }170 switch (rcNt)171 {172 case STATUS_SUCCESS:173 if (pEventInt->u32Magic == RTSEMEVENT_MAGIC)174 return VINF_SUCCESS;175 return VERR_SEM_DESTROYED;176 case STATUS_ALERTED:177 return VERR_INTERRUPTED;178 case STATUS_USER_APC:179 return VERR_INTERRUPTED;180 case STATUS_TIMEOUT:181 return VERR_TIMEOUT;182 default:183 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p: wait returned %lx!\n",184 pEventInt->u32Magic, pEventInt, (long)rcNt));185 return VERR_INTERNAL_ERROR;186 }187 }188 189 190 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)191 {192 return rtSemEventWait(EventSem, cMillies, false /* fInterruptible */);193 }194 195 196 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)197 {198 return rtSemEventWait(EventSem, cMillies, true /* fInterruptible */);199 }200 52 201 53 … … 321 173 } 322 174 323 324 325 326 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)327 {328 /*329 * Allocate.330 */331 PRTSEMFASTMUTEXINTERNAL pFastInt;332 Assert(sizeof(*pFastInt) > sizeof(void *));333 pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));334 if (!pFastInt)335 return VERR_NO_MEMORY;336 337 /*338 * Initialize.339 */340 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;341 ExInitializeFastMutex(&pFastInt->Mutex);342 *pMutexSem = pFastInt;343 return VINF_SUCCESS;344 }345 346 347 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)348 {349 /*350 * Validate.351 */352 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;353 if (!pFastInt)354 return VERR_INVALID_PARAMETER;355 if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)356 {357 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt));358 return VERR_INVALID_PARAMETER;359 }360 361 ASMAtomicIncU32(&pFastInt->u32Magic);362 RTMemFree(pFastInt);363 return VINF_SUCCESS;364 }365 366 367 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)368 {369 /*370 * Validate.371 */372 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;373 if ( !pFastInt374 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)375 {376 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));377 return VERR_INVALID_PARAMETER;378 }379 380 ExAcquireFastMutex(&pFastInt->Mutex);381 return VINF_SUCCESS;382 }383 384 385 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)386 {387 /*388 * Validate.389 */390 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;391 if ( !pFastInt392 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)393 {394 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));395 return VERR_INVALID_PARAMETER;396 }397 398 ExReleaseFastMutex(&pFastInt->Mutex);399 return VINF_SUCCESS;400 }401 402
Note:
See TracChangeset
for help on using the changeset viewer.