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:
@@ -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
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
#include <BinarySemaphore.h>
|
||||||
|
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
#include <arch/vm_translation_map.h>
|
#include <arch/vm_translation_map.h>
|
||||||
@@ -196,65 +197,8 @@ typedef DoublyLinkedList<PageReservationWaiter> PageReservationWaiterList;
|
|||||||
static PageReservationWaiterList sPageReservationWaiters;
|
static PageReservationWaiterList sPageReservationWaiters;
|
||||||
|
|
||||||
|
|
||||||
struct DaemonCondition {
|
static BinarySemaphore sPageWriterCondition;
|
||||||
void Init(const char* name)
|
static BinarySemaphore sPageDaemonCondition;
|
||||||
{
|
|
||||||
mutex_init(&fLock, "daemon condition");
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static DaemonCondition sPageWriterCondition;
|
|
||||||
static DaemonCondition sPageDaemonCondition;
|
|
||||||
|
|
||||||
|
|
||||||
#if PAGE_ALLOCATION_TRACING
|
#if PAGE_ALLOCATION_TRACING
|
||||||
|
|||||||
Reference in New Issue
Block a user