forked from Bananymous/banan-os
				
			Kernel: Allow relockign mutex even when holding a spinlock
Only reason mutex locking is now allowed with spinlocks is to prevent yield. Also try_lock can be now safely used while holding a spinlock
This commit is contained in:
		
							parent
							
								
									e8491b34b8
								
							
						
					
					
						commit
						db571b4859
					
				|  | @ -32,11 +32,11 @@ namespace Kernel | ||||||
| 		void lock() override | 		void lock() override | ||||||
| 		{ | 		{ | ||||||
| 			const auto tid = Thread::current_tid(); | 			const auto tid = Thread::current_tid(); | ||||||
| 			ASSERT(!tid || !Thread::current().has_spinlock()); |  | ||||||
| 			if (tid == m_locker) | 			if (tid == m_locker) | ||||||
| 				ASSERT(m_lock_depth > 0); | 				ASSERT(m_lock_depth > 0); | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
|  | 				ASSERT(!tid || !Thread::current().has_spinlock()); | ||||||
| 				pid_t expected = -1; | 				pid_t expected = -1; | ||||||
| 				while (!m_locker.compare_exchange(expected, tid)) | 				while (!m_locker.compare_exchange(expected, tid)) | ||||||
| 				{ | 				{ | ||||||
|  | @ -53,7 +53,6 @@ namespace Kernel | ||||||
| 		bool try_lock() override | 		bool try_lock() override | ||||||
| 		{ | 		{ | ||||||
| 			const auto tid = Thread::current_tid(); | 			const auto tid = Thread::current_tid(); | ||||||
| 			ASSERT(!tid || !Thread::current().has_spinlock()); |  | ||||||
| 			if (tid == m_locker) | 			if (tid == m_locker) | ||||||
| 				ASSERT(m_lock_depth > 0); | 				ASSERT(m_lock_depth > 0); | ||||||
| 			else | 			else | ||||||
|  | @ -102,12 +101,12 @@ namespace Kernel | ||||||
| 		void lock() override | 		void lock() override | ||||||
| 		{ | 		{ | ||||||
| 			const auto tid = Thread::current_tid(); | 			const auto tid = Thread::current_tid(); | ||||||
| 			ASSERT(!tid || !Thread::current().has_spinlock()); |  | ||||||
| 
 | 
 | ||||||
| 			if (tid == m_locker) | 			if (tid == m_locker) | ||||||
| 				ASSERT(m_lock_depth > 0); | 				ASSERT(m_lock_depth > 0); | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
|  | 				ASSERT(!tid || !Thread::current().has_spinlock()); | ||||||
| 				bool has_priority = tid ? !Thread::current().is_userspace() : true; | 				bool has_priority = tid ? !Thread::current().is_userspace() : true; | ||||||
| 				if (has_priority) | 				if (has_priority) | ||||||
| 					m_queue_length++; | 					m_queue_length++; | ||||||
|  | @ -127,7 +126,6 @@ namespace Kernel | ||||||
| 		bool try_lock() override | 		bool try_lock() override | ||||||
| 		{ | 		{ | ||||||
| 			const auto tid = Thread::current_tid(); | 			const auto tid = Thread::current_tid(); | ||||||
| 			ASSERT(!tid || !Thread::current().has_spinlock()); |  | ||||||
| 
 | 
 | ||||||
| 			if (tid == m_locker) | 			if (tid == m_locker) | ||||||
| 				ASSERT(m_lock_depth > 0); | 				ASSERT(m_lock_depth > 0); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue