Files
ppsspp/Common/TimeUtil.h
T
libretroadmin 5f0f72bfda Remove sleeps and timed polling from networking
Socket waits now block in select() on the socket plus a wake or cancel
socket (Common/Net/Cancel), so a stop or cancel ends them at once.

- HTTP: cancel flags become net::CancelToken; Connect waits once on all
  addresses, receives wait instead of spinning, no DNS retry sleep.
- Adhoc: the friend finder and adhoc server block on their sockets with
  a wake socket and a deadline; matching runs on a CoreTiming tick
  instead of two threads (savestate section bumped).
- sceNetInet select/poll check without blocking and park the HLE thread,
  re-checked from a CoreTiming event until ready or the emulated
  timeout.
- Vendor the aemu_postoffice client (was a submodule) with no sleeps:
  waits on the socket, close via shutdown and an eventcount, cancelable
  connects, and lock-free session slot claims.
- PortManager waits without a timeout; PSP_InitWait replaces the
  headless boot poll.
- TimeUtil: sleep_us/sleep_ms only outside the core; sleep_precise,
  sleep_random, yield and the Windows timer period are gone.
- Unit test for the socket waits.
2026-10-08 17:58:46 +02:00

63 lines
1.5 KiB
C++

#pragma once
#include <cstdint>
void TimeInit();
void TimeShutdown(); // Not really necessary to call, just for completeness.
// Seconds.
double time_now_d();
// Raw time in nanoseconds.
// The only intended use is to match the timings from VK_GOOGLE_display_timing.
uint64_t time_now_raw();
// This is only interesting for Linux, in relation to VK_GOOGLE_display_timing.
double from_time_raw(uint64_t raw_time);
double from_time_raw_relative(uint64_t raw_time);
// Seconds, Unix UTC time
double time_now_unix_utc();
double time_to_unix_utc(double timeNowSeconds);
#ifndef __LIBRETRO__
// Sleeps, for the standalone frontends, headless tools and tests. The core never sleeps and
// doesn't have this, so a sleep can't creep back into it.
void sleep_ms(int ms, const char *reason);
void sleep_us(int us, const char *reason);
#endif
void GetCurrentTimeFormatted(char formattedTime[13]);
// Most accurate timer possible - no extra double conversions. Only for spans.
class Instant {
public:
Instant();
static Instant Now() {
return Instant();
}
double ElapsedSeconds() const;
double ElapsedMs() const { return ElapsedSeconds() * 1000.0; }
int64_t ElapsedNanos() const;
private:
uint64_t nativeStart_;
#ifndef _WIN32
int64_t nsecs_;
#endif
};
class TimeCollector {
public:
TimeCollector(double *target, bool enable) : target_(enable ? target : nullptr) {
if (enable)
startTime_ = time_now_d();
}
~TimeCollector() {
if (target_) {
*target_ += time_now_d() - startTime_;
}
}
private:
double startTime_;
double *target_;
};