[orbis-kernel] Implement evf delete

This commit is contained in:
DH 2023-07-05 23:05:33 +03:00
parent cd9ced41d8
commit 10b620f76f
2 changed files with 24 additions and 15 deletions

View file

@ -1,4 +1,5 @@
#pragma once
#include "KernelAllocator.hpp"
#include "thread/Thread.hpp"
#include "utils/SharedMutex.hpp"
#include <atomic>
@ -24,7 +25,7 @@ struct EventFlag {
bool isDeleted = false;
std::uint8_t attrs;
std::atomic<unsigned> references{1};
std::atomic<unsigned> references{0};
std::atomic<std::uint64_t> 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);
}
}
};

View file

@ -117,8 +117,16 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr<char> name,
return {};
}
orbis::SysResult orbis::sys_evf_delete(Thread *thread, sint id) {
ORBIS_LOG_TODO(__FUNCTION__, id);
return ErrorCode::NOSYS;
Ref<EventFlag> 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<char> name) {
char _name[32];
@ -139,7 +147,7 @@ orbis::SysResult orbis::sys_evf_open(Thread *thread, ptr<char> 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<EventFlag> 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<EventFlag> 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<EventFlag> 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<EventFlag> 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<sint> pNumWaitThreads) {
auto evf = thread->tproc->evfMap.get(id);
Ref<EventFlag> evf = thread->tproc->evfMap.get(id);
if (evf == nullptr) {
return ErrorCode::BADF;
return ErrorCode::SRCH;
}
auto numWaitThreads = evf->cancel(value);