Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refax: added size cache to the group container #2510

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,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