Skip to content

Commit

Permalink
[core] Refax: added size cache to the group container (#2510).
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Nov 7, 2022
1 parent 2fd1363 commit 258a858
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ void CUDTGroup::GroupContainer::erase(CUDTGroup::gli_t it)
}
}
m_List.erase(it);
--m_SizeCache;
}

void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
Expand Down
14 changes: 10 additions & 4 deletions srtcore/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,21 @@ class CUDTGroup
SRTSOCKET m_PeerGroupID;
struct GroupContainer
{
std::list<SocketData> m_List;
private:
std::list<SocketData> m_List;
sync::atomic<size_t> m_SizeCache;

/// This field is used only by some types of groups that need
/// to keep track as to which link was lately used. Note that
/// by removal of a node from the m_List container, this link
/// must be appropriately reset.
gli_t m_LastActiveLink;

public:

GroupContainer()
: m_LastActiveLink(m_List.end())
: m_SizeCache(0)
, m_LastActiveLink(m_List.end())
{
}

Expand All @@ -425,13 +430,14 @@ class CUDTGroup
gli_t begin() { return m_List.begin(); }
gli_t end() { return m_List.end(); }
bool empty() { return m_List.empty(); }
void push_back(const SocketData& data) { m_List.push_back(data); }
void push_back(const SocketData& data) { m_List.push_back(data); ++m_SizeCache; }
void clear()
{
m_LastActiveLink = end();
m_List.clear();
m_SizeCache = 0;
}
size_t size() { return m_List.size(); }
size_t size() { return m_SizeCache; }

void erase(gli_t it);
};
Expand Down

0 comments on commit 258a858

Please sign in to comment.