aboutsummaryrefslogtreecommitdiffstats
path: root/amdgpu/amdgpu_device.c
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2015-08-07 17:09:35 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2015-08-13 17:43:36 +0100
commitbddf4df4a17df30624f27c5e85f859a1b09f8fc0 (patch)
treeb9854882fc81b841b457e8ffb5b4cadcb6b5059a /amdgpu/amdgpu_device.c
parentb47181897770520bb5afcebc2c2c3ffaf7729a36 (diff)
downloadexternal_libdrm-bddf4df4a17df30624f27c5e85f859a1b09f8fc0.tar.gz
external_libdrm-bddf4df4a17df30624f27c5e85f859a1b09f8fc0.tar.bz2
external_libdrm-bddf4df4a17df30624f27c5e85f859a1b09f8fc0.zip
amdgpu: hide the final internal functions from global namespace
Thus the only symbols that we export are the ones officially provided by the API. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
Diffstat (limited to 'amdgpu/amdgpu_device.c')
-rw-r--r--amdgpu/amdgpu_device.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index bf941c1e..c6bbae81 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -47,7 +47,7 @@
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
#define UINT_TO_PTR(x) ((void *)((intptr_t)(x)))
-pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct util_hash_table *fd_tab;
static unsigned handle_hash(void *key)
@@ -127,6 +127,41 @@ static int amdgpu_get_auth(int fd, int *auth)
return r;
}
+static void amdgpu_device_free_internal(amdgpu_device_handle dev)
+{
+ amdgpu_vamgr_reference(&dev->vamgr, NULL);
+ util_hash_table_destroy(dev->bo_flink_names);
+ util_hash_table_destroy(dev->bo_handles);
+ pthread_mutex_destroy(&dev->bo_table_mutex);
+ util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
+ close(dev->fd);
+ if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
+ close(dev->flink_fd);
+ free(dev);
+}
+
+/**
+ * Assignment between two amdgpu_device pointers with reference counting.
+ *
+ * Usage:
+ * struct amdgpu_device *dst = ... , *src = ...;
+ *
+ * dst = src;
+ * // No reference counting. Only use this when you need to move
+ * // a reference from one pointer to another.
+ *
+ * amdgpu_device_reference(&dst, src);
+ * // Reference counters are updated. dst is decremented and src is
+ * // incremented. dst is freed if its reference counter is 0.
+ */
+static void amdgpu_device_reference(struct amdgpu_device **dst,
+ struct amdgpu_device *src)
+{
+ if (update_references(&(*dst)->refcount, &src->refcount))
+ amdgpu_device_free_internal(*dst);
+ *dst = src;
+}
+
int amdgpu_device_initialize(int fd,
uint32_t *major_version,
uint32_t *minor_version,
@@ -232,29 +267,8 @@ cleanup:
return r;
}
-void amdgpu_device_free_internal(amdgpu_device_handle dev)
-{
- amdgpu_vamgr_reference(&dev->vamgr, NULL);
- util_hash_table_destroy(dev->bo_flink_names);
- util_hash_table_destroy(dev->bo_handles);
- pthread_mutex_destroy(&dev->bo_table_mutex);
- util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
- close(dev->fd);
- if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
- close(dev->flink_fd);
- free(dev);
-}
-
int amdgpu_device_deinitialize(amdgpu_device_handle dev)
{
amdgpu_device_reference(&dev, NULL);
return 0;
}
-
-void amdgpu_device_reference(struct amdgpu_device **dst,
- struct amdgpu_device *src)
-{
- if (update_references(&(*dst)->refcount, &src->refcount))
- amdgpu_device_free_internal(*dst);
- *dst = src;
-}