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