From 10b620f76f0b0fd31b8832cc04c637b1076796ac Mon Sep 17 00:00:00 2001 From: DH Date: Wed, 5 Jul 2023 23:05:33 +0300 Subject: [PATCH] [orbis-kernel] Implement evf delete --- orbis-kernel/include/orbis/evf.hpp | 5 +++-- orbis-kernel/src/sys/sys_sce.cpp | 34 ++++++++++++++++++------------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/orbis-kernel/include/orbis/evf.hpp b/orbis-kernel/include/orbis/evf.hpp index 0310fa91f..90787807f 100644 --- a/orbis-kernel/include/orbis/evf.hpp +++ b/orbis-kernel/include/orbis/evf.hpp @@ -1,4 +1,5 @@ #pragma once +#include "KernelAllocator.hpp" #include "thread/Thread.hpp" #include "utils/SharedMutex.hpp" #include @@ -24,7 +25,7 @@ struct EventFlag { bool isDeleted = false; std::uint8_t attrs; - std::atomic references{1}; + std::atomic references{0}; std::atomic value; struct WaitingThread { @@ -97,7 +98,7 @@ struct EventFlag { void decRef() { if (references.fetch_sub(1, std::memory_order::relaxed) == 1) { - delete this; + kdelete(this); } } }; diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index cb5506997..9ae6e81ad 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -117,8 +117,16 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr name, return {}; } orbis::SysResult orbis::sys_evf_delete(Thread *thread, sint id) { - ORBIS_LOG_TODO(__FUNCTION__, id); - return ErrorCode::NOSYS; + Ref evf = thread->tproc->evfMap.get(id); + if (evf == nullptr) { + return ErrorCode::SRCH; + } + + // TODO: do destroy and remove atomically + evf->destroy(); + thread->tproc->evfMap.remove(id); + + return {}; } orbis::SysResult orbis::sys_evf_open(Thread *thread, ptr name) { char _name[32]; @@ -139,7 +147,7 @@ orbis::SysResult orbis::sys_evf_open(Thread *thread, ptr name) { } orbis::SysResult orbis::sys_evf_close(Thread *thread, sint id) { if (!thread->tproc->evfMap.remove(id)) { - return ErrorCode::BADF; + return ErrorCode::SRCH; } return {}; @@ -155,10 +163,10 @@ orbis::SysResult orbis::sys_evf_wait(Thread *thread, sint id, return ErrorCode::INVAL; } - auto evf = thread->tproc->evfMap.get(id); + Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { - return ErrorCode::BADF; + return ErrorCode::SRCH; } std::uint32_t resultTimeout{}; @@ -187,10 +195,10 @@ orbis::SysResult orbis::sys_evf_trywait(Thread *thread, sint id, return ErrorCode::INVAL; } - auto evf = thread->tproc->evfMap.get(id); + Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { - return ErrorCode::BADF; + return ErrorCode::SRCH; } std::uint64_t resultPattern{}; @@ -203,30 +211,30 @@ orbis::SysResult orbis::sys_evf_trywait(Thread *thread, sint id, return result; } orbis::SysResult orbis::sys_evf_set(Thread *thread, sint id, uint64_t value) { - auto evf = thread->tproc->evfMap.get(id); + Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { - return ErrorCode::BADF; + return ErrorCode::SRCH; } evf->set(value); return{}; } orbis::SysResult orbis::sys_evf_clear(Thread *thread, sint id, uint64_t value) { - auto evf = thread->tproc->evfMap.get(id); + Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { - return ErrorCode::BADF; + return ErrorCode::SRCH; } evf->clear(value); return{}; } orbis::SysResult orbis::sys_evf_cancel(Thread *thread, sint id, uint64_t value, ptr pNumWaitThreads) { - auto evf = thread->tproc->evfMap.get(id); + Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { - return ErrorCode::BADF; + return ErrorCode::SRCH; } auto numWaitThreads = evf->cancel(value);