Changeset 25381 in vbox
- Timestamp:
- Dec 14, 2009 11:52:28 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56005
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 1 edited
- 5 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r25368 r25381 395 395 generic/RTRandAdvCreateSystemFaster-generic.cpp \ 396 396 generic/RTRandAdvCreateSystemTruer-generic.cpp \ 397 generic/RTSemEventWait-generic.cpp \ 398 generic/RTSemEventMultiWait-generic.cpp \ 399 generic/RTSemMutexRequest-generic.cpp \ 400 generic/RTSemMutexRequestDebug-generic.cpp \ 397 401 generic/mppresent-generic.cpp \ 398 generic/semnoint-generic.cpp \399 402 generic/semsrw-generic.cpp \ 400 403 generic/uuid-generic.cpp \ … … 415 418 r3/win/rtProcInitExePath-win.cpp \ 416 419 r3/win/sched-win.cpp \ 417 r3/win/sems-win.cpp \ 420 r3/win/semevent-win.cpp \ 421 r3/win/semeventmulti-win.cpp \ 422 r3/win/semmutex-win.cpp \ 418 423 r3/win/rtFileNativeSetAttributes-win.cpp \ 419 424 r3/win/thread-win.cpp \ … … 501 506 generic/RTUuidCreate-generic.cpp \ 502 507 generic/mppresent-generic.cpp \ 503 generic/semnoint-generic.cpp \ 508 generic/RTSemEventWait-generic.cpp \ 509 generic/RTSemEventMultiWait-generic.cpp \ 510 generic/RTSemMutexRequest-generic.cpp \ 511 generic/RTSemMutexRequestDebug-generic.cpp \ 504 512 generic/semsrw-generic.cpp \ 505 513 generic/timer-generic.cpp \ … … 690 698 generic/mppresent-generic.cpp \ 691 699 generic/sched-generic.cpp \ 692 generic/semnoint-generic.cpp \ 700 generic/RTSemEventWait-generic.cpp \ 701 generic/RTSemEventMultiWait-generic.cpp \ 702 generic/RTSemMutexRequest-generic.cpp \ 703 generic/RTSemMutexRequestDebug-generic.cpp \ 693 704 generic/semsrw-generic.cpp \ 694 705 generic/utf16locale-generic.cpp \ -
trunk/src/VBox/Runtime/generic/RTSemEventMultiWait-generic.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Generic Non-Interruptable Wait and Request Functions.3 * IPRT - RTSemEventMultiWait, generic RTSemEventMultiWaitNoResume wrapper. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 42 42 43 43 44 45 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies) 46 { 47 int rc; 48 if (cMillies == RT_INDEFINITE_WAIT) 49 { 50 do rc = RTSemEventWaitNoResume(EventSem, cMillies); 51 while (rc == VERR_INTERRUPTED); 52 } 53 else 54 { 55 const uint64_t u64Start = RTTimeMilliTS(); 56 rc = RTSemEventWaitNoResume(EventSem, cMillies); 57 if (rc == VERR_INTERRUPTED) 58 { 59 do 60 { 61 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start; 62 if (u64Elapsed >= cMillies) 63 return VERR_TIMEOUT; 64 rc = RTSemEventWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed); 65 } while (rc == VERR_INTERRUPTED); 66 } 67 } 68 return rc; 69 } 70 RT_EXPORT_SYMBOL(RTSemEventWait); 71 72 44 #undef RTSemEventMultiWait /* undo debug mapping */ 73 45 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventSem, unsigned cMillies) 74 46 { … … 98 70 RT_EXPORT_SYMBOL(RTSemEventMultiWait); 99 71 100 101 #undef RTSemMutexRequest /* undo debug mapping */102 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX Mutex, unsigned cMillies)103 {104 int rc;105 if (cMillies == RT_INDEFINITE_WAIT)106 {107 do rc = RTSemMutexRequestNoResume(Mutex, cMillies);108 while (rc == VERR_INTERRUPTED);109 }110 else111 {112 const uint64_t u64Start = RTTimeMilliTS();113 rc = RTSemMutexRequestNoResume(Mutex, cMillies);114 if (rc == VERR_INTERRUPTED)115 {116 do117 {118 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;119 if (u64Elapsed >= cMillies)120 return VERR_TIMEOUT;121 rc = RTSemMutexRequestNoResume(Mutex, cMillies - (unsigned)u64Elapsed);122 } while (rc == VERR_INTERRUPTED);123 }124 }125 return rc;126 }127 RT_EXPORT_SYMBOL(RTSemMutexRequest);128 129 130 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX Mutex, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)131 {132 int rc;133 if (cMillies == RT_INDEFINITE_WAIT)134 {135 do rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);136 while (rc == VERR_INTERRUPTED);137 }138 else139 {140 const uint64_t u64Start = RTTimeMilliTS();141 rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);142 if (rc == VERR_INTERRUPTED)143 {144 do145 {146 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;147 if (u64Elapsed >= cMillies)148 return VERR_TIMEOUT;149 rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies - (unsigned)u64Elapsed, uId, RT_SRC_POS_ARGS);150 } while (rc == VERR_INTERRUPTED);151 }152 }153 return rc;154 }155 RT_EXPORT_SYMBOL(RTSemMutexRequestDebug);156 -
trunk/src/VBox/Runtime/generic/RTSemEventWait-generic.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Generic Non-Interruptable Wait and Request Functions.3 * IPRT - RTSemEventWait, generic RTSemEventWaitNoResume wrapper. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 42 42 43 43 44 44 #undef RTSemEventWait /* undo debug mapping */ 45 45 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies) 46 46 { … … 70 70 RT_EXPORT_SYMBOL(RTSemEventWait); 71 71 72 73 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventSem, unsigned cMillies)74 {75 int rc;76 if (cMillies == RT_INDEFINITE_WAIT)77 {78 do rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);79 while (rc == VERR_INTERRUPTED);80 }81 else82 {83 const uint64_t u64Start = RTTimeMilliTS();84 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);85 if (rc == VERR_INTERRUPTED)86 {87 do88 {89 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;90 if (u64Elapsed >= cMillies)91 return VERR_TIMEOUT;92 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);93 } while (rc == VERR_INTERRUPTED);94 }95 }96 return rc;97 }98 RT_EXPORT_SYMBOL(RTSemEventMultiWait);99 100 101 #undef RTSemMutexRequest /* undo debug mapping */102 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX Mutex, unsigned cMillies)103 {104 int rc;105 if (cMillies == RT_INDEFINITE_WAIT)106 {107 do rc = RTSemMutexRequestNoResume(Mutex, cMillies);108 while (rc == VERR_INTERRUPTED);109 }110 else111 {112 const uint64_t u64Start = RTTimeMilliTS();113 rc = RTSemMutexRequestNoResume(Mutex, cMillies);114 if (rc == VERR_INTERRUPTED)115 {116 do117 {118 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;119 if (u64Elapsed >= cMillies)120 return VERR_TIMEOUT;121 rc = RTSemMutexRequestNoResume(Mutex, cMillies - (unsigned)u64Elapsed);122 } while (rc == VERR_INTERRUPTED);123 }124 }125 return rc;126 }127 RT_EXPORT_SYMBOL(RTSemMutexRequest);128 129 130 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX Mutex, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)131 {132 int rc;133 if (cMillies == RT_INDEFINITE_WAIT)134 {135 do rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);136 while (rc == VERR_INTERRUPTED);137 }138 else139 {140 const uint64_t u64Start = RTTimeMilliTS();141 rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);142 if (rc == VERR_INTERRUPTED)143 {144 do145 {146 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;147 if (u64Elapsed >= cMillies)148 return VERR_TIMEOUT;149 rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies - (unsigned)u64Elapsed, uId, RT_SRC_POS_ARGS);150 } while (rc == VERR_INTERRUPTED);151 }152 }153 return rc;154 }155 RT_EXPORT_SYMBOL(RTSemMutexRequestDebug);156 -
trunk/src/VBox/Runtime/generic/RTSemMutexRequest-generic.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Generic Non-Interruptable Wait and Request Functions.3 * IPRT - RTSemMutexRequest, generic RTSemMutexRequestNoResume wrapper. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 42 42 43 43 44 45 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)46 {47 int rc;48 if (cMillies == RT_INDEFINITE_WAIT)49 {50 do rc = RTSemEventWaitNoResume(EventSem, cMillies);51 while (rc == VERR_INTERRUPTED);52 }53 else54 {55 const uint64_t u64Start = RTTimeMilliTS();56 rc = RTSemEventWaitNoResume(EventSem, cMillies);57 if (rc == VERR_INTERRUPTED)58 {59 do60 {61 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;62 if (u64Elapsed >= cMillies)63 return VERR_TIMEOUT;64 rc = RTSemEventWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);65 } while (rc == VERR_INTERRUPTED);66 }67 }68 return rc;69 }70 RT_EXPORT_SYMBOL(RTSemEventWait);71 72 73 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventSem, unsigned cMillies)74 {75 int rc;76 if (cMillies == RT_INDEFINITE_WAIT)77 {78 do rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);79 while (rc == VERR_INTERRUPTED);80 }81 else82 {83 const uint64_t u64Start = RTTimeMilliTS();84 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);85 if (rc == VERR_INTERRUPTED)86 {87 do88 {89 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;90 if (u64Elapsed >= cMillies)91 return VERR_TIMEOUT;92 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);93 } while (rc == VERR_INTERRUPTED);94 }95 }96 return rc;97 }98 RT_EXPORT_SYMBOL(RTSemEventMultiWait);99 100 101 44 #undef RTSemMutexRequest /* undo debug mapping */ 102 45 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX Mutex, unsigned cMillies) … … 127 70 RT_EXPORT_SYMBOL(RTSemMutexRequest); 128 71 129 130 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX Mutex, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)131 {132 int rc;133 if (cMillies == RT_INDEFINITE_WAIT)134 {135 do rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);136 while (rc == VERR_INTERRUPTED);137 }138 else139 {140 const uint64_t u64Start = RTTimeMilliTS();141 rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);142 if (rc == VERR_INTERRUPTED)143 {144 do145 {146 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;147 if (u64Elapsed >= cMillies)148 return VERR_TIMEOUT;149 rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies - (unsigned)u64Elapsed, uId, RT_SRC_POS_ARGS);150 } while (rc == VERR_INTERRUPTED);151 }152 }153 return rc;154 }155 RT_EXPORT_SYMBOL(RTSemMutexRequestDebug);156 -
trunk/src/VBox/Runtime/generic/RTSemMutexRequestDebug-generic.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Generic Non-Interruptable Wait and Request Functions.3 * IPRT - RTSemMutexRequestDebug, generic RTSemMutexRequestNoResumeDebug wrapper. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 43 43 44 44 45 RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)46 {47 int rc;48 if (cMillies == RT_INDEFINITE_WAIT)49 {50 do rc = RTSemEventWaitNoResume(EventSem, cMillies);51 while (rc == VERR_INTERRUPTED);52 }53 else54 {55 const uint64_t u64Start = RTTimeMilliTS();56 rc = RTSemEventWaitNoResume(EventSem, cMillies);57 if (rc == VERR_INTERRUPTED)58 {59 do60 {61 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;62 if (u64Elapsed >= cMillies)63 return VERR_TIMEOUT;64 rc = RTSemEventWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);65 } while (rc == VERR_INTERRUPTED);66 }67 }68 return rc;69 }70 RT_EXPORT_SYMBOL(RTSemEventWait);71 72 73 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventSem, unsigned cMillies)74 {75 int rc;76 if (cMillies == RT_INDEFINITE_WAIT)77 {78 do rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);79 while (rc == VERR_INTERRUPTED);80 }81 else82 {83 const uint64_t u64Start = RTTimeMilliTS();84 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);85 if (rc == VERR_INTERRUPTED)86 {87 do88 {89 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;90 if (u64Elapsed >= cMillies)91 return VERR_TIMEOUT;92 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);93 } while (rc == VERR_INTERRUPTED);94 }95 }96 return rc;97 }98 RT_EXPORT_SYMBOL(RTSemEventMultiWait);99 100 101 #undef RTSemMutexRequest /* undo debug mapping */102 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX Mutex, unsigned cMillies)103 {104 int rc;105 if (cMillies == RT_INDEFINITE_WAIT)106 {107 do rc = RTSemMutexRequestNoResume(Mutex, cMillies);108 while (rc == VERR_INTERRUPTED);109 }110 else111 {112 const uint64_t u64Start = RTTimeMilliTS();113 rc = RTSemMutexRequestNoResume(Mutex, cMillies);114 if (rc == VERR_INTERRUPTED)115 {116 do117 {118 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;119 if (u64Elapsed >= cMillies)120 return VERR_TIMEOUT;121 rc = RTSemMutexRequestNoResume(Mutex, cMillies - (unsigned)u64Elapsed);122 } while (rc == VERR_INTERRUPTED);123 }124 }125 return rc;126 }127 RT_EXPORT_SYMBOL(RTSemMutexRequest);128 129 130 45 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX Mutex, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 131 46 { -
trunk/src/VBox/Runtime/r3/win/semevent-win.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Semaphores, implementation for Windows host platform.3 * IPRT - Event Sempahore, Windows. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 51 51 52 52 /* Undefine debug mappings. */ 53 #undef RTSem MutexRequest54 #undef RTSem MutexRequestNoResume53 #undef RTSemEventWait 54 #undef RTSemEventWaitNoResume 55 55 56 56 … … 124 124 } 125 125 126 127 128 129 RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)130 {131 /*132 * Create the semaphore.133 * (Manual reset, not signaled, private event object.)134 */135 HANDLE hev = CreateEvent(NULL, TRUE, FALSE, NULL);136 if (hev)137 {138 *pEventMultiSem = (RTSEMEVENTMULTI)(void *)hev;139 return VINF_SUCCESS;140 }141 return RTErrConvertFromWin32(GetLastError());142 }143 144 145 RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)146 {147 /*148 * Close semaphore handle.149 */150 if (CloseHandle(SEM2HND(EventMultiSem)))151 return VINF_SUCCESS;152 AssertMsgFailed(("Destroy EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));153 return RTErrConvertFromWin32(GetLastError());154 }155 156 157 RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)158 {159 /*160 * Signal the object.161 */162 if (SetEvent(SEM2HND(EventMultiSem)))163 return VINF_SUCCESS;164 AssertMsgFailed(("Signaling EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));165 return RTErrConvertFromWin32(GetLastError());166 }167 168 169 RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)170 {171 /*172 * Reset the object.173 */174 if (ResetEvent(SEM2HND(EventMultiSem)))175 return VINF_SUCCESS;176 AssertMsgFailed(("Resetting EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));177 return RTErrConvertFromWin32(GetLastError());178 }179 180 181 RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)182 {183 /*184 * Wait for condition.185 */186 int rc = WaitForSingleObjectEx(SEM2HND(EventMultiSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);187 switch (rc)188 {189 case WAIT_OBJECT_0: return VINF_SUCCESS;190 case WAIT_TIMEOUT: return VERR_TIMEOUT;191 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;192 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;193 default:194 {195 AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d lasterr=%d\n", EventMultiSem, rc, GetLastError()));196 int rc2 = RTErrConvertFromWin32(GetLastError());197 if (rc2)198 return rc2;199 200 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));201 return VERR_INTERNAL_ERROR;202 }203 }204 }205 206 207 208 209 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)210 {211 /*212 * Create the semaphore.213 */214 HANDLE hmtx = CreateMutex(NULL, FALSE, NULL);215 if (hmtx)216 {217 *pMutexSem = (RTSEMMUTEX)(void *)hmtx;218 return VINF_SUCCESS;219 }220 221 return RTErrConvertFromWin32(GetLastError());222 }223 224 225 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)226 {227 /*228 * Close semaphore handle.229 */230 if (CloseHandle(SEM2HND(MutexSem)))231 return VINF_SUCCESS;232 AssertMsgFailed(("Destroy MutexSem %p failed, lasterr=%d\n", MutexSem, GetLastError()));233 return RTErrConvertFromWin32(GetLastError());234 }235 236 237 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)238 {239 /*240 * Lock mutex semaphore.241 */242 int rc = WaitForSingleObjectEx(SEM2HND(MutexSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);243 switch (rc)244 {245 case WAIT_OBJECT_0:246 {247 #ifdef RTSEMMUTEX_STRICT248 RTTHREAD Thread = RTThreadSelf();249 if (Thread != NIL_RTTHREAD)250 RTThreadWriteLockInc(Thread);251 #endif252 return VINF_SUCCESS;253 }254 255 case WAIT_TIMEOUT: return VERR_TIMEOUT;256 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;257 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;258 default:259 {260 AssertMsgFailed(("Wait on MutexSem %p failed, rc=%d lasterr=%d\n", MutexSem, rc, GetLastError()));261 int rc2 = RTErrConvertFromWin32(GetLastError());262 if (rc2 != 0)263 return rc2;264 265 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));266 return VERR_INTERNAL_ERROR;267 }268 }269 }270 271 272 RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)273 {274 return RTSemMutexRequestNoResume(MutexSem, cMillies);275 }276 277 278 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)279 {280 /*281 * Unlock mutex semaphore.282 */283 #ifdef RTSEMMUTEX_STRICT284 RTTHREAD Thread = RTThreadSelf();285 if (Thread != NIL_RTTHREAD)286 RTThreadWriteLockDec(Thread);287 #endif288 if (ReleaseMutex(SEM2HND(MutexSem)))289 return VINF_SUCCESS;290 291 #ifdef RTSEMMUTEX_STRICT292 if (Thread != NIL_RTTHREAD)293 RTThreadWriteLockInc(Thread);294 #endif295 AssertMsgFailed(("Release MutexSem %p failed, lasterr=%d\n", MutexSem, GetLastError()));296 return RTErrConvertFromWin32(GetLastError());297 }298 -
trunk/src/VBox/Runtime/r3/win/semeventmulti-win.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Semaphores, implementation for Windows host platform.3 * IPRT - Multiple Release Event Semaphore, Windows. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 51 51 52 52 /* Undefine debug mappings. */ 53 #undef RTSemMutexRequest 54 #undef RTSemMutexRequestNoResume 55 56 57 RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem) 58 { 59 /* 60 * Create the semaphore. 61 * (Auto reset, not signaled, private event object.) 62 */ 63 HANDLE hev = CreateEvent(NULL, FALSE, FALSE, NULL); 64 if (hev) 65 { 66 *pEventSem = (RTSEMEVENT)(void *)hev; 67 Assert(*pEventSem != NIL_RTSEMEVENT); 68 return VINF_SUCCESS; 69 } 70 return RTErrConvertFromWin32(GetLastError()); 71 } 72 73 74 RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem) 75 { 76 if (EventSem == NIL_RTSEMEVENT) /* don't bitch */ 77 return VERR_INVALID_HANDLE; 78 79 /* 80 * Close semaphore handle. 81 */ 82 if (CloseHandle(SEM2HND(EventSem))) 83 return VINF_SUCCESS; 84 AssertMsgFailed(("Destroy EventSem %p failed, lasterr=%d\n", EventSem, GetLastError())); 85 return RTErrConvertFromWin32(GetLastError()); 86 } 87 88 89 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies) 90 { 91 /* 92 * Wait for condition. 93 */ 94 int rc = WaitForSingleObjectEx(SEM2HND(EventSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE); 95 switch (rc) 96 { 97 case WAIT_OBJECT_0: return VINF_SUCCESS; 98 case WAIT_TIMEOUT: return VERR_TIMEOUT; 99 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED; 100 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED; 101 default: 102 { 103 AssertMsgFailed(("Wait on EventSem %p failed, rc=%d lasterr=%d\n", EventSem, rc, GetLastError())); 104 int rc2 = RTErrConvertFromWin32(GetLastError()); 105 if (rc2) 106 return rc2; 107 108 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2)); 109 return VERR_INTERNAL_ERROR; 110 } 111 } 112 } 113 114 115 RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem) 116 { 117 /* 118 * Signal the object. 119 */ 120 if (SetEvent(SEM2HND(EventSem))) 121 return VINF_SUCCESS; 122 AssertMsgFailed(("Signaling EventSem %p failed, lasterr=%d\n", EventSem, GetLastError())); 123 return RTErrConvertFromWin32(GetLastError()); 124 } 125 126 53 #undef RTSemEventMultiWait 54 #undef RTSemEventMultiWaitNoResume 127 55 128 56 … … 204 132 } 205 133 206 207 208 209 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)210 {211 /*212 * Create the semaphore.213 */214 HANDLE hmtx = CreateMutex(NULL, FALSE, NULL);215 if (hmtx)216 {217 *pMutexSem = (RTSEMMUTEX)(void *)hmtx;218 return VINF_SUCCESS;219 }220 221 return RTErrConvertFromWin32(GetLastError());222 }223 224 225 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)226 {227 /*228 * Close semaphore handle.229 */230 if (CloseHandle(SEM2HND(MutexSem)))231 return VINF_SUCCESS;232 AssertMsgFailed(("Destroy MutexSem %p failed, lasterr=%d\n", MutexSem, GetLastError()));233 return RTErrConvertFromWin32(GetLastError());234 }235 236 237 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)238 {239 /*240 * Lock mutex semaphore.241 */242 int rc = WaitForSingleObjectEx(SEM2HND(MutexSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);243 switch (rc)244 {245 case WAIT_OBJECT_0:246 {247 #ifdef RTSEMMUTEX_STRICT248 RTTHREAD Thread = RTThreadSelf();249 if (Thread != NIL_RTTHREAD)250 RTThreadWriteLockInc(Thread);251 #endif252 return VINF_SUCCESS;253 }254 255 case WAIT_TIMEOUT: return VERR_TIMEOUT;256 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;257 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;258 default:259 {260 AssertMsgFailed(("Wait on MutexSem %p failed, rc=%d lasterr=%d\n", MutexSem, rc, GetLastError()));261 int rc2 = RTErrConvertFromWin32(GetLastError());262 if (rc2 != 0)263 return rc2;264 265 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));266 return VERR_INTERNAL_ERROR;267 }268 }269 }270 271 272 RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)273 {274 return RTSemMutexRequestNoResume(MutexSem, cMillies);275 }276 277 278 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)279 {280 /*281 * Unlock mutex semaphore.282 */283 #ifdef RTSEMMUTEX_STRICT284 RTTHREAD Thread = RTThreadSelf();285 if (Thread != NIL_RTTHREAD)286 RTThreadWriteLockDec(Thread);287 #endif288 if (ReleaseMutex(SEM2HND(MutexSem)))289 return VINF_SUCCESS;290 291 #ifdef RTSEMMUTEX_STRICT292 if (Thread != NIL_RTTHREAD)293 RTThreadWriteLockInc(Thread);294 #endif295 AssertMsgFailed(("Release MutexSem %p failed, lasterr=%d\n", MutexSem, GetLastError()));296 return RTErrConvertFromWin32(GetLastError());297 }298 -
trunk/src/VBox/Runtime/r3/win/semmutex-win.cpp
r25379 r25381 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Semaphores, implementation for Windows host platform.3 * IPRT - Mutex Semaphores, Windows. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 53 53 #undef RTSemMutexRequest 54 54 #undef RTSemMutexRequestNoResume 55 56 57 RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem)58 {59 /*60 * Create the semaphore.61 * (Auto reset, not signaled, private event object.)62 */63 HANDLE hev = CreateEvent(NULL, FALSE, FALSE, NULL);64 if (hev)65 {66 *pEventSem = (RTSEMEVENT)(void *)hev;67 Assert(*pEventSem != NIL_RTSEMEVENT);68 return VINF_SUCCESS;69 }70 return RTErrConvertFromWin32(GetLastError());71 }72 73 74 RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem)75 {76 if (EventSem == NIL_RTSEMEVENT) /* don't bitch */77 return VERR_INVALID_HANDLE;78 79 /*80 * Close semaphore handle.81 */82 if (CloseHandle(SEM2HND(EventSem)))83 return VINF_SUCCESS;84 AssertMsgFailed(("Destroy EventSem %p failed, lasterr=%d\n", EventSem, GetLastError()));85 return RTErrConvertFromWin32(GetLastError());86 }87 88 89 RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)90 {91 /*92 * Wait for condition.93 */94 int rc = WaitForSingleObjectEx(SEM2HND(EventSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);95 switch (rc)96 {97 case WAIT_OBJECT_0: return VINF_SUCCESS;98 case WAIT_TIMEOUT: return VERR_TIMEOUT;99 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;100 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;101 default:102 {103 AssertMsgFailed(("Wait on EventSem %p failed, rc=%d lasterr=%d\n", EventSem, rc, GetLastError()));104 int rc2 = RTErrConvertFromWin32(GetLastError());105 if (rc2)106 return rc2;107 108 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));109 return VERR_INTERNAL_ERROR;110 }111 }112 }113 114 115 RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem)116 {117 /*118 * Signal the object.119 */120 if (SetEvent(SEM2HND(EventSem)))121 return VINF_SUCCESS;122 AssertMsgFailed(("Signaling EventSem %p failed, lasterr=%d\n", EventSem, GetLastError()));123 return RTErrConvertFromWin32(GetLastError());124 }125 126 127 128 129 RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)130 {131 /*132 * Create the semaphore.133 * (Manual reset, not signaled, private event object.)134 */135 HANDLE hev = CreateEvent(NULL, TRUE, FALSE, NULL);136 if (hev)137 {138 *pEventMultiSem = (RTSEMEVENTMULTI)(void *)hev;139 return VINF_SUCCESS;140 }141 return RTErrConvertFromWin32(GetLastError());142 }143 144 145 RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)146 {147 /*148 * Close semaphore handle.149 */150 if (CloseHandle(SEM2HND(EventMultiSem)))151 return VINF_SUCCESS;152 AssertMsgFailed(("Destroy EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));153 return RTErrConvertFromWin32(GetLastError());154 }155 156 157 RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)158 {159 /*160 * Signal the object.161 */162 if (SetEvent(SEM2HND(EventMultiSem)))163 return VINF_SUCCESS;164 AssertMsgFailed(("Signaling EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));165 return RTErrConvertFromWin32(GetLastError());166 }167 168 169 RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)170 {171 /*172 * Reset the object.173 */174 if (ResetEvent(SEM2HND(EventMultiSem)))175 return VINF_SUCCESS;176 AssertMsgFailed(("Resetting EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));177 return RTErrConvertFromWin32(GetLastError());178 }179 180 181 RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)182 {183 /*184 * Wait for condition.185 */186 int rc = WaitForSingleObjectEx(SEM2HND(EventMultiSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);187 switch (rc)188 {189 case WAIT_OBJECT_0: return VINF_SUCCESS;190 case WAIT_TIMEOUT: return VERR_TIMEOUT;191 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;192 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;193 default:194 {195 AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d lasterr=%d\n", EventMultiSem, rc, GetLastError()));196 int rc2 = RTErrConvertFromWin32(GetLastError());197 if (rc2)198 return rc2;199 200 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));201 return VERR_INTERNAL_ERROR;202 }203 }204 }205 206 207 55 208 56
Note:
See TracChangeset
for help on using the changeset viewer.