4343namespace Firebird
4444{
4545
46- const int LOCK_WRITER_OFFSET = 50000 ;
46+ inline constexpr int LOCK_WRITER_OFFSET = 50000 ;
4747
4848// Should work pretty fast if atomic operations are native.
49- // This is not the case for Win95
5049class RWLock : public Reasons
5150{
5251private:
@@ -72,10 +71,6 @@ class RWLock : public Reasons
7271 system_call_failed::raise (" CreateEvent" );
7372 }
7473
75- // Forbid copying
76- RWLock (const RWLock&);
77- RWLock& operator =(const RWLock&);
78-
7974public:
8075 RWLock () { init (); }
8176 explicit RWLock (Firebird::MemoryPool&) { init (); }
@@ -86,12 +81,18 @@ class RWLock : public Reasons
8681 if (writers_event && !CloseHandle (writers_event))
8782 system_call_failed::raise (" CloseHandle" );
8883 }
84+
85+ // Forbid copying
86+ RWLock (const RWLock&) = delete ;
87+ RWLock& operator =(const RWLock&) = delete ;
88+
8989 // Returns negative value if writer is active.
9090 // Otherwise returns a number of readers
91- LONG getState () const
91+ LONG getState () const noexcept
9292 {
9393 return lock.value ();
9494 }
95+
9596 void unblockWaiting ()
9697 {
9798 if (blockedWriters.value ())
@@ -108,6 +109,7 @@ class RWLock : public Reasons
108109 }
109110 }
110111 }
112+
111113 bool tryBeginRead (const char * aReason)
112114 {
113115 if (lock.value () < 0 )
@@ -122,6 +124,7 @@ class RWLock : public Reasons
122124 unblockWaiting ();
123125 return false ;
124126 }
127+
125128 bool tryBeginWrite (const char * aReason)
126129 {
127130 if (lock.value ())
@@ -136,6 +139,7 @@ class RWLock : public Reasons
136139 unblockWaiting ();
137140 return false ;
138141 }
142+
139143 void beginRead (const char * aReason)
140144 {
141145 if (!tryBeginRead (aReason))
@@ -155,6 +159,7 @@ class RWLock : public Reasons
155159 }
156160 }
157161 }
162+
158163 void beginWrite (const char * aReason)
159164 {
160165 if (!tryBeginWrite (aReason))
@@ -168,6 +173,7 @@ class RWLock : public Reasons
168173 --blockedWriters;
169174 }
170175 }
176+
171177 void endRead ()
172178 {
173179 if (--lock == 0 )
@@ -202,10 +208,6 @@ class RWLock : public Reasons
202208 AtomicCounter lockCounter;
203209#endif
204210
205- // Forbid copying
206- RWLock (const RWLock&);
207- RWLock& operator =(const RWLock&);
208-
209211 void init ()
210212 {
211213 int code;
@@ -239,6 +241,10 @@ class RWLock : public Reasons
239241 system_call_failed::raise (" pthread_rwlock_destroy" , code);
240242 }
241243
244+ // Forbid copying
245+ RWLock (const RWLock&) = delete ;
246+ RWLock& operator =(const RWLock&) = delete ;
247+
242248 void beginRead (const char * aReason)
243249 {
244250 if (const int code = pthread_rwlock_rdlock (&lock))
@@ -342,6 +348,10 @@ class ReadLockGuard
342348 release ();
343349 }
344350
351+ // Forbid copying
352+ ReadLockGuard (const ReadLockGuard&) = delete ;
353+ ReadLockGuard& operator =(const ReadLockGuard&) = delete ;
354+
345355 void release ()
346356 {
347357 if (lock)
@@ -352,10 +362,6 @@ class ReadLockGuard
352362 }
353363
354364private:
355- // Forbid copying
356- ReadLockGuard (const ReadLockGuard&);
357- ReadLockGuard& operator =(const ReadLockGuard&);
358-
359365 RWLock* lock;
360366};
361367
@@ -381,6 +387,10 @@ class WriteLockGuard
381387 release ();
382388 }
383389
390+ // Forbid copying
391+ WriteLockGuard (const WriteLockGuard&) = delete ;
392+ WriteLockGuard& operator =(const WriteLockGuard&) = delete ;
393+
384394 void release ()
385395 {
386396 if (lock)
@@ -391,10 +401,6 @@ class WriteLockGuard
391401 }
392402
393403private:
394- // Forbid copying
395- WriteLockGuard (const WriteLockGuard&);
396- WriteLockGuard& operator =(const WriteLockGuard&);
397-
398404 RWLock* lock;
399405};
400406
0 commit comments