@@ -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
17091706std::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
0 commit comments