mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:37:46 +00:00
AK: Rename Time to Duration
That's what this class really is; in fact that's what the first line of the comment says it is. This commit does not rename the main files, since those will contain other time-related classes in a little bit.
This commit is contained in:
parent
82ddc813d5
commit
213025f210
140 changed files with 634 additions and 628 deletions
|
@ -20,7 +20,7 @@ ElapsedTimer ElapsedTimer::start_new()
|
|||
void ElapsedTimer::start()
|
||||
{
|
||||
m_valid = true;
|
||||
m_origin_time = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
|
||||
m_origin_time = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
|
||||
}
|
||||
|
||||
void ElapsedTimer::reset()
|
||||
|
@ -34,10 +34,10 @@ i64 ElapsedTimer::elapsed_milliseconds() const
|
|||
return elapsed_time().to_milliseconds();
|
||||
}
|
||||
|
||||
Time ElapsedTimer::elapsed_time() const
|
||||
Duration ElapsedTimer::elapsed_time() const
|
||||
{
|
||||
VERIFY(is_valid());
|
||||
auto now = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
|
||||
auto now = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
|
||||
return now - m_origin_time;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
void reset();
|
||||
|
||||
i64 elapsed_milliseconds() const;
|
||||
Time elapsed_time() const;
|
||||
Duration elapsed_time() const;
|
||||
|
||||
// FIXME: Move callers to elapsed_milliseconds(), remove this.
|
||||
i64 elapsed() const // milliseconds
|
||||
|
@ -32,10 +32,10 @@ public:
|
|||
return elapsed_milliseconds();
|
||||
}
|
||||
|
||||
Time const& origin_time() const { return m_origin_time; }
|
||||
Duration const& origin_time() const { return m_origin_time; }
|
||||
|
||||
private:
|
||||
Time m_origin_time {};
|
||||
Duration m_origin_time {};
|
||||
bool m_precise { false };
|
||||
bool m_valid { false };
|
||||
};
|
||||
|
|
|
@ -29,14 +29,14 @@ thread_local ThreadData* s_thread_data;
|
|||
|
||||
struct EventLoopTimer {
|
||||
int timer_id { 0 };
|
||||
Time interval;
|
||||
Time fire_time;
|
||||
Duration interval;
|
||||
Duration fire_time;
|
||||
bool should_reload { false };
|
||||
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
|
||||
WeakPtr<Object> owner;
|
||||
|
||||
void reload(Time const& now) { fire_time = now + interval; }
|
||||
bool has_expired(Time const& now) const { return now > fire_time; }
|
||||
void reload(Duration const& now) { fire_time = now + interval; }
|
||||
bool has_expired(Duration const& now) const { return now > fire_time; }
|
||||
};
|
||||
|
||||
struct ThreadData {
|
||||
|
@ -171,16 +171,16 @@ retry:
|
|||
|
||||
// Figure out how long to wait at maximum.
|
||||
// This mainly depends on the PumpMode and whether we have pending events, but also the next expiring timer.
|
||||
Time now;
|
||||
Duration now;
|
||||
struct timeval timeout = { 0, 0 };
|
||||
bool should_wait_forever = false;
|
||||
if (mode == EventLoopImplementation::PumpMode::WaitForEvents && !has_pending_events) {
|
||||
auto next_timer_expiration = get_next_timer_expiration();
|
||||
if (next_timer_expiration.has_value()) {
|
||||
now = Time::now_monotonic_coarse();
|
||||
now = Duration::now_monotonic_coarse();
|
||||
auto computed_timeout = next_timer_expiration.value() - now;
|
||||
if (computed_timeout.is_negative())
|
||||
computed_timeout = Time::zero();
|
||||
computed_timeout = Duration::zero();
|
||||
timeout = computed_timeout.to_timeval();
|
||||
} else {
|
||||
should_wait_forever = true;
|
||||
|
@ -231,7 +231,7 @@ try_select_again:
|
|||
}
|
||||
|
||||
if (!thread_data.timers.is_empty()) {
|
||||
now = Time::now_monotonic_coarse();
|
||||
now = Duration::now_monotonic_coarse();
|
||||
}
|
||||
|
||||
// Handle expired timers.
|
||||
|
@ -349,10 +349,10 @@ void EventLoopImplementationUnix::notify_forked_and_in_child()
|
|||
thread_data.pid = getpid();
|
||||
}
|
||||
|
||||
Optional<Time> EventLoopManagerUnix::get_next_timer_expiration()
|
||||
Optional<Duration> EventLoopManagerUnix::get_next_timer_expiration()
|
||||
{
|
||||
auto now = Time::now_monotonic_coarse();
|
||||
Optional<Time> soonest {};
|
||||
auto now = Duration::now_monotonic_coarse();
|
||||
Optional<Duration> soonest {};
|
||||
for (auto& it : ThreadData::the().timers) {
|
||||
auto& fire_time = it.value->fire_time;
|
||||
auto owner = it.value->owner.strong_ref();
|
||||
|
@ -489,8 +489,8 @@ int EventLoopManagerUnix::register_timer(Object& object, int milliseconds, bool
|
|||
auto& thread_data = ThreadData::the();
|
||||
auto timer = make<EventLoopTimer>();
|
||||
timer->owner = object;
|
||||
timer->interval = Time::from_milliseconds(milliseconds);
|
||||
timer->reload(Time::now_monotonic_coarse());
|
||||
timer->interval = Duration::from_milliseconds(milliseconds);
|
||||
timer->reload(Duration::now_monotonic_coarse());
|
||||
timer->should_reload = should_reload;
|
||||
timer->fire_when_not_visible = fire_when_not_visible;
|
||||
int timer_id = thread_data.id_allocator.allocate();
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
virtual void unregister_signal(int handler_id) override;
|
||||
|
||||
void wait_for_events(EventLoopImplementation::PumpMode);
|
||||
static Optional<Time> get_next_timer_expiration();
|
||||
static Optional<Duration> get_next_timer_expiration();
|
||||
|
||||
private:
|
||||
void dispatch_signal(int signal_number);
|
||||
|
|
|
@ -18,10 +18,13 @@
|
|||
static_assert(false, "This file must only be used for macOS");
|
||||
#endif
|
||||
|
||||
#define FixedPoint FixedPointMacOS // AK::FixedPoint conflicts with FixedPoint from MacTypes.h.
|
||||
// Several AK types conflict with MacOS types.
|
||||
#define FixedPoint FixedPointMacOS
|
||||
#define Duration DurationMacOS
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#undef FixedPoint
|
||||
#undef Duration
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ ErrorOr<void> PosixSocketHelper::set_close_on_exec(bool enabled)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> PosixSocketHelper::set_receive_timeout(Time timeout)
|
||||
ErrorOr<void> PosixSocketHelper::set_receive_timeout(Duration timeout)
|
||||
{
|
||||
auto timeout_spec = timeout.to_timespec();
|
||||
return System::setsockopt(m_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout_spec, sizeof(timeout_spec));
|
||||
|
@ -231,13 +231,13 @@ ErrorOr<size_t> PosixSocketHelper::pending_bytes() const
|
|||
return static_cast<size_t>(value);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Time> timeout)
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout)
|
||||
{
|
||||
auto ip_address = TRY(resolve_host(host, SocketType::Datagram));
|
||||
return connect(SocketAddress { ip_address, port }, timeout);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Time> timeout)
|
||||
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Duration> timeout)
|
||||
{
|
||||
auto socket = TRY(adopt_nonnull_own_or_enomem(new (nothrow) UDPSocket()));
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public:
|
|||
|
||||
ErrorOr<void> set_blocking(bool enabled);
|
||||
ErrorOr<void> set_close_on_exec(bool enabled);
|
||||
ErrorOr<void> set_receive_timeout(Time timeout);
|
||||
ErrorOr<void> set_receive_timeout(Duration timeout);
|
||||
|
||||
void setup_notifier();
|
||||
RefPtr<Core::Notifier> notifier() { return m_notifier; }
|
||||
|
@ -215,8 +215,8 @@ private:
|
|||
|
||||
class UDPSocket final : public Socket {
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Time> timeout = {});
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Time> timeout = {});
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout = {});
|
||||
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Duration> timeout = {});
|
||||
|
||||
UDPSocket(UDPSocket&& other)
|
||||
: Socket(static_cast<Socket&&>(other))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue