Changeset 30961 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Jul 21, 2010 1:39:14 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63851
- Location:
- trunk/src/VBox/Runtime/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/log/log.cpp
r30849 r30961 2340 2340 if (pLogger->fFlags & RTLOGFLAGS_PREFIX_TS) 2341 2341 { 2342 #if defined(IN_RING3) || defined(IN_RC) 2343 uint64_t u64 = RTTimeNanoTS(); 2344 #else 2345 uint64_t u64 = ~0; 2346 #endif 2342 uint64_t u64 = RTTimeNanoTS(); 2347 2343 int iBase = 16; 2348 2344 unsigned int fFlags = RTSTR_F_ZEROPAD; … … 2407 2403 if (pLogger->fFlags & RTLOGFLAGS_PREFIX_TIME) 2408 2404 { 2409 #if def IN_RING32405 #if defined(IN_RING3) || defined(IN_RING0) 2410 2406 RTTIMESPEC TimeSpec; 2411 2407 RTTIME Time; -
trunk/src/VBox/Runtime/common/time/time.cpp
r28800 r30961 257 257 RTDECL(PRTTIME) RTTimeExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec) 258 258 { 259 int64_t i64Div; 260 int32_t i32Div; 261 int32_t i32Rem; 262 unsigned iYear; 263 const uint16_t *paiDayOfYear; 264 int iMonth; 265 259 266 AssertMsg(VALID_PTR(pTime), ("%p\n", pTime)); 260 267 AssertMsg(VALID_PTR(pTimeSpec), ("%p\n", pTime)); … … 263 270 * The simple stuff first. 264 271 */ 265 pTime->fFlags 266 i nt64_t i64Div = pTimeSpec->i64NanosecondsRelativeToUnixEpoch;267 i nt32_t i32Rem = (int32_t)(i64Div % 1000000000);272 pTime->fFlags = RTTIME_FLAGS_TYPE_UTC; 273 i64Div = pTimeSpec->i64NanosecondsRelativeToUnixEpoch; 274 i32Rem = (int32_t)(i64Div % 1000000000); 268 275 i64Div /= 1000000000; 269 276 if (i32Rem < 0) … … 285 292 286 293 /* minute */ 287 i nt32_t i32Div = (int32_t)i64Div; /* 60,000,000,000 > 33bit, so 31bit suffices. */294 i32Div = (int32_t)i64Div; /* 60,000,000,000 > 33bit, so 31bit suffices. */ 288 295 i32Rem = i32Div % 60; 289 296 i32Div /= 60; … … 314 321 * generate a table and perform a simple two way search from the modulus 365 derived. 315 322 */ 316 unsignediYear = OFF_YEAR_IDX_EPOCH + i32Div / 365;323 iYear = OFF_YEAR_IDX_EPOCH + i32Div / 365; 317 324 while (g_aoffYear[iYear + 1] <= i32Div) 318 325 iYear++; … … 327 334 * ensure that the index is matching or too small. 328 335 */ 329 const uint16_t *paiDayOfYear;330 336 if (rtTimeIsLeapYear(pTime->i32Year)) 331 337 { … … 338 344 paiDayOfYear = &g_aiDayOfYear[0]; 339 345 } 340 i nt iMonth = i32Div / 32;346 iMonth = i32Div / 32; 341 347 i32Div++; 342 348 while (paiDayOfYear[iMonth + 1] <= i32Div) … … 370 376 RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime) 371 377 { 378 int32_t i32Days; 379 uint32_t u32Secs; 380 int64_t i64Nanos; 381 372 382 /* 373 383 * Validate input. … … 386 396 * Do the conversion to nanoseconds. 387 397 */ 388 i nt32_t i32Days = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR]389 398 i32Days = g_aoffYear[pTime->i32Year - OFF_YEAR_IDX_0_YEAR] 399 + pTime->u16YearDay - 1; 390 400 AssertMsgReturn(i32Days <= RTTIME_MAX_DAY && i32Days >= RTTIME_MIN_DAY, ("%RI32\n", i32Days), NULL); 391 401 392 u int32_t u32Secs= pTime->u8Second393 394 395 i nt64_t i64Nanos = (uint64_t)pTime->u32Nanosecond396 402 u32Secs = pTime->u8Second 403 + pTime->u8Minute * 60 404 + pTime->u8Hour * 3600; 405 i64Nanos = (uint64_t)pTime->u32Nanosecond 406 + u32Secs * UINT64_C(1000000000); 397 407 AssertMsgReturn(i32Days != RTTIME_MAX_DAY || i64Nanos <= RTTIME_MAX_DAY_NANO, ("%RI64\n", i64Nanos), NULL); 398 408 AssertMsgReturn(i32Days != RTTIME_MIN_DAY || i64Nanos >= RTTIME_MIN_DAY_NANO, ("%RI64\n", i64Nanos), NULL); … … 412 422 PRTTIME rtTimeNormalizeInternal(PRTTIME pTime) 413 423 { 424 unsigned uSecond; 425 unsigned uMinute; 426 unsigned uHour; 427 bool fLeapYear; 428 414 429 /* 415 430 * Fix the YearDay and Month/MonthDay. 416 431 */ 417 boolfLeapYear = rtTimeIsLeapYear(pTime->i32Year);432 fLeapYear = rtTimeIsLeapYear(pTime->i32Year); 418 433 if (!pTime->u16YearDay) 419 434 { … … 469 484 do 470 485 { 486 uint16_t u16YearDay; 487 471 488 /* If you change one, zero the other to make clear what you mean. */ 472 489 AssertBreak(pTime->u8Month <= 12); … … 474 491 ? g_acDaysInMonthsLeap[pTime->u8Month - 1] 475 492 : g_acDaysInMonths[pTime->u8Month - 1])); 476 u int16_t u16YearDay = pTime->u8MonthDay - 1477 478 479 493 u16YearDay = pTime->u8MonthDay - 1 494 + (fLeapYear 495 ? g_aiDayOfYearLeap[pTime->u8Month - 1] 496 : g_aiDayOfYear[pTime->u8Month - 1]); 480 497 AssertBreak(u16YearDay == pTime->u16YearDay); 481 498 fRecalc = false; … … 484 501 if (fRecalc) 485 502 { 503 const uint16_t *paiDayOfYear; 504 486 505 /* overflow adjust YearDay */ 487 506 while (pTime->u16YearDay > (fLeapYear ? 366 : 365)) … … 494 513 495 514 /* calc Month and MonthDay */ 496 const uint16_t *paiDayOfYear = fLeapYear497 498 515 paiDayOfYear = fLeapYear 516 ? &g_aiDayOfYearLeap[0] 517 : &g_aiDayOfYear[0]; 499 518 pTime->u8Month = 1; 500 519 while (pTime->u16YearDay > paiDayOfYear[pTime->u8Month]) … … 509 528 * Use unsigned int values internally to avoid overflows. 510 529 */ 511 u nsigned uSecond = pTime->u8Second;512 u nsigned uMinute = pTime->u8Minute;513 u nsigned uHour = pTime->u8Hour;530 uSecond = pTime->u8Second; 531 uMinute = pTime->u8Minute; 532 uHour = pTime->u8Hour; 514 533 515 534 while (pTime->u32Nanosecond >= 1000000000) … … 668 687 RTDECL(char *) RTTimeToString(PCRTTIME pTime, char *psz, size_t cb) 669 688 { 689 size_t cch; 690 670 691 /* (Default to UTC if not specified) */ 671 692 if ( (pTime->fFlags & RTTIME_FLAGS_TYPE_MASK) == RTTIME_FLAGS_TYPE_LOCAL 672 693 && pTime->offUTC) 673 694 { 674 Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);675 695 int32_t offUTCHour = pTime->offUTC / 60; 676 696 int32_t offUTCMinute = pTime->offUTC % 60; 677 char chSign; 697 char chSign; 698 Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840); 678 699 if (pTime->offUTC >= 0) 679 700 chSign = '+'; … … 684 705 offUTCHour = -offUTCHour; 685 706 } 686 size_tcch = RTStrPrintf(psz, cb,687 688 689 690 707 cch = RTStrPrintf(psz, cb, 708 "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02%02", 709 pTime->i32Year, pTime->u8Month, pTime->u8MonthDay, 710 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond, 711 chSign, offUTCHour, offUTCMinute); 691 712 if ( cch <= 15 692 713 || psz[cch - 5] != chSign) … … 695 716 else 696 717 { 697 size_tcch = RTStrPrintf(psz, cb, "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32Z",698 699 718 cch = RTStrPrintf(psz, cb, "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32Z", 719 pTime->i32Year, pTime->u8Month, pTime->u8MonthDay, 720 pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond); 700 721 if ( cch <= 15 701 722 || psz[cch - 1] != 'Z') -
trunk/src/VBox/Runtime/common/time/timesup.cpp
r29267 r30961 82 82 static const PFNTIMENANOTSINTERNAL g_apfnWorkers[] = 83 83 { 84 # define RTTIMENANO_WORKER_DETECT 084 # define RTTIMENANO_WORKER_DETECT 0 85 85 rtTimeNanoTSInternalRediscover, 86 # define RTTIMENANO_WORKER_SYNC_CPUID 186 # define RTTIMENANO_WORKER_SYNC_CPUID 1 87 87 RTTimeNanoTSLegacySync, 88 # define RTTIMENANO_WORKER_ASYNC_CPUID 288 # define RTTIMENANO_WORKER_ASYNC_CPUID 2 89 89 RTTimeNanoTSLegacyAsync, 90 # define RTTIMENANO_WORKER_SYNC_LFENCE 390 # define RTTIMENANO_WORKER_SYNC_LFENCE 3 91 91 RTTimeNanoTSLFenceSync, 92 # define RTTIMENANO_WORKER_ASYNC_LFENCE 492 # define RTTIMENANO_WORKER_ASYNC_LFENCE 4 93 93 RTTimeNanoTSLFenceAsync, 94 # define RTTIMENANO_WORKER_FALLBACK 594 # define RTTIMENANO_WORKER_FALLBACK 5 95 95 rtTimeNanoTSInternalFallback, 96 96 }; … … 128 128 return rtTimeNanoTSInternalRediscover(pData); 129 129 NOREF(pData); 130 # if defined(IN_RING3) /** @todo Add ring-0 RTTimeSystemNanoTS to all hosts. */130 # ifndef IN_RC 131 131 return RTTimeSystemNanoTS(); 132 # else132 # else 133 133 return 0; 134 # endif134 # endif 135 135 } 136 136
Note:
See TracChangeset
for help on using the changeset viewer.