OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 University of Washington | 3 * Copyright (c) 2008 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 { | 384 { |
385 NS_LOG_FUNCTION (this); | 385 NS_LOG_FUNCTION (this); |
386 return GetRealtime () - m_realtimeOriginNano; | 386 return GetRealtime () - m_realtimeOriginNano; |
387 } | 387 } |
388 | 388 |
389 void | 389 void |
390 WallClockSynchronizer::NsToTimeval (int64_t ns, struct timeval *tv) | 390 WallClockSynchronizer::NsToTimeval (int64_t ns, struct timeval *tv) |
391 { | 391 { |
392 NS_LOG_FUNCTION (this << ns << tv); | 392 NS_LOG_FUNCTION (this << ns << tv); |
393 NS_ASSERT ((ns % US_PER_NS) == 0); | 393 NS_ASSERT ((ns % US_PER_NS) == 0); |
394 tv->tv_sec = ns / NS_PER_SEC; | 394 tv->tv_sec = static_cast<long> (ns / NS_PER_SEC); |
395 tv->tv_usec = (ns % NS_PER_SEC) / US_PER_NS; | 395 tv->tv_usec = (ns % NS_PER_SEC) / US_PER_NS; |
396 } | 396 } |
397 | 397 |
398 uint64_t | 398 uint64_t |
399 WallClockSynchronizer::TimevalToNs (struct timeval *tv) | 399 WallClockSynchronizer::TimevalToNs (struct timeval *tv) |
400 { | 400 { |
401 NS_LOG_FUNCTION (this << tv); | 401 NS_LOG_FUNCTION (this << tv); |
402 uint64_t nsResult = tv->tv_sec * NS_PER_SEC + tv->tv_usec * US_PER_NS; | 402 uint64_t nsResult = tv->tv_sec * NS_PER_SEC + tv->tv_usec * US_PER_NS; |
403 NS_ASSERT ((nsResult % US_PER_NS) == 0); | 403 NS_ASSERT ((nsResult % US_PER_NS) == 0); |
404 return nsResult; | 404 return nsResult; |
405 } | 405 } |
406 | 406 |
407 void | 407 void |
408 WallClockSynchronizer::TimevalAdd ( | 408 WallClockSynchronizer::TimevalAdd ( |
409 struct timeval *tv1,· | 409 struct timeval *tv1,· |
410 struct timeval *tv2, | 410 struct timeval *tv2, |
411 struct timeval *result) | 411 struct timeval *result) |
412 { | 412 { |
413 NS_LOG_FUNCTION (this << tv1 << tv2 << result); | 413 NS_LOG_FUNCTION (this << tv1 << tv2 << result); |
414 result->tv_sec = tv1->tv_sec + tv2->tv_sec; | 414 result->tv_sec = tv1->tv_sec + tv2->tv_sec; |
415 result->tv_usec = tv1->tv_usec + tv2->tv_usec; | 415 result->tv_usec = tv1->tv_usec + tv2->tv_usec; |
416 if (result->tv_usec > (int64_t)US_PER_SEC) | 416 if (result->tv_usec > (int64_t)US_PER_SEC) |
417 { | 417 { |
418 ++result->tv_sec; | 418 ++result->tv_sec; |
419 result->tv_usec %= US_PER_SEC; | 419 result->tv_usec %= US_PER_SEC; |
420 } | 420 } |
421 } | 421 } |
422 | 422 |
423 } // namespace ns3 | 423 } // namespace ns3 |
OLD | NEW |