Skip to content

Commit

Permalink
[orbis-kernel] Event flag fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Jul 17, 2023
1 parent e9ffa97 commit 00690fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion orbis-kernel/include/orbis/KernelContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
auto [it, inserted] = m_event_flags.try_emplace(std::move(name), nullptr);
if (inserted) {
it->second = knew<EventFlag>(flags, initPattern);
std::strncpy(it->second->name, it->first.c_str(), 32);
}

return {it->second.get(), inserted};
Expand Down Expand Up @@ -106,7 +107,6 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
}

private:
shared_mutex m_evf_mtx;
mutable pthread_mutex_t m_heap_mtx;
void *m_heap_next = this + 1;
bool m_heap_is_freeing = false;
Expand All @@ -119,6 +119,8 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {

mutable shared_mutex m_proc_mtx;
utils::LinkedNode<Process> *m_processes = nullptr;

shared_mutex m_evf_mtx;
utils::kmap<utils::kstring, Ref<EventFlag>> m_event_flags;
};

Expand Down
12 changes: 7 additions & 5 deletions orbis-kernel/src/sys/sys_sce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,21 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr<const char[32]> name,
}

switch (attrs & (kEvfAttrSingle | kEvfAttrMulti)) {
case 0:
case kEvfAttrSingle | kEvfAttrMulti:
attrs = (attrs & ~(kEvfAttrSingle | kEvfAttrMulti)) | kEvfAttrSingle;
return ErrorCode::INVAL;
case 0:
attrs |= kEvfAttrSingle;
break;

default:
break;
}

switch (attrs & (kEvfAttrThPrio | kEvfAttrThFifo)) {
case 0:
case kEvfAttrThPrio | kEvfAttrThFifo:
attrs = (attrs & ~(kEvfAttrThPrio | kEvfAttrThFifo)) | kEvfAttrThFifo;
return ErrorCode::INVAL;
case 0:
attrs |= kEvfAttrThFifo;
break;

default:
Expand All @@ -131,6 +133,7 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr<const char[32]> name,
eventFlag = insertedEvf;
} else {
eventFlag = knew<EventFlag>(attrs, initPattern);
std::strncpy(eventFlag->name, _name, 32);
}

thread->retval[0] = thread->tproc->evfMap.insert(eventFlag);
Expand Down Expand Up @@ -162,7 +165,6 @@ orbis::SysResult orbis::sys_evf_open(Thread *thread, ptr<const char[32]> name) {
return ErrorCode::SRCH;
}

std::strcpy(eventFlag->name, _name);
thread->retval[0] = thread->tproc->evfMap.insert(eventFlag);
return {};
}
Expand Down

0 comments on commit 00690fd

Please sign in to comment.