aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Gmeiner2016-11-13 14:29:22 -0600
committerChristian Gmeiner2016-11-20 08:58:28 -0600
commitbefb6429f03072b128a55360c1cf57f7b4d47b67 (patch)
treebe4ec384bea15f490dd84731e769752dc2a6f7d1 /etnaviv/etnaviv_device.c
parenta14d6a6a43742cfad7ab346bf9168eb893881816 (diff)
downloadexternal-libdrm-befb6429f03072b128a55360c1cf57f7b4d47b67.tar.gz
external-libdrm-befb6429f03072b128a55360c1cf57f7b4d47b67.tar.xz
external-libdrm-befb6429f03072b128a55360c1cf57f7b4d47b67.zip
etnaviv: add API to create etna_device from private dup() fd
Like etna_device_new() but creates it's own private dup() of the fd which is close()d when the device is finalized. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Acked-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'etnaviv/etnaviv_device.c')
-rw-r--r--etnaviv/etnaviv_device.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/etnaviv/etnaviv_device.c b/etnaviv/etnaviv_device.c
index b7163609..3ce92030 100644
--- a/etnaviv/etnaviv_device.c
+++ b/etnaviv/etnaviv_device.c
@@ -61,6 +61,21 @@ struct etna_device *etna_device_new(int fd)
61 return dev; 61 return dev;
62} 62}
63 63
64/* like etna_device_new() but creates it's own private dup() of the fd
65 * which is close()d when the device is finalized. */
66struct etna_device *etna_device_new_dup(int fd)
67{
68 int dup_fd = dup(fd);
69 struct etna_device *dev = etna_device_new(dup_fd);
70
71 if (dev)
72 dev->closefd = 1;
73 else
74 close(dup_fd);
75
76 return dev;
77}
78
64struct etna_device *etna_device_ref(struct etna_device *dev) 79struct etna_device *etna_device_ref(struct etna_device *dev)
65{ 80{
66 atomic_inc(&dev->refcnt); 81 atomic_inc(&dev->refcnt);
@@ -74,6 +89,9 @@ static void etna_device_del_impl(struct etna_device *dev)
74 drmHashDestroy(dev->handle_table); 89 drmHashDestroy(dev->handle_table);
75 drmHashDestroy(dev->name_table); 90 drmHashDestroy(dev->name_table);
76 91
92 if (dev->closefd)
93 close(dev->fd);
94
77 free(dev); 95 free(dev);
78} 96}
79 97