kernel: Make use of the new ConditionVariable lock-switching APIs in a few places.

This commit is contained in:
Augustin Cavalier 2022-04-25 17:59:50 -04:00
parent 8af7b72d8d
commit 8f68daed84
4 changed files with 5 additions and 32 deletions

View File

@ -122,15 +122,7 @@ KernelDaemon::Unregister(daemon_hook function, void* arg)
// wait if it's busy // wait if it's busy
while (daemon->executing) { while (daemon->executing) {
fUnregisterWaiters++; fUnregisterWaiters++;
fUnregisterCondition.Wait(locker.Get());
ConditionVariableEntry entry;
fUnregisterCondition.Add(&entry);
locker.Unlock();
entry.Wait();
locker.Lock();
} }
} }

View File

@ -111,13 +111,8 @@ user_mutex_wait_locked(int32* mutex, addr_t physicalAddress, const char* name,
add_user_mutex_entry(&entry); add_user_mutex_entry(&entry);
// wait // wait
ConditionVariableEntry waitEntry;
entry.condition.Init((void*)physicalAddress, "user mutex"); entry.condition.Init((void*)physicalAddress, "user mutex");
entry.condition.Add(&waitEntry); status_t error = entry.condition.Wait(locker.Get(), flags, timeout);
locker.Unlock();
status_t error = waitEntry.Wait(flags, timeout);
locker.Lock();
if (error != B_OK && entry.locked) if (error != B_OK && entry.locked)
error = B_OK; error = B_OK;

View File

@ -983,12 +983,7 @@ MemoryManager::_AllocateChunks(size_t chunkSize, uint32 chunkCount,
} else } else
break; break;
ConditionVariableEntry entry; allocationEntry->condition.Wait(&sLock);
allocationEntry->condition.Add(&entry);
mutex_unlock(&sLock);
entry.Wait();
mutex_lock(&sLock);
if (_GetChunks(metaChunkList, chunkSize, chunkCount, _metaChunk, if (_GetChunks(metaChunkList, chunkSize, chunkCount, _metaChunk,
_chunk)) { _chunk)) {

View File

@ -920,12 +920,7 @@ object_cache_reserve_internal(ObjectCache* cache, size_t objectCount,
} else } else
break; break;
ConditionVariableEntry entry; resizeEntry->condition.Wait(&cache->lock);
resizeEntry->condition.Add(&entry);
cache->Unlock();
entry.Wait();
cache->Lock();
} }
// prepare the resize entry others can wait on // prepare the resize entry others can wait on
@ -1072,11 +1067,7 @@ object_cache_maintainer(void*)
continue; continue;
} }
ConditionVariableEntry entry; sMaintenanceCondition.Wait(locker.Get());
sMaintenanceCondition.Add(&entry);
locker.Unlock();
entry.Wait();
locker.Lock();
} }
ObjectCache* cache = sMaintenanceQueue.RemoveHead(); ObjectCache* cache = sMaintenanceQueue.RemoveHead();