mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-09 09:42:15 +02:00
scripted-diff: rename CSemaphore and CSemaphoreGrant
CountingSemaphore and CountingSemaphoreGrant model std::counting_semaphore. -BEGIN VERIFY SCRIPT- sed -i -e 's|CSemaphoreGrant|CountingSemaphoreGrant|g' -e 's|CSemaphore|CountingSemaphore|g' src/sync.h -END VERIFY SCRIPT-
This commit is contained in:
40
src/sync.h
40
src/sync.h
@@ -304,7 +304,7 @@ inline MutexType* MaybeCheckNotHeld(MutexType* m) LOCKS_EXCLUDED(m) LOCK_RETURNE
|
|||||||
*
|
*
|
||||||
* See https://en.wikipedia.org/wiki/Semaphore_(programming)
|
* See https://en.wikipedia.org/wiki/Semaphore_(programming)
|
||||||
*/
|
*/
|
||||||
class CSemaphore
|
class CountingSemaphore
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::condition_variable condition;
|
std::condition_variable condition;
|
||||||
@@ -312,14 +312,14 @@ private:
|
|||||||
int value;
|
int value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CSemaphore(int init) noexcept : value(init) {}
|
explicit CountingSemaphore(int init) noexcept : value(init) {}
|
||||||
|
|
||||||
// Disallow default construct, copy, move.
|
// Disallow default construct, copy, move.
|
||||||
CSemaphore() = delete;
|
CountingSemaphore() = delete;
|
||||||
CSemaphore(const CSemaphore&) = delete;
|
CountingSemaphore(const CountingSemaphore&) = delete;
|
||||||
CSemaphore(CSemaphore&&) = delete;
|
CountingSemaphore(CountingSemaphore&&) = delete;
|
||||||
CSemaphore& operator=(const CSemaphore&) = delete;
|
CountingSemaphore& operator=(const CountingSemaphore&) = delete;
|
||||||
CSemaphore& operator=(CSemaphore&&) = delete;
|
CountingSemaphore& operator=(CountingSemaphore&&) = delete;
|
||||||
|
|
||||||
void acquire() noexcept
|
void acquire() noexcept
|
||||||
{
|
{
|
||||||
@@ -348,14 +348,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using BinarySemaphore = CSemaphore;
|
using BinarySemaphore = CountingSemaphore;
|
||||||
using Semaphore = CSemaphore;
|
using Semaphore = CountingSemaphore;
|
||||||
|
|
||||||
/** RAII-style semaphore lock */
|
/** RAII-style semaphore lock */
|
||||||
class CSemaphoreGrant
|
class CountingSemaphoreGrant
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CSemaphore* sem;
|
CountingSemaphore* sem;
|
||||||
bool fHaveGrant;
|
bool fHaveGrant;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -386,11 +386,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Disallow copy.
|
// Disallow copy.
|
||||||
CSemaphoreGrant(const CSemaphoreGrant&) = delete;
|
CountingSemaphoreGrant(const CountingSemaphoreGrant&) = delete;
|
||||||
CSemaphoreGrant& operator=(const CSemaphoreGrant&) = delete;
|
CountingSemaphoreGrant& operator=(const CountingSemaphoreGrant&) = delete;
|
||||||
|
|
||||||
// Allow move.
|
// Allow move.
|
||||||
CSemaphoreGrant(CSemaphoreGrant&& other) noexcept
|
CountingSemaphoreGrant(CountingSemaphoreGrant&& other) noexcept
|
||||||
{
|
{
|
||||||
sem = other.sem;
|
sem = other.sem;
|
||||||
fHaveGrant = other.fHaveGrant;
|
fHaveGrant = other.fHaveGrant;
|
||||||
@@ -398,7 +398,7 @@ public:
|
|||||||
other.sem = nullptr;
|
other.sem = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSemaphoreGrant& operator=(CSemaphoreGrant&& other) noexcept
|
CountingSemaphoreGrant& operator=(CountingSemaphoreGrant&& other) noexcept
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
sem = other.sem;
|
sem = other.sem;
|
||||||
@@ -408,9 +408,9 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSemaphoreGrant() noexcept : sem(nullptr), fHaveGrant(false) {}
|
CountingSemaphoreGrant() noexcept : sem(nullptr), fHaveGrant(false) {}
|
||||||
|
|
||||||
explicit CSemaphoreGrant(CSemaphore& sema, bool fTry = false) noexcept : sem(&sema), fHaveGrant(false)
|
explicit CountingSemaphoreGrant(CountingSemaphore& sema, bool fTry = false) noexcept : sem(&sema), fHaveGrant(false)
|
||||||
{
|
{
|
||||||
if (fTry) {
|
if (fTry) {
|
||||||
TryAcquire();
|
TryAcquire();
|
||||||
@@ -419,7 +419,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~CSemaphoreGrant()
|
~CountingSemaphoreGrant()
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
@@ -430,7 +430,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using BinarySemaphoreGrant = CSemaphoreGrant;
|
using BinarySemaphoreGrant = CountingSemaphoreGrant;
|
||||||
using SemaphoreGrant = CSemaphoreGrant;
|
using SemaphoreGrant = CountingSemaphoreGrant;
|
||||||
|
|
||||||
#endif // BITCOIN_SYNC_H
|
#endif // BITCOIN_SYNC_H
|
||||||
|
Reference in New Issue
Block a user