Changeset 25714 in vbox for trunk/src/VBox/Runtime/r0drv/nt
- Timestamp:
- Jan 11, 2010 12:40:15 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56453
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp
r25433 r25714 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Sun Microsystems, Inc.7 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 64 64 65 65 66 /* Undefine debug mappings. */ 67 #undef RTSemMutexRequest 68 #undef RTSemMutexRequestNoResume 69 70 71 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem) 72 { 73 Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *)); 74 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pMutexInt)); 75 if (pMutexInt) 76 { 77 pMutexInt->u32Magic = RTSEMMUTEX_MAGIC; 78 #ifdef RT_USE_FAST_MUTEX 79 ExInitializeFastMutex(&pMutexInt->Mutex); 66 67 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phMutexSem) 68 { 69 return RTSemMutexCreateEx(phMutexSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL); 70 } 71 72 73 RTDECL(int) RTSemMutexCreateEx(PRTSEMMUTEX phMutexSem, uint32_t fFlags, 74 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...) 75 { 76 AssertReturn(!(fFlags & ~RTSEMMUTEX_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER); 77 78 AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *)); 79 PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis)); 80 if (!pThis) 81 return VERR_NO_MEMORY; 82 83 pThis->u32Magic = RTSEMMUTEX_MAGIC; 84 #ifdef RT_USE_FAST_MUTEX 85 ExInitializeFastMutex(&pThis->Mutex); 80 86 #else 81 KeInitializeMutex(&pMutexInt->Mutex, 0);87 KeInitializeMutex(&pThis->Mutex, 0); 82 88 #endif 83 *pMutexSem = pMutexInt; 89 90 *phMutexSem = pThis; 91 return VINF_SUCCESS; 92 } 93 94 95 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem) 96 { 97 /* 98 * Validate input. 99 */ 100 PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem; 101 if (pThis == NIL_RTSEMMUTEX) 84 102 return VINF_SUCCESS; 85 } 86 return VERR_NO_MEMORY; 87 } 88 89 90 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem) 91 { 92 /* 93 * Validate input. 94 */ 95 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem; 96 if (!pMutexInt) 97 return VERR_INVALID_PARAMETER; 98 AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 103 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 104 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 99 105 100 106 /* 101 107 * Invalidate it and signal the object just in case. 102 108 */ 103 AssertReturn(ASMAtomicCmpXchgU32(&p MutexInt->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);104 RTMemFree(p MutexInt);109 AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE); 110 RTMemFree(pThis); 105 111 return VINF_SUCCESS; 106 112 } … … 122 128 * Validate input. 123 129 */ 124 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem; 125 if (!pMutexInt) 126 return VERR_INVALID_PARAMETER; 127 AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 130 PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem; 131 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 132 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 128 133 129 134 /* … … 132 137 #ifdef RT_USE_FAST_MUTEX 133 138 AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n")); 134 ExAcquireFastMutex(&p MutexInt->Mutex);139 ExAcquireFastMutex(&pThis->Mutex); 135 140 #else /* !RT_USE_FAST_MUTEX */ 136 141 NTSTATUS rcNt; 137 142 if (cMillies == RT_INDEFINITE_WAIT) 138 rcNt = KeWaitForSingleObject(&p MutexInt->Mutex, Executive, KernelMode, fInterruptible, NULL);143 rcNt = KeWaitForSingleObject(&pThis->Mutex, Executive, KernelMode, fInterruptible, NULL); 139 144 else 140 145 { 141 146 LARGE_INTEGER Timeout; 142 147 Timeout.QuadPart = -(int64_t)cMillies * 10000; 143 rcNt = KeWaitForSingleObject(&p MutexInt->Mutex, Executive, KernelMode, fInterruptible, &Timeout);148 rcNt = KeWaitForSingleObject(&pThis->Mutex, Executive, KernelMode, fInterruptible, &Timeout); 144 149 } 145 150 switch (rcNt) 146 151 { 147 152 case STATUS_SUCCESS: 148 if (p MutexInt->u32Magic == RTSEMMUTEX_MAGIC)153 if (pThis->u32Magic == RTSEMMUTEX_MAGIC) 149 154 return VINF_SUCCESS; 150 155 return VERR_SEM_DESTROYED; … … 159 164 160 165 default: 161 AssertMsgFailed(("p MutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n",162 p MutexInt->u32Magic, pMutexInt, (long)rcNt));166 AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n", 167 pThis->u32Magic, pThis, (long)rcNt)); 163 168 return VERR_INTERNAL_ERROR; 164 169 } … … 168 173 169 174 175 #undef RTSemMutexRequest 170 176 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies) 171 177 { … … 180 186 181 187 188 #undef RTSemMutexRequestNoResume 182 189 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies) 183 190 { … … 197 204 * Validate input. 198 205 */ 199 PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem; 200 if (!pMutexInt) 201 return VERR_INVALID_PARAMETER; 202 AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 206 PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem; 207 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 208 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 203 209 204 210 /* … … 206 212 */ 207 213 #ifdef RT_USE_FAST_MUTEX 208 ExReleaseFastMutex(&p MutexInt->Mutex);214 ExReleaseFastMutex(&pThis->Mutex); 209 215 #else 210 KeReleaseMutex(&p MutexInt->Mutex, FALSE /*Wait*/);216 KeReleaseMutex(&pThis->Mutex, FALSE /*Wait*/); 211 217 #endif 212 218 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.