kernel/vm: DaemonCondition is really just a basic binary semaphore.

So split it off into its own file. This will make it easier to
split the page writer off into a separate file.
This commit is contained in:
Augustin Cavalier
2026-04-06 22:23:26 -04:00
parent f091a24ee2
commit 62b8be7e22
2 changed files with 74 additions and 59 deletions
@@ -0,0 +1,71 @@
/*
* Copyright 2010, Ingo Weinhold, [email protected].
* Copyright 2026, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef KERNEL_UTIL_BINARY_SEMAPHORE_H
#define KERNEL_UTIL_BINARY_SEMAPHORE_H
#include <condition_variable.h>
#include <util/AutoLock.h>
struct BinarySemaphore {
void Init(const char* name)
{
mutex_init(&fLock, "binary semaphore");
fCondition.Init(this, name);
fActivated = false;
}
bool Lock()
{
return mutex_lock(&fLock) == B_OK;
}
void Unlock()
{
mutex_unlock(&fLock);
}
bool Wait(bigtime_t timeout, bool clearActivated)
{
MutexLocker locker(fLock);
if (clearActivated)
fActivated = false;
else if (fActivated)
return true;
ConditionVariableEntry entry;
fCondition.Add(&entry);
locker.Unlock();
return entry.Wait(B_RELATIVE_TIMEOUT, timeout) == B_OK;
}
void WakeUp()
{
if (fActivated)
return;
MutexLocker locker(fLock);
fActivated = true;
fCondition.NotifyOne();
}
void ClearActivated()
{
MutexLocker locker(fLock);
fActivated = false;
}
private:
mutex fLock;
ConditionVariable fCondition;
bool fActivated;
};
#endif // KERNEL_UTIL_BINARY_SEMAPHORE_H