[orbis-kernel] evf: implement shared evf

Protect shared evfs with mutex
Fixed memory leak on shared evf allocation
Fixed set condition on wait
Update RcIdMap usage to use new api
This commit is contained in:
DH 2023-07-08 02:21:10 +03:00
parent e613f09b6d
commit 800c1ffcdc
6 changed files with 50 additions and 22 deletions

View file

@ -27,12 +27,19 @@ public:
std::pair<EventFlag *, bool> createEventFlag(utils::kstring name,
std::int32_t flags) {
auto [it, inserted] =
m_event_flags.try_emplace(std::move(name), knew<EventFlag>(flags));
std::lock_guard lock(m_evf_mtx);
auto [it, inserted] = m_event_flags.try_emplace(std::move(name), nullptr);
if (inserted) {
it->second = knew<EventFlag>(flags);
}
return {it->second.get(), inserted};
}
Ref<EventFlag> findEventFlag(std::string_view name) {
std::lock_guard lock(m_evf_mtx);
if (auto it = m_event_flags.find(name); it != m_event_flags.end()) {
return it->second;
}
@ -41,6 +48,7 @@ public:
}
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;

View file

@ -11,6 +11,7 @@ enum {
kEvfAttrThPrio = 0x02,
kEvfAttrSingle = 0x10,
kEvfAttrMulti = 0x20,
kEvfAttrShared = 0x100,
};
enum {