scripted-diff: threading: semaphore: use direct types rather than the temporary convenience ones
-BEGIN VERIFY SCRIPT- sed -i 's|BinarySemaphore|std::binary_semaphore|g' src/wallet/sqlite.h sed -i 's|SemaphoreGrant|CountingGrant|g' src/net.h src/net.cpp sed -i 's|Semaphore|std::counting_semaphore<>|g' src/net.h src/net.cpp sed -i 's|CountingGrant|CountingSemaphoreGrant<>|g' src/net.h src/net.cpp -END VERIFY SCRIPT-
This commit is contained in:
1 parent
f21365c4fc
commit
1f89e2a49a
3 files changed
+14
-14
No files matched your search
+8
-8
@@ -1893,7 +1893,7 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ
|
|||||||
if (max_connections != std::nullopt && existing_connections >= max_connections) return false;
|
if (max_connections != std::nullopt && existing_connections >= max_connections) return false;
|
||||||
|
|
||||||
// Max total outbound connections already exist
|
// Max total outbound connections already exist
|
||||||
SemaphoreGrant grant(*semOutbound, true);
|
CountingSemaphoreGrant<> grant(*semOutbound, true);
|
||||||
if (!grant) return false;
|
if (!grant) return false;
|
||||||
|
|
||||||
OpenNetworkConnection(CAddress(), false, std::move(grant), address.c_str(), conn_type, /*use_v2transport=*/use_v2transport);
|
OpenNetworkConnection(CAddress(), false, std::move(grant), address.c_str(), conn_type, /*use_v2transport=*/use_v2transport);
|
||||||
@@ -2409,7 +2409,7 @@ void CConnman::ProcessAddrFetch()
|
|||||||
// peer doesn't support it or immediately disconnects us for another reason.
|
// peer doesn't support it or immediately disconnects us for another reason.
|
||||||
const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
|
const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
|
||||||
CAddress addr;
|
CAddress addr;
|
||||||
SemaphoreGrant grant(*semOutbound, /*fTry=*/true);
|
CountingSemaphoreGrant<> grant(*semOutbound, /*fTry=*/true);
|
||||||
if (grant) {
|
if (grant) {
|
||||||
OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport);
|
OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport);
|
||||||
}
|
}
|
||||||
@@ -2583,7 +2583,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
|
|||||||
|
|
||||||
PerformReconnections();
|
PerformReconnections();
|
||||||
|
|
||||||
SemaphoreGrant grant(*semOutbound);
|
CountingSemaphoreGrant<> grant(*semOutbound);
|
||||||
if (interruptNet)
|
if (interruptNet)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -2961,7 +2961,7 @@ void CConnman::ThreadOpenAddedConnections()
|
|||||||
AssertLockNotHeld(m_reconnections_mutex);
|
AssertLockNotHeld(m_reconnections_mutex);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
SemaphoreGrant grant(*semAddnode);
|
CountingSemaphoreGrant<> grant(*semAddnode);
|
||||||
std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(/*include_connected=*/false);
|
std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(/*include_connected=*/false);
|
||||||
bool tried = false;
|
bool tried = false;
|
||||||
for (const AddedNodeInfo& info : vInfo) {
|
for (const AddedNodeInfo& info : vInfo) {
|
||||||
@@ -2974,7 +2974,7 @@ void CConnman::ThreadOpenAddedConnections()
|
|||||||
CAddress addr(CService(), NODE_NONE);
|
CAddress addr(CService(), NODE_NONE);
|
||||||
OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
|
OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
|
||||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return;
|
if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return;
|
||||||
grant = SemaphoreGrant(*semAddnode, /*fTry=*/true);
|
grant = CountingSemaphoreGrant<>(*semAddnode, /*fTry=*/true);
|
||||||
}
|
}
|
||||||
// See if any reconnections are desired.
|
// See if any reconnections are desired.
|
||||||
PerformReconnections();
|
PerformReconnections();
|
||||||
@@ -2985,7 +2985,7 @@ void CConnman::ThreadOpenAddedConnections()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if successful, this moves the passed grant to the constructed node
|
// if successful, this moves the passed grant to the constructed node
|
||||||
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, SemaphoreGrant&& grant_outbound, const char *pszDest, ConnectionType conn_type, bool use_v2transport)
|
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CountingSemaphoreGrant<>&& grant_outbound, const char *pszDest, ConnectionType conn_type, bool use_v2transport)
|
||||||
{
|
{
|
||||||
AssertLockNotHeld(m_unused_i2p_sessions_mutex);
|
AssertLockNotHeld(m_unused_i2p_sessions_mutex);
|
||||||
assert(conn_type != ConnectionType::INBOUND);
|
assert(conn_type != ConnectionType::INBOUND);
|
||||||
@@ -3336,11 +3336,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
|||||||
|
|
||||||
if (semOutbound == nullptr) {
|
if (semOutbound == nullptr) {
|
||||||
// initialize semaphore
|
// initialize semaphore
|
||||||
semOutbound = std::make_unique<Semaphore>(std::min(m_max_automatic_outbound, m_max_automatic_connections));
|
semOutbound = std::make_unique<std::counting_semaphore<>>(std::min(m_max_automatic_outbound, m_max_automatic_connections));
|
||||||
}
|
}
|
||||||
if (semAddnode == nullptr) {
|
if (semAddnode == nullptr) {
|
||||||
// initialize semaphore
|
// initialize semaphore
|
||||||
semAddnode = std::make_unique<Semaphore>(m_max_addnode);
|
semAddnode = std::make_unique<std::counting_semaphore<>>(m_max_addnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -729,7 +729,7 @@ public:
|
|||||||
// Setting fDisconnect to true will cause the node to be disconnected the
|
// Setting fDisconnect to true will cause the node to be disconnected the
|
||||||
// next time DisconnectNodes() runs
|
// next time DisconnectNodes() runs
|
||||||
std::atomic_bool fDisconnect{false};
|
std::atomic_bool fDisconnect{false};
|
||||||
SemaphoreGrant grantOutbound;
|
CountingSemaphoreGrant<> grantOutbound;
|
||||||
std::atomic<int> nRefCount{0};
|
std::atomic<int> nRefCount{0};
|
||||||
|
|
||||||
const uint64_t nKeyedNetGroup;
|
const uint64_t nKeyedNetGroup;
|
||||||
@@ -1136,7 +1136,7 @@ public:
|
|||||||
bool GetNetworkActive() const { return fNetworkActive; };
|
bool GetNetworkActive() const { return fNetworkActive; };
|
||||||
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
|
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
|
||||||
void SetNetworkActive(bool active);
|
void SetNetworkActive(bool active);
|
||||||
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, SemaphoreGrant&& grant_outbound, const char* strDest, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
|
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CountingSemaphoreGrant<>&& grant_outbound, const char* strDest, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
|
||||||
bool CheckIncomingNonce(uint64_t nonce);
|
bool CheckIncomingNonce(uint64_t nonce);
|
||||||
void ASMapHealthCheck();
|
void ASMapHealthCheck();
|
||||||
|
|
||||||
@@ -1491,8 +1491,8 @@ private:
|
|||||||
*/
|
*/
|
||||||
std::atomic<ServiceFlags> m_local_services;
|
std::atomic<ServiceFlags> m_local_services;
|
||||||
|
|
||||||
std::unique_ptr<Semaphore> semOutbound;
|
std::unique_ptr<std::counting_semaphore<>> semOutbound;
|
||||||
std::unique_ptr<Semaphore> semAddnode;
|
std::unique_ptr<std::counting_semaphore<>> semAddnode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of automatic connections permitted, excluding manual
|
* Maximum number of automatic connections permitted, excluding manual
|
||||||
@@ -1614,7 +1614,7 @@ private:
|
|||||||
struct ReconnectionInfo
|
struct ReconnectionInfo
|
||||||
{
|
{
|
||||||
CAddress addr_connect;
|
CAddress addr_connect;
|
||||||
SemaphoreGrant grant;
|
CountingSemaphoreGrant<> grant;
|
||||||
std::string destination;
|
std::string destination;
|
||||||
ConnectionType conn_type;
|
ConnectionType conn_type;
|
||||||
bool use_v2transport;
|
bool use_v2transport;
|
||||||
|
|||||||
+1
-1
@@ -127,7 +127,7 @@ public:
|
|||||||
|
|
||||||
// Batches must acquire this semaphore on writing, and release when done writing.
|
// Batches must acquire this semaphore on writing, and release when done writing.
|
||||||
// This ensures that only one batch is modifying the database at a time.
|
// This ensures that only one batch is modifying the database at a time.
|
||||||
BinarySemaphore m_write_semaphore;
|
std::binary_semaphore m_write_semaphore;
|
||||||
|
|
||||||
bool Verify(bilingual_str& error);
|
bool Verify(bilingual_str& error);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user