Skip to content

Commit

Permalink
remove lock in event management (#19285)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored Jun 8, 2022
1 parent b2fe30f commit b8e9ab1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
36 changes: 2 additions & 34 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3
mpEventBuffer = apCircularEventBuffer;
mState = EventManagementStates::Idle;
mBytesWritten = 0;

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
CHIP_ERROR err = chip::System::Mutex::Init(mAccessLock);
if (err != CHIP_NO_ERROR)
{
ChipLogError(EventLogging, "mutex init fails with error %s", ErrorStr(err));
}
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING
}

CHIP_ERROR EventManagement::CopyToNextBuffer(CircularEventBuffer * apEventBuffer)
Expand Down Expand Up @@ -347,9 +339,6 @@ void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExcha
*/
void EventManagement::DestroyEventManagement()
{
#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
ScopedLock lock(sInstance);
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING
sInstance.mState = EventManagementStates::Shutdown;
sInstance.mpEventBuffer = nullptr;
sInstance.mpExchangeMgr = nullptr;
Expand Down Expand Up @@ -408,17 +397,8 @@ void EventManagement::VendEventNumber()
CHIP_ERROR EventManagement::LogEvent(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions,
EventNumber & aEventNumber)
{
CHIP_ERROR err = CHIP_NO_ERROR;
{
#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
ScopedLock lock(sInstance);
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

VerifyOrExit(mState != EventManagementStates::Shutdown, err = CHIP_ERROR_INCORRECT_STATE);
err = LogEventPrivate(apDelegate, aEventOptions, aEventNumber);
}
exit:
return err;
VerifyOrReturnError(mState != EventManagementStates::Shutdown, CHIP_ERROR_INCORRECT_STATE);
return LogEventPrivate(apDelegate, aEventOptions, aEventNumber);
}

CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions,
Expand Down Expand Up @@ -721,10 +701,6 @@ CHIP_ERROR EventManagement::FetchEventsSince(TLVWriter & aWriter, const ObjectLi
CircularEventBufferWrapper bufWrapper;
EventLoadOutContext context(aWriter, PriorityLevel::Invalid, aEventMin);

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
ScopedLock lock(sInstance);
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

context.mSubjectDescriptor = aSubjectDescriptor;
context.mpInterestedEventPaths = apEventPathList;
err = GetEventReader(reader, PriorityLevel::Critical, &bufWrapper);
Expand Down Expand Up @@ -801,10 +777,6 @@ CHIP_ERROR EventManagement::FabricRemoved(FabricIndex aFabricIndex)
TLVReader reader;
CircularEventBufferWrapper bufWrapper;

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
ScopedLock lock(sInstance);
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

ReturnErrorOnFailure(GetEventReader(reader, PriorityLevel::Critical, &bufWrapper));
CHIP_ERROR err = TLV::Utilities::Iterate(reader, FabricRemovedCB, &aFabricIndex, recurse);
if (err == CHIP_END_OF_TLV)
Expand Down Expand Up @@ -925,10 +897,6 @@ CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void *

void EventManagement::SetScheduledEventInfo(EventNumber & aEventNumber, uint32_t & aInitialWrittenEventBytes) const
{
#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
ScopedLock lock(sInstance);
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

aEventNumber = mLastEventNumber;
aInitialWrittenEventBytes = mBytesWritten;
}
Expand Down
16 changes: 0 additions & 16 deletions src/app/EventManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <lib/core/CHIPCircularTLVBuffer.h>
#include <lib/support/CHIPCounter.h>
#include <messaging/ExchangeMgr.h>
#include <system/SystemMutex.h>

#define CHIP_CONFIG_EVENT_GLOBAL_PRIORITY PriorityLevel::Debug

Expand Down Expand Up @@ -229,18 +228,6 @@ class EventManagement

static void DestroyEventManagement();

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
class ScopedLock
{
public:
ScopedLock(EventManagement & aEventManagement) : mEventManagement(aEventManagement) { mEventManagement.mAccessLock.Lock(); }
~ScopedLock() { mEventManagement.mAccessLock.Unlock(); }

private:
EventManagement & mEventManagement;
};
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

/**
* @brief
* Log an event via a EventLoggingDelegate, with options.
Expand Down Expand Up @@ -523,9 +510,6 @@ class EventManagement
Messaging::ExchangeManager * mpExchangeMgr = nullptr;
EventManagementStates mState = EventManagementStates::Shutdown;
uint32_t mBytesWritten = 0;
#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
System::Mutex mAccessLock;
#endif // !CHIP_SYSTEM_CONFIG_NO_LOCKING

// The counter we're going to use for event numbers.
MonotonicallyIncreasingCounter<EventNumber> * mpEventNumberCounter = nullptr;
Expand Down

0 comments on commit b8e9ab1

Please sign in to comment.