diff --git a/src/leveldb/port/port_win.cc b/src/leveldb/port/port_win.cc index 5b0f0e624b2f3..26e680385c88e 100755 --- a/src/leveldb/port/port_win.cc +++ b/src/leveldb/port/port_win.cc @@ -70,8 +70,8 @@ void Mutex::AssertHeld() { CondVar::CondVar(Mutex* mu) : waiting_(0), mu_(mu), - sem1_(::CreateSemahelix(NULL, 0, 10000, NULL)), - sem2_(::CreateSemahelix(NULL, 0, 10000, NULL)) { + sem1_(::CreateSemaphore(NULL, 0, 10000, NULL)), + sem2_(::CreateSemaphore(NULL, 0, 10000, NULL)) { assert(mu_); } @@ -91,7 +91,7 @@ void CondVar::Wait() { // initiate handshake ::WaitForSingleObject(sem1_, INFINITE); - ::ReleaseSemahelix(sem2_, 1, NULL); + ::ReleaseSemaphore(sem2_, 1, NULL); mu_->Lock(); } @@ -101,7 +101,7 @@ void CondVar::Signal() { --waiting_; // finalize handshake - ::ReleaseSemahelix(sem1_, 1, NULL); + ::ReleaseSemaphore(sem1_, 1, NULL); ::WaitForSingleObject(sem2_, INFINITE); } wait_mtx_.Unlock(); @@ -109,7 +109,7 @@ void CondVar::Signal() { void CondVar::SignalAll() { wait_mtx_.Lock(); - ::ReleaseSemahelix(sem1_, waiting_, NULL); + ::ReleaseSemaphore(sem1_, waiting_, NULL); while(waiting_ > 0) { --waiting_; ::WaitForSingleObject(sem2_, INFINITE); diff --git a/src/leveldb/port/port_win.h b/src/leveldb/port/port_win.h index aed8b09f2e69e..45bf2f0ea749d 100755 --- a/src/leveldb/port/port_win.h +++ b/src/leveldb/port/port_win.h @@ -74,7 +74,7 @@ class Mutex { // the Win32 API offers a dependable condition variable mechanism, but only starting with // Windows 2008 and Vista -// no matter what we will implement our own condition variable with a semahelix +// no matter what we will implement our own condition variable with a semaphore // implementation as described in a paper written by Andrew D. Birrell in 2003 class CondVar { public: diff --git a/src/net.cpp b/src/net.cpp index cff80fbdc4091..d3e18c630f378 100755 --- a/src/net.cpp +++ b/src/net.cpp @@ -112,7 +112,7 @@ CCriticalSection cs_vAddedNodes; NodeId nLastNodeId = 0; CCriticalSection cs_nLastNodeId; -static CSemahelix* semOutbound = NULL; +static CSemaphore* semOutbound = NULL; boost::condition_variable messageHandlerCondition; // Signals for message handling @@ -1302,7 +1302,7 @@ void static ProcessOneShot() vOneShots.pop_front(); } CAddress addr; - CSemahelixGrant grant(*semOutbound, true); + CSemaphoreGrant grant(*semOutbound, true); if (grant) { if (!OpenNetworkConnection(addr, &grant, strDest.c_str(), true)) AddOneShot(strDest); @@ -1333,7 +1333,7 @@ void ThreadOpenConnections() MilliSleep(500); - CSemahelixGrant grant(*semOutbound); + CSemaphoreGrant grant(*semOutbound); boost::this_thread::interruption_point(); // Add seed nodes if DNS seeds are all down (an infrastructure attack?). @@ -1427,7 +1427,7 @@ void ThreadOpenAddedConnections() } for (string& strAddNode : lAddresses) { CAddress addr; - CSemahelixGrant grant(*semOutbound); + CSemaphoreGrant grant(*semOutbound); OpenNetworkConnection(addr, &grant, strAddNode.c_str()); MilliSleep(500); } @@ -1469,7 +1469,7 @@ void ThreadOpenAddedConnections() } } for (vector& vserv : lservAddressesToAdd) { - CSemahelixGrant grant(*semOutbound); + CSemaphoreGrant grant(*semOutbound); OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant); MilliSleep(500); } @@ -1478,7 +1478,7 @@ void ThreadOpenAddedConnections() } // if successful, this moves the passed grant to the constructed node -bool OpenNetworkConnection(const CAddress& addrConnect, CSemahelixGrant* grantOutbound, const char* pszDest, bool fOneShot) +bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant* grantOutbound, const char* pszDest, bool fOneShot) { // // Initiate outbound network connection @@ -1728,9 +1728,9 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) fAddressesInitialized = true; if (semOutbound == NULL) { - // initialize semahelix + // initialize semaphore int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections); - semOutbound = new CSemahelix(nMaxOutbound); + semOutbound = new CSemaphore(nMaxOutbound); } if (pnodeLocalHost == NULL) diff --git a/src/net.h b/src/net.h index 7643c3797d19a..5fc8d334e1a29 100755 --- a/src/net.h +++ b/src/net.h @@ -69,7 +69,7 @@ CNode* FindNode(const CSubNet& subNet); CNode* FindNode(const std::string& addrName); CNode* FindNode(const CService& ip); CNode* ConnectNode(CAddress addrConnect, const char* pszDest = NULL, bool obfuScationMaster = false); -bool OpenNetworkConnection(const CAddress& addrConnect, CSemahelixGrant* grantOutbound = NULL, const char* strDest = NULL, bool fOneShot = false); +bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant* grantOutbound = NULL, const char* strDest = NULL, bool fOneShot = false); void MapPort(bool fUseUPnP); unsigned short GetListenPort(); bool BindListenPort(const CService& bindAddr, std::string& strError, bool fWhitelisted = false); @@ -325,7 +325,7 @@ class CNode // (even if it's relative to mixing e.g. for blinding) should NOT set this to 'true'. // For such cases node should be released manually (preferably right after corresponding code). bool fObfuScationMaster; - CSemahelixGrant grantOutbound; + CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; CBloomFilter* pfilter; int nRefCount; diff --git a/src/sync.h b/src/sync.h index 3d470a8852d36..e3a3c109720f8 100755 --- a/src/sync.h +++ b/src/sync.h @@ -212,7 +212,7 @@ typedef CMutexLock CCriticalBlock; LeaveCritical(); \ } -class CSemahelix +class CSemaphore { private: boost::condition_variable condition; @@ -220,7 +220,7 @@ class CSemahelix int value; public: - CSemahelix(int init) : value(init) {} + CSemaphore(int init) : value(init) {} void wait() { @@ -250,11 +250,11 @@ class CSemahelix } }; -/** RAII-style semahelix lock */ -class CSemahelixGrant +/** RAII-style semaphore lock */ +class CSemaphoreGrant { private: - CSemahelix* sem; + CSemaphore* sem; bool fHaveGrant; public: @@ -281,7 +281,7 @@ class CSemahelixGrant return fHaveGrant; } - void MoveTo(CSemahelixGrant& grant) + void MoveTo(CSemaphoreGrant& grant) { grant.Release(); grant.sem = sem; @@ -290,9 +290,9 @@ class CSemahelixGrant fHaveGrant = false; } - CSemahelixGrant() : sem(NULL), fHaveGrant(false) {} + CSemaphoreGrant() : sem(NULL), fHaveGrant(false) {} - CSemahelixGrant(CSemahelix& sema, bool fTry = false) : sem(&sema), fHaveGrant(false) + CSemaphoreGrant(CSemaphore& sema, bool fTry = false) : sem(&sema), fHaveGrant(false) { if (fTry) TryAcquire(); @@ -300,7 +300,7 @@ class CSemahelixGrant Acquire(); } - ~CSemahelixGrant() + ~CSemaphoreGrant() { Release(); }