summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/KernelKit/Semaphore.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-24 12:25:55 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-24 12:25:55 +0100
commit0c43e344918569474e1460876105c9f1eb43efa8 (patch)
tree4ea54404a0967e48147262a392fa52c2749bddc9 /src/kernel/KernelKit/Semaphore.h
parent5b5081e679a0481356d1e026310546ac632b1c87 (diff)
[FEAT] Kernel: UTF-8 usage in UserMgr.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel/KernelKit/Semaphore.h')
-rw-r--r--src/kernel/KernelKit/Semaphore.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/kernel/KernelKit/Semaphore.h b/src/kernel/KernelKit/Semaphore.h
index bb6b9ba9..4dc9a454 100644
--- a/src/kernel/KernelKit/Semaphore.h
+++ b/src/kernel/KernelKit/Semaphore.h
@@ -29,6 +29,7 @@ using SemaphoreArr = UInt64[kSemaphoreCount];
/// @brief Checks if the semaphore is valid.
inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) {
+ if (!sem) return false;
return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0;
}
@@ -36,6 +37,8 @@ inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) {
/// @param sem
/// @return
inline bool rtl_sem_release(SemaphoreArr& sem) {
+ if (!sem) return false;
+
sem[kSemaphoreOwnerIndex] = 0;
sem[kSemaphoreCountIndex] = 0;
@@ -47,6 +50,8 @@ inline bool rtl_sem_release(SemaphoreArr& sem) {
/// @param owner the owner to set, could be anything identifitable.
/// @return
inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) {
+ if (!sem) return false;
+
if (!owner) {
err_global_get() = kErrorInvalidData;
return false; // Invalid owner, return false and set KPC.
@@ -65,6 +70,8 @@ inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) {
/// @return
inline bool rtl_sem_wait(SemaphoreArr& sem, const UInt64& owner, const UInt64& timeout,
bool& condition) {
+ if (!sem) return false;
+
if (!rtl_sem_is_valid(sem, owner)) {
return false;
}