return NULL;
}
-static void run_test()
+static void validate_monotonic(uint32_t **blocks)
{
- struct anv_device device;
- struct anv_block_pool pool;
-
- pthread_mutex_init(&device.mutex, NULL);
- anv_block_pool_init(&pool, &device, 16);
-
- for (unsigned i = 0; i < NUM_THREADS; i++) {
- jobs[i].pool = &pool;
- jobs[i].id = i;
- pthread_create(&jobs[i].thread, NULL, alloc_blocks, &jobs[i]);
- }
-
- for (unsigned i = 0; i < NUM_THREADS; i++)
- pthread_join(jobs[i].thread, NULL);
-
/* A list of indices, one per thread */
unsigned next[NUM_THREADS];
memset(next, 0, sizeof(next));
if (next[i] >= BLOCKS_PER_THREAD)
continue;
- if (thread_max < jobs[i].blocks[next[i]]) {
- thread_max = jobs[i].blocks[next[i]];
+ if (thread_max < blocks[i][next[i]]) {
+ thread_max = blocks[i][next[i]];
max_thread_idx = i;
}
}
break;
/* That next element had better be higher than the previous highest */
- assert(jobs[max_thread_idx].blocks[next[max_thread_idx]] > highest);
+ assert(blocks[max_thread_idx][next[max_thread_idx]] > highest);
- highest = jobs[max_thread_idx].blocks[next[max_thread_idx]];
+ highest = blocks[max_thread_idx][next[max_thread_idx]];
next[max_thread_idx]++;
}
+}
+
+static void run_test()
+{
+ struct anv_device device;
+ struct anv_block_pool pool;
+
+ pthread_mutex_init(&device.mutex, NULL);
+ anv_block_pool_init(&pool, &device, 16);
+
+ for (unsigned i = 0; i < NUM_THREADS; i++) {
+ jobs[i].pool = &pool;
+ jobs[i].id = i;
+ pthread_create(&jobs[i].thread, NULL, alloc_blocks, &jobs[i]);
+ }
+
+ for (unsigned i = 0; i < NUM_THREADS; i++)
+ pthread_join(jobs[i].thread, NULL);
+
+ uint32_t *block_ptrs[NUM_THREADS];
+ for (unsigned i = 0; i < NUM_THREADS; i++)
+ block_ptrs[i] = jobs[i].blocks;
+
+ validate_monotonic(block_ptrs);
anv_block_pool_finish(&pool);
pthread_mutex_destroy(&device.mutex);