Skip to content

Commit 07375a7

Browse files
committed
LZEventPool finish
1 parent b8e96a3 commit 07375a7

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/backend/Level0/CHIPBackendLevel0.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,8 @@ void CHIPStaleEventMonitorLevel0::checkEvents() {
721721

722722
ChipEventLz->isDeletedSanityCheck();
723723

724-
// delete the event if refcount reached 2
725-
// this->ChipEvent and LZEventPool::Events_
726-
if (ChipEventLz.use_count() == 2) {
724+
// delete the event if refcount reached 1 (this->ChipEventLz)
725+
if (ChipEventLz.use_count() == 1) {
727726
if (ChipEventLz->EventPool) {
728727
ChipEventLz->isDeletedSanityCheck();
729728
ChipEventLz->EventPool->returnEvent(ChipEventLz);
@@ -1682,8 +1681,7 @@ LZEventPool::LZEventPool(CHIPContextLevel0 *Ctx, unsigned int Size)
16821681
chipstar::EventFlags Flags;
16831682
auto NewEvent = std::shared_ptr<CHIPEventLevel0>(
16841683
new CHIPEventLevel0(Ctx_, this, i, Flags));
1685-
Events_.push_back(NewEvent);
1686-
AvailableEvents_.push(NewEvent);
1684+
Events_.push(NewEvent);
16871685
}
16881686
};
16891687

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

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

17091706
std::shared_ptr<CHIPEventLevel0> LZEventPool::getEvent() {
17101707
std::shared_ptr<CHIPEventLevel0> Event;
1711-
if (!AvailableEvents_.size())
1708+
if (!Events_.size())
17121709
return nullptr;
17131710

1714-
Event = AvailableEvents_.top();
1715-
AvailableEvents_.pop();
1711+
Event = Events_.top();
1712+
Events_.pop();
17161713

17171714
return Event;
17181715
};
@@ -1723,7 +1720,7 @@ void LZEventPool::returnEvent(std::shared_ptr<CHIPEventLevel0> Event) {
17231720
LOCK(EventPoolMtx);
17241721
logTrace("Returning event {} handle {}", (void *)Event.get(),
17251722
(void *)Event.get()->get());
1726-
AvailableEvents_.push(Event);
1723+
Events_.push(Event);
17271724
}
17281725

17291726
// End EventPool

src/backend/Level0/CHIPBackendLevel0.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ private:
208208
CHIPContextLevel0 *Ctx_;
209209
ze_event_pool_handle_t EventPool_;
210210
unsigned int Size_;
211-
std::vector<std::shared_ptr<CHIPEventLevel0>> Events_;
212-
std::stack<std::shared_ptr<CHIPEventLevel0>> AvailableEvents_;
211+
std::stack<std::shared_ptr<CHIPEventLevel0>> Events_;
213212

214213
public:
215214
std::mutex EventPoolMtx;
216215
LZEventPool(CHIPContextLevel0 *Ctx, unsigned int Size);
217216
~LZEventPool();
218-
bool EventAvailable() { return AvailableEvents_.size() > 0; }
217+
bool EventAvailable() { return Events_.size() > 0; }
219218
ze_event_pool_handle_t get() { return EventPool_; }
220219

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

0 commit comments

Comments
 (0)