Skip to content

Commit 8e52fde

Browse files
committed
Delete instead of hide copy constructor/assignment in semaphore
+ some const/constexpr
1 parent 8f46cfe commit 8e52fde

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/common/classes/semaphore.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ namespace Firebird {
8080
system_call_failed::raise("CloseHandle");
8181
}
8282

83-
bool Semaphore::tryEnter(const int seconds , int milliseconds)
83+
bool Semaphore::tryEnter(const int seconds, int milliseconds)
8484
{
8585
milliseconds += seconds * 1000;
86-
DWORD result = WaitForSingleObject(hSemaphore, milliseconds >= 0 ? milliseconds : INFINITE);
86+
const DWORD result = WaitForSingleObject(hSemaphore, milliseconds >= 0 ? milliseconds : INFINITE);
8787
if (result == WAIT_FAILED)
8888
system_call_failed::raise("WaitForSingleObject");
8989
return result != WAIT_TIMEOUT;
@@ -119,7 +119,7 @@ namespace Firebird {
119119
#ifdef COMMON_CLASSES_SEMAPHORE_POSIX_RT
120120

121121
#ifndef WORKING_SEM_INIT
122-
static const char* semName = "/firebird_temp_sem";
122+
static constexpr const char* semName = "/firebird_temp_sem";
123123
#endif
124124

125125
#ifndef SEM_FAILED

src/common/classes/semaphore.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ class Semaphore
5353
HANDLE hSemaphore;
5454
void init();
5555

56-
// Forbid copying (there is no definition of these methods)
57-
Semaphore(const Semaphore&);
58-
Semaphore& operator=(const Semaphore&);
59-
6056
public:
6157
Semaphore() { init(); }
6258
explicit Semaphore(MemoryPool&) { init(); }
6359

6460
~Semaphore();
6561

62+
// Forbid copying
63+
Semaphore(const Semaphore&) = delete;
64+
Semaphore& operator=(const Semaphore&) = delete;
65+
6666
#define CLASSES_SEMAPHORE_H_HAS_TRYENTER 1
6767
bool tryEnter(const int seconds = 0, int milliseconds = 0);
6868

@@ -96,16 +96,16 @@ class SignalSafeSemaphore
9696

9797
void init();
9898

99-
// Forbid copying
100-
SignalSafeSemaphore(const SignalSafeSemaphore&);
101-
SignalSafeSemaphore& operator=(const SignalSafeSemaphore&);
102-
10399
public:
104100
SignalSafeSemaphore() { init(); }
105101
explicit SignalSafeSemaphore(MemoryPool&) { init(); }
106102

107103
~SignalSafeSemaphore();
108104

105+
// Forbid copying
106+
SignalSafeSemaphore(const SignalSafeSemaphore&) = delete;
107+
SignalSafeSemaphore& operator=(const SignalSafeSemaphore&) = delete;
108+
109109
void enter()
110110
{
111111
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
@@ -148,15 +148,16 @@ class SignalSafeSemaphore
148148

149149
void init();
150150

151-
// Forbid copying
152-
SignalSafeSemaphore(const SignalSafeSemaphore&);
153-
SignalSafeSemaphore& operator=(const SignalSafeSemaphore&);
154-
155151
public:
156152
SignalSafeSemaphore() { init(); }
157153
explicit SignalSafeSemaphore(MemoryPool&) { init(); }
158154

159155
~SignalSafeSemaphore();
156+
157+
// Forbid copying
158+
SignalSafeSemaphore(const SignalSafeSemaphore&) = delete;
159+
SignalSafeSemaphore& operator=(const SignalSafeSemaphore&) = delete;
160+
160161
void enter();
161162

162163
void release(SLONG count = 1)
@@ -218,16 +219,16 @@ class Semaphore
218219
void mtxLock();
219220
void mtxUnlock();
220221

221-
// Forbid copying
222-
Semaphore(const Semaphore&);
223-
Semaphore& operator=(const Semaphore&);
224-
225222
public:
226223
Semaphore() { init(); }
227224
explicit Semaphore(MemoryPool&) { init(); }
228225

229226
~Semaphore();
230227

228+
// Forbid copying
229+
Semaphore(const Semaphore&) = delete;
230+
Semaphore& operator=(const Semaphore&) = delete;
231+
231232
bool tryEnter(const int seconds = 0, int milliseconds = 0);
232233
void enter();
233234
void release(SLONG count = 1);

0 commit comments

Comments
 (0)