| 153 | } |
| 154 | |
| 155 | bool 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 | |
| 212 | void SyncObject::unlock(Sync* /*sync*/, SyncType type) |
no test coverage detected