Changeset 5222 in vbox for trunk/src/VBox/Runtime/r0drv/nt
- Timestamp:
- Oct 10, 2007 2:57:53 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv/nt
- Files:
-
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/semevent-r0drv-nt.cpp
r5219 r5222 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Semaphores, Ring-0 Driver, NT.3 * innotek Portable Runtime - Single Release Event Semaphores, Ring-0 Driver, NT. 4 4 */ 5 5 … … 44 44 KEVENT Event; 45 45 } RTSEMEVENTINTERNAL, *PRTSEMEVENTINTERNAL; 46 47 48 49 /**50 * NT mutex semaphore.51 */52 typedef struct RTSEMMUTEXINTERNAL53 {54 /** Magic value (RTSEMMUTEX_MAGIC). */55 uint32_t volatile u32Magic;56 #ifdef RT_USE_FAST_MUTEX57 /** The fast mutex object. */58 FAST_MUTEX Mutex;59 #else60 /** The NT Mutex object. */61 KMUTEX Mutex;62 #endif63 } RTSEMMUTEXINTERNAL, *PRTSEMMUTEXINTERNAL;64 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 46 80 47 … … 199 166 } 200 167 201 202 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)203 {204 Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));205 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pMutexInt));206 if (pMutexInt)207 {208 pMutexInt->u32Magic = RTSEMMUTEX_MAGIC;209 #ifdef RT_USE_FAST_MUTEX210 ExInitializeFastMutex(&pMutexInt->Mutex);211 #else212 KeInitializeMutex(&pMutexInt->Mutex, 0);213 #endif214 *pMutexSem = pMutexInt;215 return VINF_SUCCESS;216 }217 return VERR_NO_MEMORY;218 }219 220 221 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)222 {223 /*224 * Validate input.225 */226 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;227 if (!pMutexInt)228 return VERR_INVALID_PARAMETER;229 if (pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)230 {231 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt->u32Magic, pMutexInt));232 return VERR_INVALID_PARAMETER;233 }234 235 /*236 * Invalidate it and signal the object just in case.237 */238 ASMAtomicIncU32(&pMutexInt->u32Magic);239 RTMemFree(pMutexInt);240 return VINF_SUCCESS;241 }242 243 244 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies)245 {246 /*247 * Validate input.248 */249 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;250 if (!pMutexInt)251 return VERR_INVALID_PARAMETER;252 if ( !pMutexInt253 || pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)254 {255 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));256 return VERR_INVALID_PARAMETER;257 }258 259 /*260 * Get the mutex.261 */262 #ifdef RT_USE_FAST_MUTEX263 AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n"));264 ExAcquireFastMutex(&pMutexInt->Mutex);265 #else266 NTSTATUS rcNt;267 if (cMillies == RT_INDEFINITE_WAIT)268 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, NULL);269 else270 {271 LARGE_INTEGER Timeout;272 Timeout.QuadPart = -(int64_t)cMillies * 10000;273 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, &Timeout);274 }275 switch (rcNt)276 {277 case STATUS_SUCCESS:278 if (pMutexInt->u32Magic == RTSEMMUTEX_MAGIC)279 return VINF_SUCCESS;280 return VERR_SEM_DESTROYED;281 case STATUS_ALERTED:282 return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */283 case STATUS_USER_APC:284 return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */285 case STATUS_TIMEOUT:286 return VERR_TIMEOUT;287 default:288 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n",289 pMutexInt->u32Magic, pMutexInt, (long)rcNt));290 return VERR_INTERNAL_ERROR;291 }292 #endif293 return VINF_SUCCESS;294 }295 296 297 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)298 {299 /*300 * Validate input.301 */302 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;303 if (!pMutexInt)304 return VERR_INVALID_PARAMETER;305 if ( !pMutexInt306 || pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)307 {308 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));309 return VERR_INVALID_PARAMETER;310 }311 312 /*313 * Release the mutex.314 */315 #ifdef RT_USE_FAST_MUTEX316 ExReleaseFastMutex(&pMutexInt->Mutex);317 #else318 KeReleaseMutex(&pMutexInt->Mutex, FALSE);319 #endif320 return VINF_SUCCESS;321 }322 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 -
trunk/src/VBox/Runtime/r0drv/nt/semfastmutex-r0drv-nt.cpp
r5219 r5222 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Semaphores, Ring-0 Driver, NT.3 * innotek Portable Runtime - Fast 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 * NT mutex semaphore.51 */52 typedef struct RTSEMMUTEXINTERNAL53 {54 /** Magic value (RTSEMMUTEX_MAGIC). */55 uint32_t volatile u32Magic;56 #ifdef RT_USE_FAST_MUTEX57 /** The fast mutex object. */58 FAST_MUTEX Mutex;59 #else60 /** The NT Mutex object. */61 KMUTEX Mutex;62 #endif63 } RTSEMMUTEXINTERNAL, *PRTSEMMUTEXINTERNAL;64 65 66 67 /**68 37 * Wrapper for the linux semaphore structure. 69 38 */ … … 75 44 FAST_MUTEX Mutex; 76 45 } 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 201 202 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)203 {204 Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));205 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pMutexInt));206 if (pMutexInt)207 {208 pMutexInt->u32Magic = RTSEMMUTEX_MAGIC;209 #ifdef RT_USE_FAST_MUTEX210 ExInitializeFastMutex(&pMutexInt->Mutex);211 #else212 KeInitializeMutex(&pMutexInt->Mutex, 0);213 #endif214 *pMutexSem = pMutexInt;215 return VINF_SUCCESS;216 }217 return VERR_NO_MEMORY;218 }219 220 221 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)222 {223 /*224 * Validate input.225 */226 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;227 if (!pMutexInt)228 return VERR_INVALID_PARAMETER;229 if (pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)230 {231 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt->u32Magic, pMutexInt));232 return VERR_INVALID_PARAMETER;233 }234 235 /*236 * Invalidate it and signal the object just in case.237 */238 ASMAtomicIncU32(&pMutexInt->u32Magic);239 RTMemFree(pMutexInt);240 return VINF_SUCCESS;241 }242 243 244 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies)245 {246 /*247 * Validate input.248 */249 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;250 if (!pMutexInt)251 return VERR_INVALID_PARAMETER;252 if ( !pMutexInt253 || pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)254 {255 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));256 return VERR_INVALID_PARAMETER;257 }258 259 /*260 * Get the mutex.261 */262 #ifdef RT_USE_FAST_MUTEX263 AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n"));264 ExAcquireFastMutex(&pMutexInt->Mutex);265 #else266 NTSTATUS rcNt;267 if (cMillies == RT_INDEFINITE_WAIT)268 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, NULL);269 else270 {271 LARGE_INTEGER Timeout;272 Timeout.QuadPart = -(int64_t)cMillies * 10000;273 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, &Timeout);274 }275 switch (rcNt)276 {277 case STATUS_SUCCESS:278 if (pMutexInt->u32Magic == RTSEMMUTEX_MAGIC)279 return VINF_SUCCESS;280 return VERR_SEM_DESTROYED;281 case STATUS_ALERTED:282 return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */283 case STATUS_USER_APC:284 return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */285 case STATUS_TIMEOUT:286 return VERR_TIMEOUT;287 default:288 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n",289 pMutexInt->u32Magic, pMutexInt, (long)rcNt));290 return VERR_INTERNAL_ERROR;291 }292 #endif293 return VINF_SUCCESS;294 }295 296 297 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)298 {299 /*300 * Validate input.301 */302 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;303 if (!pMutexInt)304 return VERR_INVALID_PARAMETER;305 if ( !pMutexInt306 || pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)307 {308 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));309 return VERR_INVALID_PARAMETER;310 }311 312 /*313 * Release the mutex.314 */315 #ifdef RT_USE_FAST_MUTEX316 ExReleaseFastMutex(&pMutexInt->Mutex);317 #else318 KeReleaseMutex(&pMutexInt->Mutex, FALSE);319 #endif320 return VINF_SUCCESS;321 }322 323 46 324 47 … … 400 123 } 401 124 402 -
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.