Changeset 25717 in vbox for trunk/src/VBox/Runtime/r0drv/linux/semevent-r0drv-linux.c
- Timestamp:
- Jan 11, 2010 1:24:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/semevent-r0drv-linux.c
r24956 r25717 62 62 63 63 64 RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem) 65 { 66 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt)); 67 if (pEventInt) 68 { 69 pEventInt->u32Magic = RTSEMEVENT_MAGIC; 70 pEventInt->fState = 0; 71 init_waitqueue_head(&pEventInt->Head); 72 *pEventSem = pEventInt; 64 RTDECL(int) RTSemEventCreate(PRTSEMEVENT phEventSem) 65 { 66 return RTSemEventCreateEx(phEventSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL); 67 } 68 69 70 RTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...) 71 { 72 PRTSEMEVENTINTERNAL pThis; 73 74 AssertReturn(!(fFlags & ~RTSEMEVENT_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER); 75 pThis = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pThis)); 76 if (!pThis) 77 return VERR_NO_MEMORY; 78 79 pThis->u32Magic = RTSEMEVENT_MAGIC; 80 pThis->fState = 0; 81 init_waitqueue_head(&pThis->Head); 82 83 *phEventSem = pThis; 84 return VINF_SUCCESS; 85 } 86 RT_EXPORT_SYMBOL(RTSemEventCreate); 87 88 89 RTDECL(int) RTSemEventDestroy(RTSEMEVENT hEventSem) 90 { 91 /* 92 * Validate input. 93 */ 94 PRTSEMEVENTINTERNAL pThis = hEventSem; 95 if (pThis == NIL_RTSEMEVENT) 73 96 return VINF_SUCCESS; 74 } 75 return VERR_NO_MEMORY; 76 } 77 RT_EXPORT_SYMBOL(RTSemEventCreate); 78 79 80 RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem) 97 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 98 99 /* 100 * Invalidate it and signal the object just in case. 101 */ 102 ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENT_MAGIC); 103 ASMAtomicWriteU32(&pThis->fState, 0); 104 Assert(!waitqueue_active(&pThis->Head)); 105 wake_up_all(&pThis->Head); 106 RTMemFree(pThis); 107 return VINF_SUCCESS; 108 } 109 RT_EXPORT_SYMBOL(RTSemEventDestroy); 110 111 112 RTDECL(int) RTSemEventSignal(RTSEMEVENT hEventSem) 81 113 { 82 114 /* 83 115 * Validate input. 84 116 */ 85 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 86 if (!pEventInt) 87 return VERR_INVALID_PARAMETER; 88 if (pEventInt->u32Magic != RTSEMEVENT_MAGIC) 89 { 90 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt->u32Magic, pEventInt)); 91 return VERR_INVALID_PARAMETER; 92 } 93 94 /* 95 * Invalidate it and signal the object just in case. 96 */ 97 ASMAtomicWriteU32(&pEventInt->u32Magic, ~RTSEMEVENT_MAGIC); 98 ASMAtomicWriteU32(&pEventInt->fState, 0); 99 Assert(!waitqueue_active(&pEventInt->Head)); 100 wake_up_all(&pEventInt->Head); 101 RTMemFree(pEventInt); 102 return VINF_SUCCESS; 103 } 104 RT_EXPORT_SYMBOL(RTSemEventDestroy); 105 106 107 RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem) 108 { 109 /* 110 * Validate input. 111 */ 112 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 113 if (!pEventInt) 114 return VERR_INVALID_PARAMETER; 115 if ( !pEventInt 116 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 117 { 118 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 119 return VERR_INVALID_PARAMETER; 120 } 117 PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem; 118 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 119 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 121 120 122 121 /* 123 122 * Signal the event object. 124 123 */ 125 ASMAtomicWriteU32(&p EventInt->fState, 1);126 wake_up(&p EventInt->Head);124 ASMAtomicWriteU32(&pThis->fState, 1); 125 wake_up(&pThis->Head); 127 126 128 127 return VINF_SUCCESS; … … 135 134 * 136 135 * @returns VBox status code. 137 * @param p EventIntThe event semaphore.136 * @param pThis The event semaphore. 138 137 * @param cMillies The number of milliseconds to wait. 139 138 * @param fInterruptible Whether it's an interruptible wait or not. 140 139 */ 141 static int rtSemEventWait(PRTSEMEVENTINTERNAL p EventInt, unsigned cMillies, bool fInterruptible)140 static int rtSemEventWait(PRTSEMEVENTINTERNAL pThis, unsigned cMillies, bool fInterruptible) 142 141 { 143 142 /* … … 148 147 long lTimeout = cMillies == RT_INDEFINITE_WAIT ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(cMillies); 149 148 #ifdef IPRT_DEBUG_SEMS 150 snprintf(current->comm, TASK_COMM_LEN, "e%lx", IPRT_DEBUG_SEMS_ADDRESS(p EventInt));149 snprintf(current->comm, TASK_COMM_LEN, "e%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis)); 151 150 #endif 152 151 for (;;) 153 152 { 154 153 /* make everything thru schedule_timeout() atomic scheduling wise. */ 155 prepare_to_wait(&p EventInt->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);154 prepare_to_wait(&pThis->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); 156 155 157 156 /* check the condition. */ 158 if (ASMAtomicCmpXchgU32(&p EventInt->fState, 0, 1))157 if (ASMAtomicCmpXchgU32(&pThis->fState, 0, 1)) 159 158 break; 160 159 … … 172 171 173 172 /* Check if someone destroyed the semaphore while we were waiting. */ 174 if (p EventInt->u32Magic != RTSEMEVENT_MAGIC)173 if (pThis->u32Magic != RTSEMEVENT_MAGIC) 175 174 { 176 175 rc = VERR_SEM_DESTROYED; … … 186 185 } 187 186 188 finish_wait(&p EventInt->Head, &Wait);187 finish_wait(&pThis->Head, &Wait); 189 188 #ifdef IPRT_DEBUG_SEMS 190 snprintf(current->comm, TASK_COMM_LEN, "e%lx:%d", IPRT_DEBUG_SEMS_ADDRESS(p EventInt), rc);189 snprintf(current->comm, TASK_COMM_LEN, "e%lx:%d", IPRT_DEBUG_SEMS_ADDRESS(pThis), rc); 191 190 #endif 192 191 return rc; … … 194 193 195 194 196 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies) 197 { 198 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 199 if (!pEventInt) 200 return VERR_INVALID_PARAMETER; 201 if ( !pEventInt 202 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 203 { 204 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 205 return VERR_INVALID_PARAMETER; 206 } 207 208 if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1)) 195 RTDECL(int) RTSemEventWait(RTSEMEVENT hEventSem, unsigned cMillies) 196 { 197 PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem; 198 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 199 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 200 201 if (ASMAtomicCmpXchgU32(&pThis->fState, 0, 1)) 209 202 return VINF_SUCCESS; 210 return rtSemEventWait(p EventInt, cMillies, false /* fInterruptible */);203 return rtSemEventWait(pThis, cMillies, false /* fInterruptible */); 211 204 } 212 205 RT_EXPORT_SYMBOL(RTSemEventWait); 213 206 214 207 215 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies) 216 { 217 PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem; 218 if (!pEventInt) 219 return VERR_INVALID_PARAMETER; 220 if ( !pEventInt 221 || pEventInt->u32Magic != RTSEMEVENT_MAGIC) 222 { 223 AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt)); 224 return VERR_INVALID_PARAMETER; 225 } 226 227 if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1)) 208 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT hEventSem, unsigned cMillies) 209 { 210 PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem; 211 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 212 AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 213 214 if (ASMAtomicCmpXchgU32(&pThis->fState, 0, 1)) 228 215 return VINF_SUCCESS; 229 return rtSemEventWait(p EventInt, cMillies, true /* fInterruptible */);216 return rtSemEventWait(pThis, cMillies, true /* fInterruptible */); 230 217 } 231 218 RT_EXPORT_SYMBOL(RTSemEventWaitNoResume);
Note:
See TracChangeset
for help on using the changeset viewer.