int gem_handle;
struct anv_mmap_cleanup *cleanup;
+ pthread_mutex_lock(&pool->device->mutex);
+
if (old_size == 0) {
size = 32 * pool->block_size;
} else {
cleanup = anv_vector_add(&pool->mmap_cleanups);
if (!cleanup)
- return 0;
+ goto fail;
*cleanup = ANV_MMAP_CLEANUP_INIT;
if (old_size == 0)
pool->fd = memfd_create("block pool", MFD_CLOEXEC);
if (pool->fd == -1)
- return 0;
+ goto fail;
if (ftruncate(pool->fd, size) == -1)
- return 0;
+ goto fail;
/* First try to see if mremap can grow the map in place. */
map = MAP_FAILED;
cleanup->size = size;
}
if (map == MAP_FAILED)
- return 0;
+ goto fail;
gem_handle = anv_gem_userptr(pool->device, map, size);
if (gem_handle == 0)
- return 0;
+ goto fail;
cleanup->gem_handle = gem_handle;
/* Now that we successfull allocated everything, we can write the new
pool->bo.map = map;
pool->bo.index = 0;
+ pthread_mutex_unlock(&pool->device->mutex);
+
return size;
+
+fail:
+ pthread_mutex_unlock(&pool->device->mutex);
+ return 0;
}
uint32_t
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++) {
}
anv_block_pool_finish(&pool);
+ pthread_mutex_destroy(&device.mutex);
}
int main(int argc, char **argv)
struct anv_block_pool block_pool;
struct anv_state_pool state_pool;
+ pthread_mutex_init(&device.mutex, NULL);
+
for (unsigned i = 0; i < NUM_RUNS; i++) {
anv_block_pool_init(&block_pool, &device, 256);
anv_state_pool_init(&state_pool, &block_pool);
anv_state_pool_finish(&state_pool);
anv_block_pool_finish(&block_pool);
}
+
+ pthread_mutex_destroy(&device.mutex);
}
struct anv_block_pool block_pool;
struct anv_state_pool state_pool;
+ pthread_mutex_init(&device.mutex, NULL);
anv_block_pool_init(&block_pool, &device, 4096);
anv_state_pool_init(&state_pool, &block_pool);
anv_state_pool_finish(&state_pool);
anv_block_pool_finish(&block_pool);
+ pthread_mutex_destroy(&device.mutex);
}
struct anv_block_pool block_pool;
struct anv_state_pool state_pool;
+ pthread_mutex_init(&device.mutex, NULL);
anv_block_pool_init(&block_pool, &device, 64);
anv_state_pool_init(&state_pool, &block_pool);
anv_state_pool_finish(&state_pool);
anv_block_pool_finish(&block_pool);
+ pthread_mutex_destroy(&device.mutex);
}
int main(int argc, char **argv)