From dbf5965244c978b30484fffaf5c6b8845fcdbb22 Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Tue, 30 Jul 2024 09:52:49 +0200 Subject: [PATCH] [core] Added some SRT_ATTR_EXCLUDES to CUDT (#2979). --- srtcore/core.h | 9 ++++++++- srtcore/srt_attr_defs.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/srtcore/core.h b/srtcore/core.h index 3935b99d3..3d5314281 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -773,6 +773,7 @@ class CUDT /// @param seqno [in] The sequence number of the first packets following those to be dropped. /// @param reason A reason for dropping (see @a DropReason). /// @return The number of packets dropped. + SRT_ATTR_EXCLUDES(m_RcvBufferLock, m_RcvLossLock) int rcvDropTooLateUpTo(int seqno, DropReason reason = DROP_TOO_LATE); static loss_seqs_t defaultPacketArrival(void* vself, CPacket& pkt); @@ -962,6 +963,7 @@ class CUDT bool frequentLogAllowed(size_t logid, const time_point& tnow, std::string& why); private: // Receiving related data + SRT_ATTR_GUARDED_BY(m_RcvBufferLock) CRcvBuffer* m_pRcvBuffer; //< Receiver buffer SRT_ATTR_GUARDED_BY(m_RcvLossLock) CRcvLossList* m_pRcvLossList; //< Receiver loss list @@ -992,6 +994,7 @@ class CUDT bool m_bTsbPd; // Peer sends TimeStamp-Based Packet Delivery Packets bool m_bGroupTsbPd; // TSBPD should be used for GROUP RECEIVER instead + SRT_ATTR_GUARDED_BY(m_RcvTsbPdStartupLock) sync::CThread m_RcvTsbPdThread; // Rcv TsbPD Thread handle sync::Condition m_RcvTsbPdCond; // TSBPD signals if reading is ready. Use together with m_RecvLock bool m_bTsbPdNeedsWakeup; // Signal TsbPd thread to wake up on RCV buffer state change. @@ -1126,6 +1129,8 @@ class CUDT /// @retval false Nothing was extracted for sending, @a nexttime should be ignored bool packData(CPacket& packet, time_point& nexttime, sockaddr_any& src_addr); + /// Also excludes srt::CUDTUnited::m_GlobControlLock. + SRT_ATTR_EXCLUDES(m_RcvTsbPdStartupLock, m_StatsLock, m_RecvLock, m_RcvLossLock, m_RcvBufferLock) int processData(CUnit* unit); /// This function passes the incoming packet to the initial processing @@ -1149,8 +1154,10 @@ class CUDT /// and shall not be used when ENABLE_BONDING=0. time_point getPktTsbPdTime(void* grp, const CPacket& packet); + SRT_ATTR_EXCLUDES(m_RcvTsbPdStartupLock) /// Checks and spawns the TSBPD thread if required. int checkLazySpawnTsbPdThread(); + void processClose(); /// Process the request after receiving the handshake from caller. @@ -1167,9 +1174,9 @@ class CUDT void processKeepalive(const CPacket& ctrlpkt, const time_point& tsArrival); + SRT_ATTR_REQUIRES(m_RcvBufferLock) /// Retrieves the available size of the receiver buffer. /// Expects that m_RcvBufferLock is locked. - SRT_ATTR_REQUIRES(m_RcvBufferLock) size_t getAvailRcvBufferSizeNoLock() const; private: // Trace diff --git a/srtcore/srt_attr_defs.h b/srtcore/srt_attr_defs.h index 85ea9f96d..726c4a03b 100644 --- a/srtcore/srt_attr_defs.h +++ b/srtcore/srt_attr_defs.h @@ -118,7 +118,7 @@ used by SRT library internally. #define SRT_ATTR_RELEASE_GENERIC(...) #define SRT_ATTR_TRY_ACQUIRE(...) _Acquires_nonreentrant_lock_(expr) #define SRT_ATTR_TRY_ACQUIRE_SHARED(...) -#define SRT_ATTR_EXCLUDES(...) +#define SRT_ATTR_EXCLUDES(...) // the caller must not hold the given capabilities #define SRT_ATTR_ASSERT_CAPABILITY(expr) #define SRT_ATTR_ASSERT_SHARED_CAPABILITY(x) #define SRT_ATTR_RETURN_CAPABILITY(x) @@ -179,6 +179,7 @@ used by SRT library internally. #define SRT_ATTR_TRY_ACQUIRE_SHARED(...) \ THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__)) +// The caller must not hold the given capabilities. #define SRT_ATTR_EXCLUDES(...) \ THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))