s64 iTime_getLocalMs(void) { SYSTEMTIME time; GetLocalTime(&time); return(iTime_computeMilliseconds(&time)); }
s64 iTime_getSystemMs(void) { SYSTEMTIME time; GetSystemTime(&time); return(iTime_computeMilliseconds(&time)); }
////////// // // Called to potentially retry so long as the callback returns true. // ////// SDiskLock* iDisk_lock_range_retryCallback(SThisCode* thisCode, SBuilder* lockRoot, s32 tnFile, s64 tnOffset, s32 tnLength, uptr tnCallbackFunction, uptr tnExtra) { s32 lnAttempts, lnMillisecondsDelta; s64 lnMillisecondsStart; SDiskLock* dl; SDiskLockCallback dcb; ////////// // Initialize ////// memset(&dcb, 0, sizeof(dcb)); dcb._diskRetryLockCallback = tnCallbackFunction; dcb.extra = tnExtra; lnAttempts = 0; ////////// // Begin the trial ////// GetLocalTime(&dcb.timeStart); lnMillisecondsStart = iTime_computeMilliseconds(&dcb.timeStart); while (1) { ////////// // Try to lock ////// ++lnAttempts; dl = iDisk_lock_range(thisCode, lockRoot, tnFile, tnOffset, tnLength, tnExtra); ////////// // Were we successful? ////// if (dl && dl->nLength == tnLength) return(dl); // Yes ////////// // When we get here, we need to see if they want to continue waiting or not ////// GetLocalTime(&dcb.timeNow); lnMillisecondsDelta = (s32)iTime_computeMillisecondsBetween(&dcb.timeNow, lnMillisecondsStart); ////////// // Inquire politely about our retry ////// if (!dcb._diskRetryLockCallback || !dcb.diskRetryLockCallback(thisCode, &dcb, lnAttempts, lnMillisecondsDelta)) { // They inform us: "No more waiting!" return(dl); // Failure } // If we get here, try again } }
////////// // // Time functions // ////// // Computes time1 - time2 s64 iTime_computeMillisecondsBetween(SYSTEMTIME* time1, SYSTEMTIME* time2) { s64 lnMs1, lnMs2; // Compute the times together if (time1 && time2) { // Grab each lnMs1 = iTime_computeMilliseconds(time1); lnMs2 = iTime_computeMilliseconds(time2); // Return the result return(lnMs1 - lnMs2); } else { // return(0); } }