| 376 | } |
| 377 | |
| 378 | inline void ThreadCache::Deallocate(void* ptr, size_t cl) { |
| 379 | FreeList* list = &list_[cl]; |
| 380 | size_ += Static::sizemap()->ByteSizeForClass(cl); |
| 381 | ssize_t size_headroom = max_size_ - size_ - 1; |
| 382 | |
| 383 | // This catches back-to-back frees of allocs in the same size |
| 384 | // class. A more comprehensive (and expensive) test would be to walk |
| 385 | // the entire freelist. But this might be enough to find some bugs. |
| 386 | ASSERT(ptr != list->Next()); |
| 387 | |
| 388 | list->Push(ptr); |
| 389 | ssize_t list_headroom = |
| 390 | static_cast<ssize_t>(list->max_length()) - list->length(); |
| 391 | |
| 392 | // There are two relatively uncommon things that require further work. |
| 393 | // In the common case we're done, and in that case we need a single branch |
| 394 | // because of the bitwise-or trick that follows. |
| 395 | |
| 396 | //BCF- we manually scavenge now |
| 397 | if ((list_headroom | size_headroom) < 0) { |
| 398 | if (list_headroom < 0) { |
| 399 | ListTooLong(list, cl); |
| 400 | } |
| 401 | if (size_ >= max_size_) Scavenge(); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | inline ThreadCache* ThreadCache::GetThreadHeap() { |
| 406 | #ifdef HAVE_TLS |
no test coverage detected