| 288 | } |
| 289 | |
| 290 | bool |
| 291 | BgFetchState::uniqueAcquire(const String &url) |
| 292 | { |
| 293 | bool permitted = true; |
| 294 | bool throttled = false; |
| 295 | size_t cachedCounter = 0; |
| 296 | |
| 297 | TSMutexLock(_lock); |
| 298 | if (0 == _concurrentFetchesMax || _concurrentFetches < _concurrentFetchesMax) { |
| 299 | permitted = _unique->acquire(url); |
| 300 | if (permitted) { |
| 301 | cachedCounter = ++_concurrentFetches; |
| 302 | } |
| 303 | } else { |
| 304 | throttled = true; |
| 305 | } |
| 306 | TSMutexUnlock(_lock); |
| 307 | |
| 308 | /* Update the metrics, no need to lock? */ |
| 309 | if (throttled) { |
| 310 | incrementMetric(FETCH_THROTTLED); |
| 311 | } |
| 312 | |
| 313 | if (permitted && !throttled) { |
| 314 | incrementMetric(FETCH_UNIQUE_YES); |
| 315 | incrementMetric(FETCH_TOTAL); |
| 316 | setMetric(FETCH_ACTIVE, cachedCounter); |
| 317 | } else { |
| 318 | incrementMetric(FETCH_UNIQUE_NO); |
| 319 | } |
| 320 | |
| 321 | return permitted; |
| 322 | } |
| 323 | |
| 324 | bool |
| 325 | BgFetchState::uniqueRelease(const String &url) |
no test coverage detected