Skip to content

Commit

Permalink
LZEventPool finish
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelesko committed Feb 20, 2024
1 parent b8e96a3 commit 07375a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/backend/Level0/CHIPBackendLevel0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,8 @@ void CHIPStaleEventMonitorLevel0::checkEvents() {

ChipEventLz->isDeletedSanityCheck();

// delete the event if refcount reached 2
// this->ChipEvent and LZEventPool::Events_
if (ChipEventLz.use_count() == 2) {
// delete the event if refcount reached 1 (this->ChipEventLz)
if (ChipEventLz.use_count() == 1) {
if (ChipEventLz->EventPool) {
ChipEventLz->isDeletedSanityCheck();
ChipEventLz->EventPool->returnEvent(ChipEventLz);
Expand Down Expand Up @@ -1682,8 +1681,7 @@ LZEventPool::LZEventPool(CHIPContextLevel0 *Ctx, unsigned int Size)
chipstar::EventFlags Flags;
auto NewEvent = std::shared_ptr<CHIPEventLevel0>(
new CHIPEventLevel0(Ctx_, this, i, Flags));
Events_.push_back(NewEvent);
AvailableEvents_.push(NewEvent);
Events_.push(NewEvent);
}
};

Expand All @@ -1695,9 +1693,8 @@ LZEventPool::~LZEventPool() {
logWarn("CHIPUserEventLevel0 objects still exist at the time of EventPool "
"destruction");

while (AvailableEvents_.size())
AvailableEvents_.pop();
Events_.clear(); // shared_ptr's will be deleted
while (Events_.size())
Events_.pop();
// The application must not call this function from
// simultaneous threads with the same event pool handle.
// Done via destructor should not be called from multiple threads
Expand All @@ -1708,11 +1705,11 @@ LZEventPool::~LZEventPool() {

std::shared_ptr<CHIPEventLevel0> LZEventPool::getEvent() {
std::shared_ptr<CHIPEventLevel0> Event;
if (!AvailableEvents_.size())
if (!Events_.size())
return nullptr;

Event = AvailableEvents_.top();
AvailableEvents_.pop();
Event = Events_.top();
Events_.pop();

return Event;
};
Expand All @@ -1723,7 +1720,7 @@ void LZEventPool::returnEvent(std::shared_ptr<CHIPEventLevel0> Event) {
LOCK(EventPoolMtx);
logTrace("Returning event {} handle {}", (void *)Event.get(),
(void *)Event.get()->get());
AvailableEvents_.push(Event);
Events_.push(Event);
}

// End EventPool
Expand Down
5 changes: 2 additions & 3 deletions src/backend/Level0/CHIPBackendLevel0.hh
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,13 @@ private:
CHIPContextLevel0 *Ctx_;
ze_event_pool_handle_t EventPool_;
unsigned int Size_;
std::vector<std::shared_ptr<CHIPEventLevel0>> Events_;
std::stack<std::shared_ptr<CHIPEventLevel0>> AvailableEvents_;
std::stack<std::shared_ptr<CHIPEventLevel0>> Events_;

public:
std::mutex EventPoolMtx;
LZEventPool(CHIPContextLevel0 *Ctx, unsigned int Size);
~LZEventPool();
bool EventAvailable() { return AvailableEvents_.size() > 0; }
bool EventAvailable() { return Events_.size() > 0; }
ze_event_pool_handle_t get() { return EventPool_; }

void returnEvent(std::shared_ptr<CHIPEventLevel0> Event);
Expand Down

0 comments on commit 07375a7

Please sign in to comment.