Changeset 92700 in vbox for trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp
- Timestamp:
- Dec 2, 2021 12:39:54 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp
r82968 r92700 35 35 #include <VBox/param.h> 36 36 #include <iprt/assert.h> 37 #include <iprt/semaphore.h> 38 #include <iprt/time.h> 37 39 38 40 #include "SUPLibInternal.h" … … 112 114 AssertPtrReturn(phEvent, VERR_INVALID_POINTER); 113 115 114 SUPSEMOP3 Req; 115 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_CREATE, &Req); 116 if (RT_SUCCESS(rc)) 117 *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem; 116 int rc; 117 if (!g_supLibData.fDriverless) 118 { 119 SUPSEMOP3 Req; 120 rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_CREATE, &Req); 121 if (RT_SUCCESS(rc)) 122 *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem; 123 } 124 else 125 { 126 RTSEMEVENT hEvent; 127 rc = RTSemEventCreate(&hEvent); 128 if (RT_SUCCESS(rc)) 129 *phEvent = (SUPSEMEVENT)hEvent; 130 } 118 131 return rc; 119 132 } … … 124 137 if (hEvent == NIL_SUPSEMEVENT) 125 138 return VINF_SUCCESS; 126 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_CLOSE, 0); 139 int rc; 140 if (!g_supLibData.fDriverless) 141 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_CLOSE, 0); 142 else 143 rc = RTSemEventDestroy((RTSEMEVENT)hEvent); 144 return rc; 127 145 } 128 146 … … 130 148 SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent) 131 149 { 132 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_SIGNAL, 0); 150 int rc; 151 if (!g_supLibData.fDriverless) 152 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_SIGNAL, 0); 153 else 154 rc = RTSemEventSignal((RTSEMEVENT)hEvent); 155 return rc; 133 156 } 134 157 … … 136 159 SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies) 137 160 { 138 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_MS_REL, cMillies); 161 int rc; 162 if (!g_supLibData.fDriverless) 163 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_MS_REL, cMillies); 164 else 165 rc = RTSemEventWaitNoResume((RTSEMEVENT)hEvent, cMillies); 166 return rc; 139 167 } 140 168 … … 142 170 SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout) 143 171 { 144 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout); 172 int rc; 173 if (!g_supLibData.fDriverless) 174 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout); 175 else 176 { 177 #if 0 178 rc = RTSemEventWaitEx((RTSEMEVENT)hEvent, 179 RTSEMWAIT_FLAGS_ABSOLUTE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, uNsTimeout); 180 #else 181 uint64_t nsNow = RTTimeNanoTS(); 182 if (nsNow < uNsTimeout) 183 rc = RTSemEventWaitNoResume((RTSEMEVENT)hEvent, (uNsTimeout - nsNow + RT_NS_1MS - 1) / RT_NS_1MS); 184 else 185 rc = VERR_TIMEOUT; 186 #endif 187 } 188 return rc; 145 189 } 146 190 … … 148 192 SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout) 149 193 { 150 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_REL, cNsTimeout); 194 int rc; 195 if (!g_supLibData.fDriverless) 196 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_REL, cNsTimeout); 197 else 198 { 199 #if 0 200 rc = RTSemEventWaitEx((RTSEMEVENT)hEvent, 201 RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, cNsTimeout); 202 #else 203 rc = RTSemEventWaitNoResume((RTSEMEVENT)hEvent, (cNsTimeout + RT_NS_1MS - 1) / RT_NS_1MS); 204 #endif 205 } 206 return rc; 151 207 } 152 208 … … 154 210 SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession) 155 211 { 156 SUPSEMOP3 Req; 157 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_GET_RESOLUTION, &Req); 158 if (RT_SUCCESS(rc)) 159 return Req.u.Out.cNsResolution; 160 return 1000 / 100; 212 if (!g_supLibData.fDriverless) 213 { 214 SUPSEMOP3 Req; 215 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_GET_RESOLUTION, &Req); 216 if (RT_SUCCESS(rc)) 217 return Req.u.Out.cNsResolution; 218 return 1000 / 100; 219 } 220 #if 0 221 return RTSemEventGetResolution(); 222 #else 223 return RT_NS_1MS; 224 #endif 161 225 } 162 226 … … 169 233 AssertPtrReturn(phEventMulti, VERR_INVALID_POINTER); 170 234 171 SUPSEMOP3 Req; 172 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_CREATE, &Req); 173 if (RT_SUCCESS(rc)) 174 *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem; 235 int rc; 236 if (!g_supLibData.fDriverless) 237 { 238 SUPSEMOP3 Req; 239 rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_CREATE, &Req); 240 if (RT_SUCCESS(rc)) 241 *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem; 242 } 243 else 244 { 245 RTSEMEVENTMULTI hEventMulti; 246 rc = RTSemEventMultiCreate(&hEventMulti); 247 if (RT_SUCCESS(rc)) 248 *phEventMulti = (SUPSEMEVENTMULTI)hEventMulti; 249 } 175 250 return rc; 176 251 } … … 181 256 if (hEventMulti == NIL_SUPSEMEVENTMULTI) 182 257 return VINF_SUCCESS; 183 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_CLOSE, 0); 258 int rc; 259 if (!g_supLibData.fDriverless) 260 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_CLOSE, 0); 261 else 262 rc = RTSemEventMultiDestroy((RTSEMEVENTMULTI)hEventMulti); 263 return rc; 184 264 } 185 265 … … 187 267 SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti) 188 268 { 189 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_SIGNAL, 0); 269 int rc; 270 if (!g_supLibData.fDriverless) 271 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_SIGNAL, 0); 272 else 273 rc = RTSemEventMultiSignal((RTSEMEVENTMULTI)hEventMulti); 274 return rc; 190 275 } 191 276 … … 193 278 SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti) 194 279 { 195 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_RESET, 0); 280 int rc; 281 if (!g_supLibData.fDriverless) 282 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_RESET, 0); 283 else 284 rc = RTSemEventMultiReset((RTSEMEVENTMULTI)hEventMulti); 285 return rc; 196 286 } 197 287 … … 199 289 SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies) 200 290 { 201 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_MS_REL, cMillies); 291 int rc; 292 if (!g_supLibData.fDriverless) 293 supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_MS_REL, cMillies); 294 else 295 rc = RTSemEventMultiWaitNoResume((RTSEMEVENTMULTI)hEventMulti, cMillies); 296 return rc; 202 297 } 203 298 … … 205 300 SUPDECL(int) SUPSemEventMultiWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout) 206 301 { 207 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout); 302 int rc; 303 if (!g_supLibData.fDriverless) 304 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout); 305 else 306 { 307 #if 0 308 rc = RTSemEventMultiWaitEx((RTSEMEVENTMULTI)hEventMulti, 309 RTSEMWAIT_FLAGS_ABSOLUTE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, uNsTimeout); 310 #else 311 uint64_t nsNow = RTTimeNanoTS(); 312 if (nsNow < uNsTimeout) 313 rc = RTSemEventMultiWaitNoResume((RTSEMEVENTMULTI)hEventMulti, (uNsTimeout - nsNow + RT_NS_1MS - 1) / RT_NS_1MS); 314 else 315 rc = VERR_TIMEOUT; 316 #endif 317 } 318 return rc; 208 319 } 209 320 … … 211 322 SUPDECL(int) SUPSemEventMultiWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout) 212 323 { 213 return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_REL, cNsTimeout); 324 int rc; 325 if (!g_supLibData.fDriverless) 326 rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_REL, cNsTimeout); 327 else 328 { 329 #if 0 330 rc = RTSemEventMultiWaitEx((RTSEMEVENTMULTI)hEventMulti, 331 RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, cNsTimeout); 332 #else 333 rc = RTSemEventMultiWaitNoResume((RTSEMEVENTMULTI)hEventMulti, (cNsTimeout + RT_NS_1MS - 1) / RT_NS_1MS); 334 #endif 335 } 336 return rc; 214 337 } 215 338 … … 217 340 SUPDECL(uint32_t) SUPSemEventMultiGetResolution(PSUPDRVSESSION pSession) 218 341 { 219 SUPSEMOP3 Req; 220 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_GET_RESOLUTION, &Req); 221 if (RT_SUCCESS(rc)) 222 return Req.u.Out.cNsResolution; 223 return 1000 / 100; 224 } 225 342 if (!g_supLibData.fDriverless) 343 { 344 SUPSEMOP3 Req; 345 int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_GET_RESOLUTION, &Req); 346 if (RT_SUCCESS(rc)) 347 return Req.u.Out.cNsResolution; 348 return 1000 / 100; 349 } 350 #if 0 351 return RTSemEventMultiGetResolution(); 352 #else 353 return RT_NS_1MS; 354 #endif 355 } 356
Note:
See TracChangeset
for help on using the changeset viewer.