mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	Kernel: Add WaitQueue::wait_forever and it use it for all infinite waits.
In preparation for marking BlockingResult [[nodiscard]], there are a few places that perform infinite waits, which we never observe the result of the wait. Instead of suppressing them, add an alternate function which returns void when performing and infinite wait.
This commit is contained in:
		
							parent
							
								
									4ac286903d
								
							
						
					
					
						commit
						ddd79fe2cf
					
				
					 9 changed files with 15 additions and 9 deletions
				
			
		|  | @ -239,7 +239,7 @@ void SB16::handle_irq(const RegisterState&) | ||||||
| 
 | 
 | ||||||
| void SB16::wait_for_irq() | void SB16::wait_for_irq() | ||||||
| { | { | ||||||
|     m_irq_queue.wait_on({}, "SB16"); |     m_irq_queue.wait_forever("SB16"); | ||||||
|     disable_irq(); |     disable_irq(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -74,7 +74,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction_blocking(FIFO::Di | ||||||
| 
 | 
 | ||||||
|         if (m_writers == 0) { |         if (m_writers == 0) { | ||||||
|             locker.unlock(); |             locker.unlock(); | ||||||
|             m_write_open_queue.wait_on({}, "FIFO"); |             m_write_open_queue.wait_forever("FIFO"); | ||||||
|             locker.lock(); |             locker.lock(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | @ -84,7 +84,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction_blocking(FIFO::Di | ||||||
| 
 | 
 | ||||||
|         if (m_readers == 0) { |         if (m_readers == 0) { | ||||||
|             locker.unlock(); |             locker.unlock(); | ||||||
|             m_read_open_queue.wait_on({}, "FIFO"); |             m_read_open_queue.wait_forever("FIFO"); | ||||||
|             locker.lock(); |             locker.lock(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -127,7 +127,7 @@ void Lock::lock(Mode mode) | ||||||
|         } |         } | ||||||
|         m_lock.store(false, AK::memory_order_release); |         m_lock.store(false, AK::memory_order_release); | ||||||
|         dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}) waiting...", this, m_name); |         dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}) waiting...", this, m_name); | ||||||
|         m_queue.wait_on({}, m_name); |         m_queue.wait_forever(m_name); | ||||||
|         dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}) waited", this, m_name); |         dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}) waited", this, m_name); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -444,7 +444,7 @@ void E1000NetworkAdapter::send_raw(ReadonlyBytes payload) | ||||||
|             sti(); |             sti(); | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|         m_wait_queue.wait_on({}, "E1000NetworkAdapter"); |         m_wait_queue.wait_forever("E1000NetworkAdapter"); | ||||||
|     } |     } | ||||||
| #if E1000_DEBUG | #if E1000_DEBUG | ||||||
|     dbgln("E1000: Sent packet, status is now {:#02x}!", (u8)descriptor.status); |     dbgln("E1000: Sent packet, status is now {:#02x}!", (u8)descriptor.status); | ||||||
|  |  | ||||||
|  | @ -392,7 +392,7 @@ void NE2000NetworkAdapter::send_raw(ReadonlyBytes payload) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     while (in8(REG_RW_COMMAND) & BIT_COMMAND_TXP) |     while (in8(REG_RW_COMMAND) & BIT_COMMAND_TXP) | ||||||
|         m_wait_queue.wait_on({}, "NE2000NetworkAdapter"); |         m_wait_queue.wait_forever("NE2000NetworkAdapter"); | ||||||
| 
 | 
 | ||||||
|     disable_irq(); |     disable_irq(); | ||||||
|     size_t packet_size = payload.size(); |     size_t packet_size = payload.size(); | ||||||
|  |  | ||||||
|  | @ -106,7 +106,7 @@ void NetworkTask_main(void*) | ||||||
|     for (;;) { |     for (;;) { | ||||||
|         size_t packet_size = dequeue_packet(buffer, buffer_size, packet_timestamp); |         size_t packet_size = dequeue_packet(buffer, buffer_size, packet_timestamp); | ||||||
|         if (!packet_size) { |         if (!packet_size) { | ||||||
|             packet_wait_queue.wait_on({}, "NetworkTask"); |             packet_wait_queue.wait_forever("NetworkTask"); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|         if (packet_size < sizeof(EthernetFrameHeader)) { |         if (packet_size < sizeof(EthernetFrameHeader)) { | ||||||
|  |  | ||||||
|  | @ -91,7 +91,7 @@ void KernelRng::wait_for_entropy() | ||||||
|     ScopedSpinLock lock(get_lock()); |     ScopedSpinLock lock(get_lock()); | ||||||
|     if (!resource().is_ready()) { |     if (!resource().is_ready()) { | ||||||
|         dbgln("Entropy starvation..."); |         dbgln("Entropy starvation..."); | ||||||
|         m_seed_queue.wait_on({}, "KernelRng"); |         m_seed_queue.wait_forever("KernelRng"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ void FinalizerTask::spawn() | ||||||
|         finalizer_thread, "FinalizerTask", [](void*) { |         finalizer_thread, "FinalizerTask", [](void*) { | ||||||
|             Thread::current()->set_priority(THREAD_PRIORITY_LOW); |             Thread::current()->set_priority(THREAD_PRIORITY_LOW); | ||||||
|             for (;;) { |             for (;;) { | ||||||
|                 g_finalizer_wait_queue->wait_on({}, "FinalizerTask"); |                 g_finalizer_wait_queue->wait_forever("FinalizerTask"); | ||||||
| 
 | 
 | ||||||
|                 if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true) |                 if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true) | ||||||
|                     Thread::finalize_dying_threads(); |                     Thread::finalize_dying_threads(); | ||||||
|  |  | ||||||
|  | @ -50,6 +50,12 @@ public: | ||||||
|         return Thread::current()->block<Thread::QueueBlocker>(timeout, *this, forward<Args>(args)...); |         return Thread::current()->block<Thread::QueueBlocker>(timeout, *this, forward<Args>(args)...); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     template<class... Args> | ||||||
|  |     void wait_forever(Args&&... args) | ||||||
|  |     { | ||||||
|  |         (void)Thread::current()->block<Thread::QueueBlocker>({}, *this, forward<Args>(args)...); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| protected: | protected: | ||||||
|     virtual bool should_add_blocker(Thread::Blocker& b, void* data) override; |     virtual bool should_add_blocker(Thread::Blocker& b, void* data) override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brian Gianforcaro
						Brian Gianforcaro