Skip to content

Commit

Permalink
Remove APIs which on longer make sense in heap based ObjectPool (#9229)
Browse files Browse the repository at this point in the history
* Remove APIs which do not make sense in dynamic pool

* Remove the sMutex protection from unit test
  • Loading branch information
yufengwangca authored and pull[bot] committed Oct 4, 2021
1 parent 22d906d commit 3319217
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 263 deletions.
62 changes: 1 addition & 61 deletions src/system/SystemObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ class ObjectPool
{
public:
void Reset();
size_t Size();

T * Get(const Layer & aLayer, size_t aIndex);
T * TryCreate(Layer & aLayer);
void GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark);

Expand Down Expand Up @@ -265,69 +263,11 @@ inline void ObjectPool<T, N>::Reset()
memset(mArena.uMemory, 0, N * sizeof(T));

#if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS
mHighWatermark = 0;
mHighWatermark = 0;
#endif
#endif
}

/**
* @brief
* Returns the number of objects that can be simultaneously retained from a pool.
*/
template <class T, unsigned int N>
inline size_t ObjectPool<T, N>::Size()
{
#if CHIP_SYSTEM_CONFIG_POOL_USE_HEAP
size_t count = 0;
std::lock_guard<std::mutex> lock(mMutex);
Object * p = mDummyHead.mNext;

while (p)
{
count++;
p = p->mNext;
}

return count;
#else
return N;
#endif
}

/**
* @brief
* Returns a pointer the object at \c aIndex or \c NULL if the object is not retained by \c aLayer.
*/
template <class T, unsigned int N>
inline T * ObjectPool<T, N>::Get(const Layer & aLayer, size_t aIndex)
{
T * lReturn = nullptr;

#if CHIP_SYSTEM_CONFIG_POOL_USE_HEAP
{
std::lock_guard<std::mutex> lock(mMutex);
Object * p = mDummyHead.mNext;

while (aIndex > 0)
{
if (p == nullptr)
break;
p = p->mNext;
aIndex--;
}

lReturn = static_cast<T *>(p);
}
#else
if (aIndex < N)
lReturn = &reinterpret_cast<T *>(mArena.uMemory)[aIndex];
#endif

(void) static_cast<Object *>(lReturn); /* In C++-11, this would be a static_assert that T inherits Object. */

return (lReturn != nullptr) && lReturn->IsRetained(aLayer) ? lReturn : nullptr;
}

/**
* @brief
* Tries to initially retain the first object in the pool that is not retained by any layer.
Expand Down
2 changes: 1 addition & 1 deletion src/system/WatchableEventManagerLwIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ CHIP_ERROR WatchableEventManager::HandlePlatformTimer()
// The platform timer API has MSEC resolution so expire any timer with less than 1 msec remaining.
size_t timersHandled = 0;
Timer * timer = nullptr;
while ((timersHandled < Timer::sPool.Size()) && ((timer = mTimerList.PopIfEarlier(currentTime + 1)) != nullptr))
while ((timersHandled < CHIP_SYSTEM_CONFIG_NUM_TIMERS) && ((timer = mTimerList.PopIfEarlier(currentTime + 1)) != nullptr))
{
mHandlingTimerComplete = true;
timer->HandleComplete();
Expand Down
Loading

0 comments on commit 3319217

Please sign in to comment.