Changeset 92780 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Dec 7, 2021 10:26:50 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 148698
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/semwait.h
r92776 r92780 48 48 49 49 /** 50 * Converts a extended wait timeout specification to timespec.51 *52 * This does _not_ cover indefinite waits!53 *54 * @returns Approximate number of milliseconds to wait. This is only guaranteed55 * to be correct in that it is zero for non-blocking polling calls and56 * non-zero for the rest.57 * @param pTsDeadline Where to return the deadline.58 * @param fFlags RTSEMWAIT_FLAGS_XXX.59 * @param uTimeout The timeout.60 */61 DECLINLINE(uint32_t) rtSemPosixCalcDeadline(struct timespec *pTsDeadline, uint32_t fFlags, uint64_t uTimeout)62 {63 uint64_t cApproxMillies;64 if (fFlags & RTSEMWAIT_FLAGS_RELATIVE)65 {66 Assert(!(fFlags & RTSEMWAIT_FLAGS_RELATIVE));67 68 #if defined(RT_OS_DARWIN) || defined(RT_OS_HAIKU)69 struct timeval tv = {0,0};70 gettimeofday(&tv, NULL);71 pTsDeadline->tv_sec = tv.tv_sec;72 pTsDeadline->tv_nsec = tv.tv_usec * RT_NS_1US;73 #else74 clock_gettime(CLOCK_REALTIME, pTsDeadline);75 #endif76 if (uTimeout == 0)77 cApproxMillies = 0;78 else79 {80 if (fFlags & RTSEMWAIT_FLAGS_MILLISECS)81 {82 Assert(!(fFlags & RTSEMWAIT_FLAGS_NANOSECS));83 cApproxMillies = uTimeout;84 pTsDeadline->tv_sec += uTimeout / RT_MS_1SEC;85 pTsDeadline->tv_nsec += (uTimeout % RT_MS_1SEC) * RT_NS_1MS;86 }87 else88 {89 Assert(fFlags & RTSEMWAIT_FLAGS_NANOSECS);90 cApproxMillies = (uTimeout + RT_NS_1MS - 1) / RT_NS_1MS; Assert(cApproxMillies > 0);91 pTsDeadline->tv_sec += uTimeout / RT_NS_1SEC;92 pTsDeadline->tv_nsec += uTimeout % RT_NS_1SEC;93 }94 if (pTsDeadline->tv_nsec >= RT_NS_1SEC)95 {96 pTsDeadline->tv_nsec -= RT_NS_1SEC;97 pTsDeadline->tv_sec++;98 }99 }100 }101 /*102 * Absolute time (ASSUMING we all use the same clock here).103 */104 else if (fFlags & RTSEMWAIT_FLAGS_NANOSECS)105 {106 Assert(!(fFlags & RTSEMWAIT_FLAGS_MILLISECS));107 pTsDeadline->tv_sec = uTimeout / RT_NS_1SEC;108 pTsDeadline->tv_nsec = uTimeout % RT_NS_1SEC;109 cApproxMillies = RT_MS_30SEC; /* whatever, we're not going to calculate it */110 }111 else112 {113 Assert(fFlags & RTSEMWAIT_FLAGS_MILLISECS);114 pTsDeadline->tv_sec = uTimeout / RT_MS_1SEC;115 pTsDeadline->tv_nsec = (uTimeout % RT_MS_1SEC) * RT_NS_1MS;116 cApproxMillies = RT_MS_30SEC; /* whatever, we're not going to calculate it */117 }118 return (uint32_t)RT_MIN(cApproxMillies, UINT32_MAX - 1);119 }120 121 122 /**123 50 * Converts a extended wait timeout specification to an absolute timespec and a 124 51 * relative nanosecond count. … … 130 57 * an effectively indefinite wait. 131 58 * @param fFlags RTSEMWAIT_FLAGS_XXX. 59 * @param fMonotonicClock Whether the timeout is in monotonic (true) or real 60 * (false) time. 132 61 * @param uTimeout The timeout. 133 62 * @param pAbsDeadline Where to return the absolute deadline.
Note:
See TracChangeset
for help on using the changeset viewer.