Skip to content

Commit

Permalink
[core] Added missing SRT_ATTR_GUARDED_BY(m_GlobControlLock).
Browse files Browse the repository at this point in the history
Removed unused m_MultiplexerLock.
  • Loading branch information
maxsharabayko committed Jul 10, 2024
1 parent 54c002f commit 84d18ec
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
5 changes: 1 addition & 4 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ srt::CUDTUnited::CUDTUnited()
, m_GlobControlLock()
, m_IDLock()
, m_mMultiplexer()
, m_MultiplexerLock()
, m_pCache(NULL)
, m_pCache(new CCache<CInfoBlock>)
, m_bClosing(false)
, m_GCStopCond()
, m_InitLock()
Expand All @@ -195,8 +194,6 @@ srt::CUDTUnited::CUDTUnited()
setupMutex(m_GlobControlLock, "GlobControl");
setupMutex(m_IDLock, "ID");
setupMutex(m_InitLock, "Init");

m_pCache = new CCache<CInfoBlock>;
}

srt::CUDTUnited::~CUDTUnited()
Expand Down
20 changes: 15 additions & 5 deletions srtcore/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,13 @@ class CUDTUnited

private:
typedef std::map<SRTSOCKET, CUDTSocket*> sockets_t; // stores all the socket structures
sockets_t m_Sockets;
SRT_ATTR_GUARDED_BY(m_GlobControlLock)
sockets_t m_Sockets;

#if ENABLE_BONDING
typedef std::map<SRTSOCKET, CUDTGroup*> groups_t;
groups_t m_Groups;
SRT_ATTR_GUARDED_BY(m_GlobControlLock)
groups_t m_Groups;
#endif

sync::Mutex m_GlobControlLock; // used to synchronize UDT API
Expand All @@ -399,6 +401,7 @@ class CUDTUnited
SRTSOCKET m_SocketIDGenerator; // seed to generate a new unique socket ID
SRTSOCKET m_SocketIDGenerator_init; // Keeps track of the very first one

SRT_ATTR_GUARDED_BY(m_GlobControlLock)
std::map<int64_t, std::set<SRTSOCKET> >
m_PeerRec; // record sockets from peers to avoid repeated connection request, int64_t = (socker_id << 30) + isn

Expand Down Expand Up @@ -460,26 +463,33 @@ class CUDTUnited
const sockaddr_any& reqaddr, const CSrtMuxerConfig& cfgSocket);

private:
SRT_ATTR_GUARDED_BY(m_GlobControlLock)
std::map<int, CMultiplexer> m_mMultiplexer; // UDP multiplexer
sync::Mutex m_MultiplexerLock;

private:
CCache<CInfoBlock>* m_pCache; // UDT network information cache
/// UDT network information cache.
/// Existence is guarded by m_GlobControlLock, but the cache itself is thread-safe.
SRT_ATTR_GUARDED_BY(m_GlobControlLock)
CCache<CInfoBlock>* const m_pCache;

private:
srt::sync::atomic<bool> m_bClosing;
sync::Mutex m_GCStopLock;
sync::Condition m_GCStopCond;

sync::Mutex m_InitLock;
SRT_ATTR_GUARDED_BY(m_InitLock)
int m_iInstanceCount; // number of startup() called by application
SRT_ATTR_GUARDED_BY(m_InitLock)
bool m_bGCStatus; // if the GC thread is working (true)

SRT_ATTR_GUARDED_BY(m_InitLock)
sync::CThread m_GCThread;
static void* garbageCollect(void*);

SRT_ATTR_GUARDED_BY(m_GlobControlLock)
sockets_t m_ClosedSockets; // temporarily store closed sockets
#if ENABLE_BONDING
SRT_ATTR_GUARDED_BY(m_GlobControlLock)
groups_t m_ClosedGroups;
#endif

Expand Down
10 changes: 6 additions & 4 deletions srtcore/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,20 @@ template<typename T> class CCache
return 0;
}

/// Specify the cache size (i.e., max number of items).
/// @param [in] size max cache size.
private:

/// Specify the cache size (i.e., max number of items).
/// Private or else must be protected by a lock.
/// @param [in] size max cache size.
void setSizeLimit(int size)
{
m_iMaxSize = size;
m_iHashSize = size * 3;
m_vHashPtr.resize(m_iHashSize);
}

/// Clear all entries in the cache, restore to initialization state.

/// Clear all entries in the cache, restore to initialization state.
/// Private or else must be protected by a lock.
void clear()
{
for (typename std::list<T*>::iterator i = m_StorageList.begin(); i != m_StorageList.end(); ++ i)
Expand Down
2 changes: 1 addition & 1 deletion srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11946,7 +11946,7 @@ void srt::CUDT::processKeepalive(const CPacket& ctrlpkt, const time_point& tsArr
if (m_parent->m_GroupOf)
{
// Lock GlobControlLock in order to make sure that
// the state if the socket having the group and the
// the state of the socket having the group and the
// existence of the group will not be changed during
// the operation. The attempt of group deletion will
// have to wait until this operation completes.
Expand Down
2 changes: 1 addition & 1 deletion srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3199,7 +3199,7 @@ void CUDTGroup::send_CloseBrokenSockets(vector<SRTSOCKET>& w_wipeme)
InvertedLock ug(m_GroupLock);

// With unlocked GroupLock, we can now lock GlobControlLock.
// This is needed prevent any of them be deleted from the container
// This is needed to prevent any of them deleted from the container
// at the same time.
ScopedLock globlock(CUDT::uglobal().m_GlobControlLock);

Expand Down

0 comments on commit 84d18ec

Please sign in to comment.