-
Notifications
You must be signed in to change notification settings - Fork 37.8k
p2p: Replace RecursiveMutex cs_totalBytesSent
with Mutex and rename it
#24157
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
Conversation
756e882
to
6cb0fab
Compare
45e2f9b
to
378facf
Compare
378facf
to
6a3eeda
Compare
Addressed @hebasto suggestion. All functions changed in the second commit use The only exception is Not sure about the reason for this error. net.cpp:1655:29: error: calling function 'RecordBytesSent' requires negative capability '!m_total_bytes_sent_mutex' [-Werror,-Wthread-safety-analysis]
if (bytes_sent) RecordBytesSent(bytes_sent);
^
net.cpp:3077:21: error: calling function 'RecordBytesSent' requires negative capability '!m_total_bytes_sent_mutex' [-Werror,-Wthread-safety-analysis]
if (nBytesSent) RecordBytesSent(nBytesSent);
|
Maybe: --- a/src/net.h
+++ b/src/net.h
@@ -829,7 +829,8 @@ public:
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
- void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
+ void PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
using NodeFn = std::function<void(CNode*)>;
void ForEachNode(const NodeFn& func)
@@ -1024,7 +1025,8 @@ private:
/**
* Check connected and listening sockets for IO readiness and process them accordingly.
*/
- void SocketHandler();
+ void SocketHandler()
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
/**
* Do the read/write for connected sockets that are ready for IO.
@@ -1037,7 +1039,8 @@ private:
void SocketHandlerConnected(const std::vector<CNode*>& nodes,
const std::set<SOCKET>& recv_set,
const std::set<SOCKET>& send_set,
- const std::set<SOCKET>& error_set);
+ const std::set<SOCKET>& error_set)
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
/**
* Accept incoming connections, one from each read-ready listening socket.
@@ -1045,7 +1048,8 @@ private:
*/
void SocketHandlerListening(const std::set<SOCKET>& recv_set);
- void ThreadSocketHandler();
+ void ThreadSocketHandler()
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
void ThreadDNSAddressSeed();
uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
@@ -1074,7 +1078,8 @@ private:
// Network stats
void RecordBytesRecv(uint64_t bytes);
- void RecordBytesSent(uint64_t bytes) LOCKS_EXCLUDED(m_total_bytes_sent_mutex);
+ void RecordBytesSent(uint64_t bytes)
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
/**
* Return vector of current BLOCK_RELAY peers. ? |
6a3eeda
to
ebf1f2c
Compare
@hebasto Thanks. This worked. Very interesting. So, using |
That is why negative capabilities provide a stronger safety guarantee. I don't see any reason of splitting changes between second and third commits. Maybe squash them? |
ebf1f2c
to
0b6c5da
Compare
Sure. Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 0b6c5da
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
0b6c5da
to
f04ffdd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK f04ffdd
f04ffdd
to
eef2c7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK eef2c7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK eef2c7b, only suggested changes since my previous review.
UPDATE: ACK retracted. See #24157 (comment)
Is any further action needed in this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think there's a missing annotation, but otherwise looks good.
ACK modulo the missing annotation Verified the methods updated here have both an annotation in the declaration and a corresponding assertion in the definition:
|
-BEGIN VERIFY SCRIPT- sed -i 's/cs_totalBytesSent/m_total_bytes_sent_mutex/g' -- $(git grep --files-with-matches 'cs_totalBytesSent') -END VERIFY SCRIPT-
eef2c7b
to
eff7918
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK eff7918
Compiles with clang 15.
…nt_mutex` Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
eff7918
to
709af67
Compare
Added the suggestion #24157 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 709af67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 709af67, tested on Ubuntu 22.04.
ACK 709af67 per |
Related to #19303, this PR gets rid of the RecursiveMutex
cs_totalBytesSent
and also addsAssertLockNotHeld
macros combined withLOCKS_EXCLUDED
thread safety annotations to avoid recursive locking.