MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / lockConditional

Method lockConditional

src/common/classes/SyncObject.cpp:155–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155bool SyncObject::lockConditional(SyncType type, const char* from)
156{
157 if (waitingThreads)
158 return false;
159
160 if (type == SYNC_SHARED)
161 {
162 while (true)
163 {
164 const AtomicCounter::counter_type oldState = lockState;
165 if (oldState < 0)
166 break;
167
168 const AtomicCounter::counter_type newState = oldState + 1;
169 if (lockState.compareExchange(oldState, newState))
170 {
171 WaitForFlushCache();
172#ifdef DEV_BUILD
173 MutexLockGuard g(mutex, FB_FUNCTION);
174#endif
175 reason(from);
176 return true;
177 }
178 }
179 }
180 else
181 {
182 ThreadSync* thread = ThreadSync::findThread();
183 fb_assert(thread);
184
185 if (thread == exclusiveThread)
186 {
187 ++monitorCount;
188 reason(from);
189 return true;
190 }
191
192 while (waiters == 0)
193 {
194 const AtomicCounter::counter_type oldState = lockState;
195 if (oldState != 0)
196 break;
197
198 if (lockState.compareExchange(oldState, -1))
199 {
200 WaitForFlushCache();
201 exclusiveThread = thread;
202 reason(from);
203 return true;
204 }
205 }
206
207 }
208
209 return false;
210}
211
212void SyncObject::unlock(Sync* /*sync*/, SyncType type)

Callers 4

CheckoutSyncGuardMethod · 0.45
CCH_down_grade_dbbFunction · 0.45
get_bufferFunction · 0.45
addRefConditionalMethod · 0.45

Calls 2

WaitForFlushCacheFunction · 0.85
compareExchangeMethod · 0.80

Tested by

no test coverage detected