timings.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #if defined(EA_PRAGMA_ONCE_SUPPORTED)
  5. #pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
  6. #endif
  7. #ifndef EATHREAD_INTERNAL_TIMINGS_H
  8. #define EATHREAD_INTERNAL_TIMINGS_H
  9. namespace EA
  10. {
  11. namespace Thread
  12. {
  13. #if defined(EA_PLATFORM_SONY)
  14. // RelativeTimeoutFromAbsoluteTimeout returns a relative timeout in microseconds.
  15. inline uint32_t RelativeTimeoutFromAbsoluteTimeout(EA::Thread::ThreadTime timeoutAbsolute)
  16. {
  17. using namespace EA::Thread;
  18. EAT_ASSERT((timeoutAbsolute == kTimeoutImmediate) || (timeoutAbsolute > EATHREAD_MIN_ABSOLUTE_TIME)); // Assert that the user didn't make the mistake of treating time as relative instead of absolute.
  19. uint32_t timeoutRelative = 0;
  20. if (timeoutAbsolute == kTimeoutNone)
  21. {
  22. timeoutRelative = 0xffffffff;
  23. }
  24. else if (timeoutAbsolute == kTimeoutImmediate)
  25. {
  26. timeoutRelative = 0;
  27. }
  28. else
  29. {
  30. ThreadTime timeCurrent(GetThreadTime());
  31. timeoutRelative = (timeoutAbsolute > timeCurrent) ? EA_THREADTIME_AS_UINT_MICROSECONDS(timeoutAbsolute - timeCurrent) : 0;
  32. }
  33. EAT_ASSERT((timeoutRelative == 0xffffffff) || (timeoutRelative < 100000000)); // Assert that the timeout is a sane value and didn't wrap around.
  34. return timeoutRelative;
  35. }
  36. #endif
  37. }
  38. }
  39. #endif