| 168 | } |
| 169 | |
| 170 | void SharedLazyTessellationCache::realloc(const size_t new_size) |
| 171 | { |
| 172 | /* lock the reset_state */ |
| 173 | reset_state.lock(); |
| 174 | |
| 175 | /* lock the linked list of thread states */ |
| 176 | linkedlist_mtx.lock(); |
| 177 | |
| 178 | /* block all threads */ |
| 179 | for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next) |
| 180 | if (lockThread(t,THREAD_BLOCK_ATOMIC_ADD) != 0) |
| 181 | waitForUsersLessEqual(t,THREAD_BLOCK_ATOMIC_ADD); |
| 182 | |
| 183 | /* reallocate data */ |
| 184 | if (data) os_free(data,size,hugepages); |
| 185 | size = new_size; |
| 186 | data = nullptr; |
| 187 | if (size) data = (float*)os_malloc(size,hugepages); |
| 188 | maxBlocks = size/BLOCK_SIZE; |
| 189 | |
| 190 | /* invalidate entire cache */ |
| 191 | localTime += NUM_CACHE_SEGMENTS; |
| 192 | |
| 193 | /* reset to the first segment */ |
| 194 | #if FORCE_SIMPLE_FLUSH == 1 |
| 195 | next_block = 0; |
| 196 | switch_block_threshold = maxBlocks; |
| 197 | #else |
| 198 | const size_t region = localTime % NUM_CACHE_SEGMENTS; |
| 199 | next_block = region * (maxBlocks/NUM_CACHE_SEGMENTS); |
| 200 | switch_block_threshold = next_block + (maxBlocks/NUM_CACHE_SEGMENTS); |
| 201 | assert( switch_block_threshold <= maxBlocks ); |
| 202 | #endif |
| 203 | |
| 204 | /* release all blocked threads */ |
| 205 | for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next) |
| 206 | unlockThread(t,-THREAD_BLOCK_ATOMIC_ADD); |
| 207 | |
| 208 | /* unlock the linked list of thread states */ |
| 209 | linkedlist_mtx.unlock(); |
| 210 | |
| 211 | /* unlock the reset_state */ |
| 212 | reset_state.unlock(); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
no test coverage detected