int fd;
- mtx_t lock;
+ simple_mtx_t lock;
/** Array of lists of cached gem objects of power-of-two sizes */
struct bo_cache_bucket cache_bucket[14 * 4];
bool bo_reuse:1;
};
-static mtx_t global_bufmgr_list_mutex = _MTX_INITIALIZER_NP;
+static simple_mtx_t global_bufmgr_list_mutex = _SIMPLE_MTX_INITIALIZER_NP;
static struct list_head global_bufmgr_list = {
.next = &global_bufmgr_list,
.prev = &global_bufmgr_list,
uint64_t bo_size =
bucket ? bucket->size : MAX2(ALIGN(size, page_size), page_size);
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
/* Get a buffer out of the cache if available. First, we try to find
* one with a matching memory zone so we can avoid reallocating VMA.
*/
bo = alloc_bo_from_cache(bufmgr, bucket, alignment, flags);
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
if (!bo) {
bo = alloc_fresh_bo(bufmgr, bo_size);
* alternating names for the front/back buffer a linear search
* provides a sufficiently fast match.
*/
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
bo = find_and_ref_external_bo(bufmgr->name_table, handle);
if (bo)
goto out;
DBG("bo_create_from_handle: %d (%s)\n", handle, bo->name);
out:
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return bo;
err_unref:
bo_free(bo);
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return NULL;
}
clock_gettime(CLOCK_MONOTONIC, &time);
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
if (p_atomic_dec_zero(&bo->refcount)) {
bo_unreference_final(bo, time.tv_sec);
cleanup_bo_cache(bufmgr, time.tv_sec);
}
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
}
static void
static void
crocus_bufmgr_destroy(struct crocus_bufmgr *bufmgr)
{
- mtx_destroy(&bufmgr->lock);
+ simple_mtx_destroy(&bufmgr->lock);
/* Free any cached buffer objects we were going to reuse */
for (int i = 0; i < bufmgr->num_buckets; i++) {
uint32_t handle;
struct crocus_bo *bo;
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
int ret = drmPrimeFDToHandle(bufmgr->fd, prime_fd, &handle);
if (ret) {
DBG("import_dmabuf: failed to obtain handle from fd: %s\n",
strerror(errno));
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return NULL;
}
}
out:
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return bo;
err:
bo_free(bo);
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return NULL;
}
uint32_t handle;
struct crocus_bo *bo;
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
int ret = drmPrimeFDToHandle(bufmgr->fd, prime_fd, &handle);
if (ret) {
DBG("import_dmabuf: failed to obtain handle from fd: %s\n",
strerror(errno));
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return NULL;
}
_mesa_hash_table_insert(bufmgr->handle_table, &bo->gem_handle, bo);
out:
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
return bo;
}
return;
}
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
crocus_bo_make_external_locked(bo);
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
}
int
if (intel_ioctl(bufmgr->fd, DRM_IOCTL_GEM_FLINK, &flink))
return -errno;
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
if (!bo->global_name) {
crocus_bo_make_external_locked(bo);
bo->global_name = flink.name;
_mesa_hash_table_insert(bufmgr->name_table, &bo->global_name, bo);
}
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
}
*name = bo->global_name;
return err;
}
- mtx_lock(&bufmgr->lock);
+ simple_mtx_lock(&bufmgr->lock);
err = drmPrimeFDToHandle(drm_fd, dmabuf_fd, &export->gem_handle);
close(dmabuf_fd);
if (err) {
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
free(export);
return err;
}
if (!found)
list_addtail(&export->link, &bo->exports);
- mtx_unlock(&bufmgr->lock);
+ simple_mtx_unlock(&bufmgr->lock);
*out_handle = export->gem_handle;
p_atomic_set(&bufmgr->refcount, 1);
- if (mtx_init(&bufmgr->lock, mtx_plain) != 0) {
- free(bufmgr);
- return NULL;
- }
+ simple_mtx_init(&bufmgr->lock, mtx_plain);
list_inithead(&bufmgr->zombie_list);
void
crocus_bufmgr_unref(struct crocus_bufmgr *bufmgr)
{
- mtx_lock(&global_bufmgr_list_mutex);
+ simple_mtx_lock(&global_bufmgr_list_mutex);
if (p_atomic_dec_zero(&bufmgr->refcount)) {
list_del(&bufmgr->link);
crocus_bufmgr_destroy(bufmgr);
}
- mtx_unlock(&global_bufmgr_list_mutex);
+ simple_mtx_unlock(&global_bufmgr_list_mutex);
}
/**
struct crocus_bufmgr *bufmgr = NULL;
- mtx_lock(&global_bufmgr_list_mutex);
+ simple_mtx_lock(&global_bufmgr_list_mutex);
list_for_each_entry(struct crocus_bufmgr, iter_bufmgr, &global_bufmgr_list, link) {
struct stat iter_st;
if (fstat(iter_bufmgr->fd, &iter_st))
list_addtail(&bufmgr->link, &global_bufmgr_list);
unlock:
- mtx_unlock(&global_bufmgr_list_mutex);
+ simple_mtx_unlock(&global_bufmgr_list_mutex);
return bufmgr;
}