Remove some objects of class "cl" from central cache and add to thread heap. On success, return the first object for immediate use; otherwise return NULL.
| 152 | // Remove some objects of class "cl" from central cache and add to thread heap. |
| 153 | // On success, return the first object for immediate use; otherwise return NULL. |
| 154 | void* ThreadCache::FetchFromCentralCache(size_t cl, size_t byte_size) { |
| 155 | FreeList* list = &list_[cl]; |
| 156 | ASSERT(list->empty()); |
| 157 | const int batch_size = Static::sizemap()->num_objects_to_move(cl); |
| 158 | |
| 159 | const int num_to_move = min<int>(list->max_length(), batch_size); |
| 160 | void *start, *end; |
| 161 | int fetch_count = Static::central_cache()[cl].RemoveRange(&start, &end, num_to_move); |
| 162 | |
| 163 | ASSERT((start == NULL) == (fetch_count == 0)); |
| 164 | if (--fetch_count >= 0) { |
| 165 | size_ += byte_size * fetch_count; |
| 166 | list->PushRange(fetch_count, SLL_Next(start), end); |
| 167 | } |
| 168 | |
| 169 | // Increase max length slowly up to batch_size. After that, |
| 170 | // increase by batch_size in one shot so that the length is a |
| 171 | // multiple of batch_size. |
| 172 | if (static_cast<int>(list->max_length()) < batch_size) { |
| 173 | list->set_max_length(list->max_length() + 1); |
| 174 | } else { |
| 175 | // Don't let the list get too long. In 32 bit builds, the length is represented by a 16 bit int, so we need to watch out |
| 176 | // for integer overflow. |
| 177 | int new_length = min<int>(list->max_length() + batch_size, kMaxDynamicFreeListLength); |
| 178 | |
| 179 | // The list's max_length must always be a multiple of batch_size, and kMaxDynamicFreeListLength is not necessarily a |
| 180 | // multiple of batch_size. |
| 181 | new_length -= new_length % batch_size; |
| 182 | ASSERT(new_length % batch_size == 0); |
| 183 | list->set_max_length(new_length); |
| 184 | } |
| 185 | return start; |
| 186 | } |
| 187 | |
| 188 | void ThreadCache::ListTooLong(FreeList* list, size_t cl) { |
| 189 | const int batch_size = Static::sizemap()->num_objects_to_move(cl); |
nothing calls this directly
no test coverage detected