mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:22:43 +00:00 
			
		
		
		
	Kernel: Make Thread use AK::Time internally
This commit is very invasive, because Thread likes to take a pointer and write to it. This means that translating between timespec/timeval/Time would have been more difficult than just changing everything that hands a raw pointer to Thread, in bulk.
This commit is contained in:
		
							parent
							
								
									65b36e42b8
								
							
						
					
					
						commit
						2b6546c40a
					
				
					 14 changed files with 66 additions and 82 deletions
				
			
		|  | @ -68,7 +68,7 @@ void AsyncDeviceRequest::request_finished() | ||||||
|     m_queue.wake_all(); |     m_queue.wake_all(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| auto AsyncDeviceRequest::wait(timeval* timeout) -> RequestWaitResult | auto AsyncDeviceRequest::wait(Time* timeout) -> RequestWaitResult | ||||||
| { | { | ||||||
|     VERIFY(!m_parent_request); |     VERIFY(!m_parent_request); | ||||||
|     auto request_result = get_request_result(); |     auto request_result = get_request_result(); | ||||||
|  |  | ||||||
|  | @ -76,7 +76,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     void add_sub_request(NonnullRefPtr<AsyncDeviceRequest>); |     void add_sub_request(NonnullRefPtr<AsyncDeviceRequest>); | ||||||
| 
 | 
 | ||||||
|     [[nodiscard]] RequestWaitResult wait(timeval* = nullptr); |     [[nodiscard]] RequestWaitResult wait(Time* = nullptr); | ||||||
| 
 | 
 | ||||||
|     void do_start(Badge<Device>) |     void do_start(Badge<Device>) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -398,10 +398,8 @@ void UHCIController::do_debug_transfer() | ||||||
| void UHCIController::spawn_port_proc() | void UHCIController::spawn_port_proc() | ||||||
| { | { | ||||||
|     RefPtr<Thread> usb_hotplug_thread; |     RefPtr<Thread> usb_hotplug_thread; | ||||||
|     timespec sleep_time {}; |  | ||||||
| 
 | 
 | ||||||
|     sleep_time.tv_sec = 1; |     Process::create_kernel_process(usb_hotplug_thread, "UHCIHotplug", [&] { | ||||||
|     Process::create_kernel_process(usb_hotplug_thread, "UHCIHotplug", [&, sleep_time] { |  | ||||||
|         for (;;) { |         for (;;) { | ||||||
|             for (int port = 0; port < UHCI_ROOT_PORT_COUNT; port++) { |             for (int port = 0; port < UHCI_ROOT_PORT_COUNT; port++) { | ||||||
|                 u16 port_data = 0; |                 u16 port_data = 0; | ||||||
|  | @ -448,7 +446,7 @@ void UHCIController::spawn_port_proc() | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             (void)Thread::current()->sleep(sleep_time); |             (void)Thread::current()->sleep(Time::from_seconds(1)); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -36,9 +36,8 @@ KResultOr<unsigned> Process::sys$alarm(unsigned seconds) | ||||||
|     if (auto alarm_timer = move(m_alarm_timer)) { |     if (auto alarm_timer = move(m_alarm_timer)) { | ||||||
|         if (TimerQueue::the().cancel_timer(*alarm_timer)) { |         if (TimerQueue::the().cancel_timer(*alarm_timer)) { | ||||||
|             // The timer hasn't fired. Round up the remaining time (if any)
 |             // The timer hasn't fired. Round up the remaining time (if any)
 | ||||||
|             timespec remaining; |             Time remaining = alarm_timer->remaining() + Time::from_nanoseconds(999'999'999); | ||||||
|             timespec_add(alarm_timer->remaining(), { 0, 1000000000 - 1 }, remaining); |             previous_alarm_remaining = remaining.to_truncated_seconds(); | ||||||
|             previous_alarm_remaining = remaining.tv_sec; |  | ||||||
|         } |         } | ||||||
|         // We had an existing alarm, must return a non-zero value here!
 |         // We had an existing alarm, must return a non-zero value here!
 | ||||||
|         if (previous_alarm_remaining == 0) |         if (previous_alarm_remaining == 0) | ||||||
|  | @ -46,8 +45,9 @@ KResultOr<unsigned> Process::sys$alarm(unsigned seconds) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (seconds > 0) { |     if (seconds > 0) { | ||||||
|         auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE).value(); |         // FIXME: Should use AK::Time internally
 | ||||||
|         timespec_add(deadline, { seconds, 0 }, deadline); |         auto deadline = Time::from_timespec(TimeManagement::the().current_time(CLOCK_REALTIME_COARSE).value()); | ||||||
|  |         deadline = deadline + Time::from_seconds(seconds); | ||||||
|         m_alarm_timer = TimerQueue::the().add_timer_without_id(CLOCK_REALTIME_COARSE, deadline, [this]() { |         m_alarm_timer = TimerQueue::the().add_timer_without_id(CLOCK_REALTIME_COARSE, deadline, [this]() { | ||||||
|             [[maybe_unused]] auto rc = send_signal(SIGALRM, nullptr); |             [[maybe_unused]] auto rc = send_signal(SIGALRM, nullptr); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ namespace Kernel { | ||||||
| KResultOr<int> Process::sys$beep() | KResultOr<int> Process::sys$beep() | ||||||
| { | { | ||||||
|     PCSpeaker::tone_on(440); |     PCSpeaker::tone_on(440); | ||||||
|     auto result = Thread::current()->sleep({ 0, 200 }); |     auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000)); | ||||||
|     PCSpeaker::tone_off(); |     PCSpeaker::tone_off(); | ||||||
|     if (result.was_interrupted()) |     if (result.was_interrupted()) | ||||||
|         return EINTR; |         return EINTR; | ||||||
|  |  | ||||||
|  | @ -94,13 +94,12 @@ KResultOr<int> Process::sys$clock_nanosleep(Userspace<const Syscall::SC_clock_na | ||||||
| 
 | 
 | ||||||
|     bool was_interrupted; |     bool was_interrupted; | ||||||
|     if (is_absolute) { |     if (is_absolute) { | ||||||
|         // FIXME: Should use AK::Time internally
 |         was_interrupted = Thread::current()->sleep_until(params.clock_id, requested_sleep.value()).was_interrupted(); | ||||||
|         was_interrupted = Thread::current()->sleep_until(params.clock_id, requested_sleep->to_timespec()).was_interrupted(); |  | ||||||
|     } else { |     } else { | ||||||
|         timespec remaining_sleep; |         Time remaining_sleep; | ||||||
|         // FIXME: Should use AK::Time internally
 |         was_interrupted = Thread::current()->sleep(params.clock_id, requested_sleep.value(), &remaining_sleep).was_interrupted(); | ||||||
|         was_interrupted = Thread::current()->sleep(params.clock_id, requested_sleep->to_timespec(), &remaining_sleep).was_interrupted(); |         timespec remaining_sleep_ts = remaining_sleep.to_timespec(); | ||||||
|         if (was_interrupted && params.remaining_sleep && !copy_to_user(params.remaining_sleep, &remaining_sleep)) |         if (was_interrupted && params.remaining_sleep && !copy_to_user(params.remaining_sleep, &remaining_sleep_ts)) | ||||||
|             return EFAULT; |             return EFAULT; | ||||||
|     } |     } | ||||||
|     if (was_interrupted) |     if (was_interrupted) | ||||||
|  |  | ||||||
|  | @ -123,9 +123,7 @@ KResultOr<int> Process::sys$futex(Userspace<const Syscall::SC_futex_params*> use | ||||||
|                 return EFAULT; |                 return EFAULT; | ||||||
|             clockid_t clock_id = (params.futex_op & FUTEX_CLOCK_REALTIME) ? CLOCK_REALTIME_COARSE : CLOCK_MONOTONIC_COARSE; |             clockid_t clock_id = (params.futex_op & FUTEX_CLOCK_REALTIME) ? CLOCK_REALTIME_COARSE : CLOCK_MONOTONIC_COARSE; | ||||||
|             bool is_absolute = cmd != FUTEX_WAIT; |             bool is_absolute = cmd != FUTEX_WAIT; | ||||||
|             // FIXME: Should use AK::Time internally
 |             timeout = Thread::BlockTimeout(is_absolute, &timeout_time.value(), nullptr, clock_id); | ||||||
|             timespec timeout_copy = timeout_time->to_timespec(); |  | ||||||
|             timeout = Thread::BlockTimeout(is_absolute, &timeout_copy, nullptr, clock_id); |  | ||||||
|         } |         } | ||||||
|         if (cmd == FUTEX_WAIT_BITSET && params.val3 == FUTEX_BITSET_MATCH_ANY) |         if (cmd == FUTEX_WAIT_BITSET && params.val3 == FUTEX_BITSET_MATCH_ANY) | ||||||
|             cmd = FUTEX_WAIT; |             cmd = FUTEX_WAIT; | ||||||
|  |  | ||||||
|  | @ -48,9 +48,7 @@ KResultOr<int> Process::sys$select(Userspace<const Syscall::SC_select_params*> u | ||||||
|         Optional<Time> timeout_time = copy_time_from_user(params.timeout); |         Optional<Time> timeout_time = copy_time_from_user(params.timeout); | ||||||
|         if (!timeout_time.has_value()) |         if (!timeout_time.has_value()) | ||||||
|             return EFAULT; |             return EFAULT; | ||||||
|         auto timeout_copy = timeout_time->to_timespec(); |         timeout = Thread::BlockTimeout(false, &timeout_time.value()); | ||||||
|         // FIXME: Should use AK::Time internally
 |  | ||||||
|         timeout = Thread::BlockTimeout(false, &timeout_copy); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto current_thread = Thread::current(); |     auto current_thread = Thread::current(); | ||||||
|  | @ -156,9 +154,7 @@ KResultOr<int> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> user_ | ||||||
|         auto timeout_time = copy_time_from_user(params.timeout); |         auto timeout_time = copy_time_from_user(params.timeout); | ||||||
|         if (!timeout_time.has_value()) |         if (!timeout_time.has_value()) | ||||||
|             return EFAULT; |             return EFAULT; | ||||||
|         timespec timeout_copy = timeout_time->to_timespec(); |         timeout = Thread::BlockTimeout(false, &timeout_time.value()); | ||||||
|         // FIXME: Should use AK::Time internally
 |  | ||||||
|         timeout = Thread::BlockTimeout(false, &timeout_copy); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     sigset_t sigmask = {}; |     sigset_t sigmask = {}; | ||||||
|  |  | ||||||
|  | @ -38,7 +38,7 @@ void SyncTask::spawn() | ||||||
|         dbgln("SyncTask is running"); |         dbgln("SyncTask is running"); | ||||||
|         for (;;) { |         for (;;) { | ||||||
|             VFS::the().sync(); |             VFS::the().sync(); | ||||||
|             (void)Thread::current()->sleep({ 1, 0 }); |             (void)Thread::current()->sleep(Time::from_seconds(1)); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -333,13 +333,13 @@ void Thread::relock_process(LockMode previous_locked, u32 lock_count_to_restore) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| auto Thread::sleep(clockid_t clock_id, const timespec& duration, timespec* remaining_time) -> BlockResult | auto Thread::sleep(clockid_t clock_id, const Time& duration, Time* remaining_time) -> BlockResult | ||||||
| { | { | ||||||
|     VERIFY(state() == Thread::Running); |     VERIFY(state() == Thread::Running); | ||||||
|     return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time); |     return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| auto Thread::sleep_until(clockid_t clock_id, const timespec& deadline) -> BlockResult | auto Thread::sleep_until(clockid_t clock_id, const Time& deadline) -> BlockResult | ||||||
| { | { | ||||||
|     VERIFY(state() == Thread::Running); |     VERIFY(state() == Thread::Running); | ||||||
|     return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(true, &deadline, nullptr, clock_id)); |     return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(true, &deadline, nullptr, clock_id)); | ||||||
|  |  | ||||||
|  | @ -208,44 +208,17 @@ public: | ||||||
|             : m_infinite(true) |             : m_infinite(true) | ||||||
|         { |         { | ||||||
|         } |         } | ||||||
|         explicit BlockTimeout(bool is_absolute, const timeval* time, const timespec* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE) |         explicit BlockTimeout(bool is_absolute, const Time* time, const Time* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE); | ||||||
|             : m_clock_id(clock_id) |  | ||||||
|             , m_infinite(!time) |  | ||||||
|         { |  | ||||||
|             if (!m_infinite) { |  | ||||||
|                 if (time->tv_sec > 0 || time->tv_usec > 0) { |  | ||||||
|                     timeval_to_timespec(*time, m_time); |  | ||||||
|                     m_should_block = true; |  | ||||||
|                 } |  | ||||||
|                 m_start_time = start_time ? *start_time : TimeManagement::the().current_time(clock_id).value(); |  | ||||||
|                 if (!is_absolute) |  | ||||||
|                     timespec_add(m_time, m_start_time, m_time); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         explicit BlockTimeout(bool is_absolute, const timespec* time, const timespec* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE) |  | ||||||
|             : m_clock_id(clock_id) |  | ||||||
|             , m_infinite(!time) |  | ||||||
|         { |  | ||||||
|             if (!m_infinite) { |  | ||||||
|                 if (time->tv_sec > 0 || time->tv_nsec > 0) { |  | ||||||
|                     m_time = *time; |  | ||||||
|                     m_should_block = true; |  | ||||||
|                 } |  | ||||||
|                 m_start_time = start_time ? *start_time : TimeManagement::the().current_time(clock_id).value(); |  | ||||||
|                 if (!is_absolute) |  | ||||||
|                     timespec_add(m_time, m_start_time, m_time); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         const timespec& absolute_time() const { return m_time; } |         const Time& absolute_time() const { return m_time; } | ||||||
|         const timespec* start_time() const { return !m_infinite ? &m_start_time : nullptr; } |         const Time* start_time() const { return !m_infinite ? &m_start_time : nullptr; } | ||||||
|         clockid_t clock_id() const { return m_clock_id; } |         clockid_t clock_id() const { return m_clock_id; } | ||||||
|         bool is_infinite() const { return m_infinite; } |         bool is_infinite() const { return m_infinite; } | ||||||
|         bool should_block() const { return m_infinite || m_should_block; }; |         bool should_block() const { return m_infinite || m_should_block; }; | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         timespec m_time { 0, 0 }; |         Time m_time {}; | ||||||
|         timespec m_start_time { 0, 0 }; |         Time m_start_time {}; | ||||||
|         clockid_t m_clock_id { CLOCK_MONOTONIC_COARSE }; |         clockid_t m_clock_id { CLOCK_MONOTONIC_COARSE }; | ||||||
|         bool m_infinite { false }; |         bool m_infinite { false }; | ||||||
|         bool m_should_block { false }; |         bool m_should_block { false }; | ||||||
|  | @ -640,7 +613,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     class SleepBlocker final : public Blocker { |     class SleepBlocker final : public Blocker { | ||||||
|     public: |     public: | ||||||
|         explicit SleepBlocker(const BlockTimeout&, timespec* = nullptr); |         explicit SleepBlocker(const BlockTimeout&, Time* = nullptr); | ||||||
|         virtual const char* state_string() const override { return "Sleeping"; } |         virtual const char* state_string() const override { return "Sleeping"; } | ||||||
|         virtual Type blocker_type() const override { return Type::Sleep; } |         virtual Type blocker_type() const override { return Type::Sleep; } | ||||||
|         virtual const BlockTimeout& override_timeout(const BlockTimeout&) override; |         virtual const BlockTimeout& override_timeout(const BlockTimeout&) override; | ||||||
|  | @ -652,7 +625,7 @@ public: | ||||||
|         void calculate_remaining(); |         void calculate_remaining(); | ||||||
| 
 | 
 | ||||||
|         BlockTimeout m_deadline; |         BlockTimeout m_deadline; | ||||||
|         timespec* m_remaining; |         Time* m_remaining; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     class SelectBlocker final : public FileBlocker { |     class SelectBlocker final : public FileBlocker { | ||||||
|  | @ -955,13 +928,13 @@ public: | ||||||
|         return block<Thread::QueueBlocker>(timeout, wait_queue, forward<Args>(args)...); |         return block<Thread::QueueBlocker>(timeout, wait_queue, forward<Args>(args)...); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     BlockResult sleep(clockid_t, const timespec&, timespec* = nullptr); |     BlockResult sleep(clockid_t, const Time&, Time* = nullptr); | ||||||
|     BlockResult sleep(const timespec& duration, timespec* remaining_time = nullptr) |     BlockResult sleep(const Time& duration, Time* remaining_time = nullptr) | ||||||
|     { |     { | ||||||
|         return sleep(CLOCK_MONOTONIC_COARSE, duration, remaining_time); |         return sleep(CLOCK_MONOTONIC_COARSE, duration, remaining_time); | ||||||
|     } |     } | ||||||
|     BlockResult sleep_until(clockid_t, const timespec&); |     BlockResult sleep_until(clockid_t, const Time&); | ||||||
|     BlockResult sleep_until(const timespec& duration) |     BlockResult sleep_until(const Time& duration) | ||||||
|     { |     { | ||||||
|         return sleep_until(CLOCK_MONOTONIC_COARSE, duration); |         return sleep_until(CLOCK_MONOTONIC_COARSE, duration); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -33,6 +33,22 @@ | ||||||
| 
 | 
 | ||||||
| namespace Kernel { | namespace Kernel { | ||||||
| 
 | 
 | ||||||
|  | Thread::BlockTimeout::BlockTimeout(bool is_absolute, const Time* time, const Time* start_time, clockid_t clock_id) | ||||||
|  |     : m_clock_id(clock_id) | ||||||
|  |     , m_infinite(!time) | ||||||
|  | { | ||||||
|  |     if (!m_infinite) { | ||||||
|  |         if (*time > Time::zero()) { | ||||||
|  |             m_time = *time; | ||||||
|  |             m_should_block = true; | ||||||
|  |         } | ||||||
|  |         // FIXME: Should use AK::Time internally
 | ||||||
|  |         m_start_time = start_time ? *start_time : Time::from_timespec(TimeManagement::the().current_time(clock_id).value()); | ||||||
|  |         if (!is_absolute) | ||||||
|  |             m_time = m_time + m_start_time; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool Thread::Blocker::set_block_condition(Thread::BlockCondition& block_condition, void* data) | bool Thread::Blocker::set_block_condition(Thread::BlockCondition& block_condition, void* data) | ||||||
| { | { | ||||||
|     VERIFY(!m_block_condition); |     VERIFY(!m_block_condition); | ||||||
|  | @ -270,7 +286,9 @@ auto Thread::WriteBlocker::override_timeout(const BlockTimeout& timeout) -> cons | ||||||
|     if (description.is_socket()) { |     if (description.is_socket()) { | ||||||
|         auto& socket = *description.socket(); |         auto& socket = *description.socket(); | ||||||
|         if (socket.has_send_timeout()) { |         if (socket.has_send_timeout()) { | ||||||
|             m_timeout = BlockTimeout(false, &socket.send_timeout(), timeout.start_time(), timeout.clock_id()); |             // FIXME: Should use AK::Time internally
 | ||||||
|  |             Time send_timeout = Time::from_timeval(socket.send_timeout()); | ||||||
|  |             m_timeout = BlockTimeout(false, &send_timeout, timeout.start_time(), timeout.clock_id()); | ||||||
|             if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time())) |             if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time())) | ||||||
|                 return m_timeout; |                 return m_timeout; | ||||||
|         } |         } | ||||||
|  | @ -289,7 +307,9 @@ auto Thread::ReadBlocker::override_timeout(const BlockTimeout& timeout) -> const | ||||||
|     if (description.is_socket()) { |     if (description.is_socket()) { | ||||||
|         auto& socket = *description.socket(); |         auto& socket = *description.socket(); | ||||||
|         if (socket.has_receive_timeout()) { |         if (socket.has_receive_timeout()) { | ||||||
|             m_timeout = BlockTimeout(false, &socket.receive_timeout(), timeout.start_time(), timeout.clock_id()); |             // FIXME: Should use AK::Time internally
 | ||||||
|  |             Time receive_timeout = Time::from_timeval(socket.receive_timeout()); | ||||||
|  |             m_timeout = BlockTimeout(false, &receive_timeout, timeout.start_time(), timeout.clock_id()); | ||||||
|             if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time())) |             if (timeout.is_infinite() || (!m_timeout.is_infinite() && m_timeout.absolute_time() < timeout.absolute_time())) | ||||||
|                 return m_timeout; |                 return m_timeout; | ||||||
|         } |         } | ||||||
|  | @ -297,7 +317,7 @@ auto Thread::ReadBlocker::override_timeout(const BlockTimeout& timeout) -> const | ||||||
|     return timeout; |     return timeout; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Thread::SleepBlocker::SleepBlocker(const BlockTimeout& deadline, timespec* remaining) | Thread::SleepBlocker::SleepBlocker(const BlockTimeout& deadline, Time* remaining) | ||||||
|     : m_deadline(deadline) |     : m_deadline(deadline) | ||||||
|     , m_remaining(remaining) |     , m_remaining(remaining) | ||||||
| { | { | ||||||
|  | @ -329,9 +349,10 @@ void Thread::SleepBlocker::calculate_remaining() | ||||||
| { | { | ||||||
|     if (!m_remaining) |     if (!m_remaining) | ||||||
|         return; |         return; | ||||||
|     auto time_now = TimeManagement::the().current_time(m_deadline.clock_id()).value(); |     // FIXME: Should use AK::Time internally
 | ||||||
|  |     auto time_now = Time::from_timespec(TimeManagement::the().current_time(m_deadline.clock_id()).value()); | ||||||
|     if (time_now < m_deadline.absolute_time()) |     if (time_now < m_deadline.absolute_time()) | ||||||
|         timespec_sub(m_deadline.absolute_time(), time_now, *m_remaining); |         *m_remaining = m_deadline.absolute_time() - time_now; | ||||||
|     else |     else | ||||||
|         *m_remaining = {}; |         *m_remaining = {}; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -38,10 +38,9 @@ namespace Kernel { | ||||||
| static AK::Singleton<TimerQueue> s_the; | static AK::Singleton<TimerQueue> s_the; | ||||||
| static SpinLock<u8> g_timerqueue_lock; | static SpinLock<u8> g_timerqueue_lock; | ||||||
| 
 | 
 | ||||||
| timespec Timer::remaining() const | Time Timer::remaining() const | ||||||
| { | { | ||||||
|     // FIXME: Should use AK::Time internally
 |     return m_remaining; | ||||||
|     return m_remaining.to_timespec(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Time Timer::now(bool is_firing) const | Time Timer::now(bool is_firing) const | ||||||
|  | @ -79,9 +78,10 @@ UNMAP_AFTER_INIT TimerQueue::TimerQueue() | ||||||
|     m_ticks_per_second = TimeManagement::the().ticks_per_second(); |     m_ticks_per_second = TimeManagement::the().ticks_per_second(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| RefPtr<Timer> TimerQueue::add_timer_without_id(clockid_t clock_id, const timespec& deadline, Function<void()>&& callback) | RefPtr<Timer> TimerQueue::add_timer_without_id(clockid_t clock_id, const Time& deadline, Function<void()>&& callback) | ||||||
| { | { | ||||||
|     if (deadline <= TimeManagement::the().current_time(clock_id).value()) |     // FIXME: Should use AK::Time internally
 | ||||||
|  |     if (deadline <= Time::from_timespec(TimeManagement::the().current_time(clock_id).value())) | ||||||
|         return {}; |         return {}; | ||||||
| 
 | 
 | ||||||
|     // Because timer handlers can execute on any processor and there is
 |     // Because timer handlers can execute on any processor and there is
 | ||||||
|  | @ -89,7 +89,7 @@ RefPtr<Timer> TimerQueue::add_timer_without_id(clockid_t clock_id, const timespe | ||||||
|     // *must* be a RefPtr<Timer>. Otherwise calling cancel_timer() could
 |     // *must* be a RefPtr<Timer>. Otherwise calling cancel_timer() could
 | ||||||
|     // inadvertently cancel another timer that has been created between
 |     // inadvertently cancel another timer that has been created between
 | ||||||
|     // returning from the timer handler and a call to cancel_timer().
 |     // returning from the timer handler and a call to cancel_timer().
 | ||||||
|     auto timer = adopt(*new Timer(clock_id, Time::from_timespec(deadline), move(callback))); |     auto timer = adopt(*new Timer(clock_id, deadline, move(callback))); | ||||||
| 
 | 
 | ||||||
|     ScopedSpinLock lock(g_timerqueue_lock); |     ScopedSpinLock lock(g_timerqueue_lock); | ||||||
|     timer->m_id = 0; // Don't generate a timer id
 |     timer->m_id = 0; // Don't generate a timer id
 | ||||||
|  |  | ||||||
|  | @ -55,7 +55,7 @@ public: | ||||||
|         VERIFY(!is_queued()); |         VERIFY(!is_queued()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     timespec remaining() const; |     Time remaining() const; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     TimerId m_id; |     TimerId m_id; | ||||||
|  | @ -92,8 +92,7 @@ public: | ||||||
|     static TimerQueue& the(); |     static TimerQueue& the(); | ||||||
| 
 | 
 | ||||||
|     TimerId add_timer(NonnullRefPtr<Timer>&&); |     TimerId add_timer(NonnullRefPtr<Timer>&&); | ||||||
|     // FIXME: Should use AK::Time internally
 |     RefPtr<Timer> add_timer_without_id(clockid_t, const Time&, Function<void()>&&); | ||||||
|     RefPtr<Timer> add_timer_without_id(clockid_t, const timespec&, Function<void()>&&); |  | ||||||
|     TimerId add_timer(clockid_t, timeval& timeout, Function<void()>&& callback); |     TimerId add_timer(clockid_t, timeval& timeout, Function<void()>&& callback); | ||||||
|     bool cancel_timer(TimerId id); |     bool cancel_timer(TimerId id); | ||||||
|     bool cancel_timer(Timer&); |     bool cancel_timer(Timer&); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ben Wiederhake
						Ben Wiederhake