Changeset 5230 in vbox for trunk/src/VBox/Runtime/r0drv/nt
- Timestamp:
- Oct 10, 2007 4:20:26 PM (17 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/semeventmulti-r0drv-nt.cpp
r5222 r5230 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Single Release Event Semaphores, Ring-0 Driver, NT.3 * innotek Portable Runtime - Multiple Release Event Semaphores, Ring-0 Driver, NT. 4 4 */ 5 5 … … 15 15 * be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 17 19 18 … … 37 36 * NT event semaphore. 38 37 */ 39 typedef struct RTSEMEVENT INTERNAL38 typedef struct RTSEMEVENTMULTIINTERNAL 40 39 { 41 /** Magic value (RTSEMEVENT _MAGIC). */40 /** Magic value (RTSEMEVENTMULTI_MAGIC). */ 42 41 uint32_t volatile u32Magic; 43 42 /** The NT Event object. */ 44 43 KEVENT Event; 45 } RTSEMEVENT INTERNAL, *PRTSEMEVENTINTERNAL;44 } RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL; 46 45 47 46 48 RTDECL(int) RTSemEventCreate(PRTSEMEVENTpEventSem)47 RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventSem) 49 48 { 50 Assert(sizeof(RTSEMEVENT INTERNAL) > sizeof(void *));51 PRTSEMEVENT INTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt));52 if (p EventInt)49 Assert(sizeof(RTSEMEVENTMULTIINTERNAL) > sizeof(void *)); 50 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis)); 51 if (pThis) 53 52 { 54 p EventInt->u32Magic = RTSEMEVENT_MAGIC;55 KeInitializeEvent(&p EventInt->Event, SynchronizationEvent, FALSE);56 *pEventSem = p EventInt;53 pThis->u32Magic = RTSEMEVENTMULTI_MAGIC; 54 KeInitializeEvent(&pThis->Event, NotificationEvent, FALSE /* not signalled */); 55 *pEventSem = pThis; 57 56 return VINF_SUCCESS; 58 57 } … … 61 60 62 61 63 RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem)62 RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem) 64 63 { 65 64 /* 66 65 * Validate input. 67 66 */ 68 PRTSEMEVENT INTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;69 if (!p EventInt)67 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 68 if (!pThis) 70 69 return VERR_INVALID_PARAMETER; 71 if (pEventInt->u32Magic != RTSEMEVENT_MAGIC) 72 { 73 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt->u32Magic, pEventInt)); 74 return VERR_INVALID_PARAMETER; 75 } 70 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 71 AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 76 72 77 73 /* 78 74 * Invalidate it and signal the object just in case. 79 75 */ 80 ASMAtomicIncU32(&p EventInt->u32Magic);81 KeSetEvent(&p EventInt->Event, 0xfff, FALSE);82 RTMemFree(p EventInt);76 ASMAtomicIncU32(&pThis->u32Magic); 77 KeSetEvent(&pThis->Event, 0xfff, FALSE); 78 RTMemFree(pThis); 83 79 return VINF_SUCCESS; 84 80 } 85 81 86 82 87 RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem)83 RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem) 88 84 { 89 85 /* 90 86 * Validate input. 91 87 */ 92 PRTSEMEVENT INTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;93 if (!p EventInt)88 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 89 if (!pThis) 94 90 return VERR_INVALID_PARAMETER; 95 if ( !pEventInt 96 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 97 { 98 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 99 return VERR_INVALID_PARAMETER; 100 } 91 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 92 AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 101 93 102 94 /* 103 95 * Signal the event object. 104 96 */ 105 KeSetEvent(&p EventInt->Event, 1, FALSE);97 KeSetEvent(&pThis->Event, 1, FALSE); 106 98 return VINF_SUCCESS; 107 99 } 108 100 109 101 110 static int rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fInterruptible)102 RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem) 111 103 { 112 104 /* 113 105 * Validate input. 114 106 */ 115 PRTSEMEVENT INTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;116 if (!p EventInt)107 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 108 if (!pThis) 117 109 return VERR_INVALID_PARAMETER; 118 if ( !pEventInt 119 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 120 { 121 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 110 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 111 AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 112 113 /* 114 * Reset the event object. 115 */ 116 KeResetEvent(&pThis->Event); 117 return VINF_SUCCESS; 118 } 119 120 121 static int rtSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies, bool fInterruptible) 122 { 123 /* 124 * Validate input. 125 */ 126 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 127 if (!pThis) 122 128 return VERR_INVALID_PARAMETER; 123 } 129 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 130 AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 124 131 125 132 /* … … 128 135 NTSTATUS rcNt; 129 136 if (cMillies == RT_INDEFINITE_WAIT) 130 rcNt = KeWaitForSingleObject(&p EventInt->Event, Executive, KernelMode, fInterruptible, NULL);137 rcNt = KeWaitForSingleObject(&pThis->Event, Executive, KernelMode, fInterruptible, NULL); 131 138 else 132 139 { 133 140 LARGE_INTEGER Timeout; 134 141 Timeout.QuadPart = -(int64_t)cMillies * 10000; 135 rcNt = KeWaitForSingleObject(&p EventInt->Event, Executive, KernelMode, fInterruptible, &Timeout);142 rcNt = KeWaitForSingleObject(&pThis->Event, Executive, KernelMode, fInterruptible, &Timeout); 136 143 } 137 144 switch (rcNt) 138 145 { 139 146 case STATUS_SUCCESS: 140 if (p EventInt->u32Magic == RTSEMEVENT_MAGIC)147 if (pThis->u32Magic == RTSEMEVENTMULTI_MAGIC) 141 148 return VINF_SUCCESS; 142 149 return VERR_SEM_DESTROYED; … … 148 155 return VERR_TIMEOUT; 149 156 default: 150 AssertMsgFailed(("p EventInt->u32Magic=%RX32 pEventInt=%p: wait returned %lx!\n",151 p EventInt->u32Magic, pEventInt, (long)rcNt));157 AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n", 158 pThis->u32Magic, pThis, (long)rcNt)); 152 159 return VERR_INTERNAL_ERROR; 153 160 } … … 155 162 156 163 157 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)164 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies) 158 165 { 159 return rtSemEvent Wait(EventSem, cMillies, false /* fInterruptible */);166 return rtSemEventMultiWait(EventMultiSem, cMillies, false /* fInterruptible */); 160 167 } 161 168 162 169 163 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)170 RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies) 164 171 { 165 return rtSemEvent Wait(EventSem, cMillies, true /* fInterruptible */);172 return rtSemEventMultiWait(EventMultiSem, cMillies, true /* fInterruptible */); 166 173 } 167 174
Note:
See TracChangeset
for help on using the changeset viewer.