mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:42:43 +00:00 
			
		
		
		
	Kernel: Simplify unregistering a Blocker from a BlockerSet
The BlockerSet stores its blockers along with a "void* data" that may contain some blocker-specific context relevant to the specific blocker registration (for example, SelectBlocker stores a pointer to the relevant entry in an array of SelectBlocker::FDInfo structs.) When unregistering a blocker from a set, we don't need to key the blocker by both the Blocker* and the data. Just the Blocker* is enough, since all registrations for that blocker need to be removed anyway as the blocker is about to be destroyed. So we stop passing the "void* data" to BlockerSet::remove_blocker(), which also allows us to remove the now-unneeded Blocker::m_block_data.
This commit is contained in:
		
							parent
							
								
									6ce05026b4
								
							
						
					
					
						commit
						c351945474
					
				
					 2 changed files with 5 additions and 7 deletions
				
			
		|  | @ -393,7 +393,6 @@ public: | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         BlockerSet* m_blocker_set { nullptr }; |         BlockerSet* m_blocker_set { nullptr }; | ||||||
|         void* m_block_data { nullptr }; |  | ||||||
|         Thread* m_blocked_thread { nullptr }; |         Thread* m_blocked_thread { nullptr }; | ||||||
|         u8 m_was_interrupted_by_signal { 0 }; |         u8 m_was_interrupted_by_signal { 0 }; | ||||||
|         bool m_is_blocking { false }; |         bool m_is_blocking { false }; | ||||||
|  | @ -423,12 +422,12 @@ public: | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         void remove_blocker(Blocker& blocker, void* data) |         void remove_blocker(Blocker& blocker) | ||||||
|         { |         { | ||||||
|             SpinlockLocker lock(m_lock); |             SpinlockLocker lock(m_lock); | ||||||
|             // NOTE: it's possible that the blocker is no longer present
 |             // NOTE: it's possible that the blocker is no longer present
 | ||||||
|             m_blockers.remove_first_matching([&](auto& info) { |             m_blockers.remove_all_matching([&](auto& info) { | ||||||
|                 return info.blocker == &blocker && info.data == data; |                 return info.blocker == &blocker; | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -33,7 +33,6 @@ bool Thread::Blocker::add_to_blocker_set(Thread::BlockerSet& blocker_set, void* | ||||||
|     VERIFY(!m_blocker_set); |     VERIFY(!m_blocker_set); | ||||||
|     if (blocker_set.add_blocker(*this, data)) { |     if (blocker_set.add_blocker(*this, data)) { | ||||||
|         m_blocker_set = &blocker_set; |         m_blocker_set = &blocker_set; | ||||||
|         m_block_data = data; |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|     return false; |     return false; | ||||||
|  | @ -43,7 +42,7 @@ Thread::Blocker::~Blocker() | ||||||
| { | { | ||||||
|     VERIFY(!m_lock.is_locked()); |     VERIFY(!m_lock.is_locked()); | ||||||
|     if (m_blocker_set) |     if (m_blocker_set) | ||||||
|         m_blocker_set->remove_blocker(*this, m_block_data); |         m_blocker_set->remove_blocker(*this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Thread::Blocker::begin_blocking(Badge<Thread>) | void Thread::Blocker::begin_blocking(Badge<Thread>) | ||||||
|  | @ -355,7 +354,7 @@ Thread::SelectBlocker::SelectBlocker(FDVector& fds) | ||||||
| Thread::SelectBlocker::~SelectBlocker() | Thread::SelectBlocker::~SelectBlocker() | ||||||
| { | { | ||||||
|     for (auto& fd_entry : m_fds) |     for (auto& fd_entry : m_fds) | ||||||
|         fd_entry.description->blocker_set().remove_blocker(*this, &fd_entry); |         fd_entry.description->blocker_set().remove_blocker(*this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Thread::SelectBlocker::will_unblock_immediately_without_blocking(UnblockImmediatelyReason reason) | void Thread::SelectBlocker::will_unblock_immediately_without_blocking(UnblockImmediatelyReason reason) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling