Changeset 5226 in vbox for trunk/src/VBox/Runtime/r0drv/linux/semeventmulti-r0drv-linux.c
- Timestamp:
- Oct 10, 2007 3:35:11 PM (17 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/semeventmulti-r0drv-linux.c
r5225 r5226 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Single Release Event Semaphores, Ring-0 Driver, Linux.3 * innotek Portable Runtime - Multiple Release Event Semaphores, Ring-0 Driver, Linux. 4 4 */ 5 5 … … 37 37 * Linux event semaphore. 38 38 */ 39 typedef struct RTSEMEVENT INTERNAL39 typedef struct RTSEMEVENTMULTIINTERNAL 40 40 { 41 41 /** Magic value (RTSEMEVENT_MAGIC). */ … … 45 45 /** The wait queue. */ 46 46 wait_queue_head_t Head; 47 } RTSEMEVENT INTERNAL, *PRTSEMEVENTINTERNAL;48 49 50 51 RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem)52 { 53 PRTSEMEVENT INTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt));54 if (p EventInt)47 } RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL; 48 49 50 51 RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem) 52 { 53 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis)); 54 if (pThis) 55 55 { 56 p EventInt->u32Magic = RTSEMEVENT_MAGIC;57 init_waitqueue_head(&p EventInt->Head);58 *pEvent Sem = pEventInt;56 pThis->u32Magic = RTSEMEVENT_MAGIC; 57 init_waitqueue_head(&pThis->Head); 58 *pEventMultiSem = pThis; 59 59 return VINF_SUCCESS; 60 60 } … … 63 63 64 64 65 RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem)65 RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem) 66 66 { 67 67 /* 68 68 * Validate input. 69 69 */ 70 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 71 if (!pEventInt) 72 return VERR_INVALID_PARAMETER; 73 if (pEventInt->u32Magic != RTSEMEVENT_MAGIC) 74 { 75 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt->u32Magic, pEventInt)); 76 return VERR_INVALID_PARAMETER; 77 } 70 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 71 if (!pThis) 72 return VERR_INVALID_PARAMETER; 73 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 74 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 78 75 79 76 /* 80 77 * Invalidate it and signal the object just in case. 81 78 */ 82 ASMAtomicIncU32(&p EventInt->u32Magic);83 ASMAtomicXchgU32(&p EventInt->fState, 0);84 Assert(!waitqueue_active(&p EventInt->Head));85 wake_up_all(&p EventInt->Head);86 RTMemFree(p EventInt);79 ASMAtomicIncU32(&pThis->u32Magic); 80 ASMAtomicXchgU32(&pThis->fState, 0); 81 Assert(!waitqueue_active(&pThis->Head)); 82 wake_up_all(&pThis->Head); 83 RTMemFree(pThis); 87 84 return VINF_SUCCESS; 88 85 } 89 86 90 87 91 RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem)88 RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem) 92 89 { 93 90 /* 94 91 * Validate input. 95 92 */ 96 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 97 if (!pEventInt) 98 return VERR_INVALID_PARAMETER; 99 if ( !pEventInt 100 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 101 { 102 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 103 return VERR_INVALID_PARAMETER; 104 } 93 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 94 if (!pThis) 95 return VERR_INVALID_PARAMETER; 96 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 97 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 105 98 106 99 /* 107 100 * Signal the event object. 108 101 */ 109 ASMAtomicXchgU32(&pEventInt->fState, 1); 110 wake_up(&pEventInt->Head); 111 102 ASMAtomicXchgU32(&pThis->fState, 1); 103 wake_up_all(&pThis->Head); 112 104 return VINF_SUCCESS; 113 105 } 114 106 115 107 108 RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem) 109 { 110 /* 111 * Validate input. 112 */ 113 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 114 if (!pThis) 115 return VERR_INVALID_PARAMETER; 116 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 117 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 118 119 /* 120 * Reset it. 121 */ 122 ASMAtomicXchgU32(&pThis->fState, 0); 123 return VINF_SUCCESS; 124 } 125 126 116 127 /** 117 * Worker for RTSemEvent and RTSemEventNoResume.128 * Worker for RTSemEventMulti and RTSemEventMultiNoResume. 118 129 * 119 130 * @returns VBox status code. 120 * @param p EventIntThe event semaphore.131 * @param pThis The event semaphore. 121 132 * @param cMillies The number of milliseconds to wait. 122 133 * @param fInterruptible Whether it's an interruptible wait or not. 123 134 */ 124 static int rtSemEventWait(PRTSEMEVENT INTERNAL pEventInt, unsigned cMillies, bool fInterruptible)135 static int rtSemEventWait(PRTSEMEVENTMULTIINTERNAL pThis, unsigned cMillies, bool fInterruptible) 125 136 { 126 137 /* … … 133 144 { 134 145 /* make everything thru schedule() atomic scheduling wise. */ 135 prepare_to_wait(&p EventInt->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);146 prepare_to_wait(&pThis->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); 136 147 137 148 /* check the condition. */ 138 if ( ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1))149 if (pThis->fState) 139 150 break; 140 151 … … 150 161 151 162 /* Check if someone destroyed the semaphore while we were waiting. */ 152 if (p EventInt->u32Magic != RTSEMEVENT_MAGIC)163 if (pThis->u32Magic != RTSEMEVENT_MAGIC) 153 164 { 154 165 rc = VERR_SEM_DESTROYED; … … 164 175 } 165 176 166 finish_wait(&p EventInt->Head, &Wait);177 finish_wait(&pThis->Head, &Wait); 167 178 return rc; 168 179 } 169 180 170 181 171 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies) 172 { 173 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 174 if (!pEventInt) 175 return VERR_INVALID_PARAMETER; 176 if ( !pEventInt 177 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 178 { 179 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 180 return VERR_INVALID_PARAMETER; 181 } 182 183 if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1)) 182 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies) 183 { 184 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 185 if (!pThis) 186 return VERR_INVALID_PARAMETER; 187 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 188 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 189 190 if (pThis->fState) 184 191 return VINF_SUCCESS; 185 return rtSemEventWait(pEventInt, cMillies, false /* fInterruptible */); 186 } 187 188 189 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies) 190 { 191 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 192 if (!pEventInt) 193 return VERR_INVALID_PARAMETER; 194 if ( !pEventInt 195 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 196 { 197 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 198 return VERR_INVALID_PARAMETER; 199 } 200 201 if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1)) 192 return rtSemEventWait(pThis, cMillies, false /* fInterruptible */); 193 } 194 195 196 RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies) 197 { 198 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem; 199 if (!pThis) 200 return VERR_INVALID_PARAMETER; 201 AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); 202 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); 203 204 if (pThis->fState) 202 205 return VINF_SUCCESS; 203 return rtSemEventWait(p EventInt, cMillies, true /* fInterruptible */);204 } 205 206 return rtSemEventWait(pThis, cMillies, true /* fInterruptible */); 207 } 208
Note:
See TracChangeset
for help on using the changeset viewer.