etnaviv: replace all dup() with os_dupfd_cloexec()
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_fence.c
index 65402aaa3bde0bd9c0e0db05adb76ee5f95b0b04..c0f451fac2d3ab3cee1960bfa5da5307eb7403a6 100644 (file)
 #include "etnaviv_context.h"
 #include "etnaviv_screen.h"
 
+#include "util/os_file.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 
 struct pipe_fence_handle {
    struct pipe_reference reference;
-   struct etna_context *ctx;
    struct etna_screen *screen;
    int fence_fd;
    uint32_t timestamp;
@@ -61,14 +61,12 @@ etna_screen_fence_reference(struct pipe_screen *pscreen,
    *ptr = fence;
 }
 
-static boolean
+static bool
 etna_screen_fence_finish(struct pipe_screen *pscreen, struct pipe_context *ctx,
                          struct pipe_fence_handle *fence, uint64_t timeout)
 {
-   if (fence->fence_fd != -1) {
-      int ret = sync_wait(fence->fence_fd, timeout / 1000000);
-      return ret == 0;
-   }
+   if (fence->fence_fd != -1)
+       return !sync_wait(fence->fence_fd, timeout / 1000000);
 
    if (etna_pipe_wait_ns(fence->screen->pipe, fence->timestamp, timeout))
       return false;
@@ -78,9 +76,11 @@ etna_screen_fence_finish(struct pipe_screen *pscreen, struct pipe_context *ctx,
 
 void
 etna_create_fence_fd(struct pipe_context *pctx,
-                     struct pipe_fence_handle **pfence, int fd)
+                     struct pipe_fence_handle **pfence, int fd,
+                     enum pipe_fd_type type)
 {
-   *pfence = etna_fence_create(pctx, dup(fd));
+   assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
+   *pfence = etna_fence_create(pctx, os_dupfd_cloexec(fd));
 }
 
 void
@@ -89,14 +89,15 @@ etna_fence_server_sync(struct pipe_context *pctx,
 {
    struct etna_context *ctx = etna_context(pctx);
 
-   sync_accumulate("etnaviv", &ctx->in_fence_fd, pfence->fence_fd);
+   if (pfence->fence_fd != -1)
+      sync_accumulate("etnaviv", &ctx->in_fence_fd, pfence->fence_fd);
 }
 
 static int
 etna_screen_fence_get_fd(struct pipe_screen *pscreen,
                          struct pipe_fence_handle *pfence)
 {
-   return dup(pfence->fence_fd);
+   return os_dupfd_cloexec(pfence->fence_fd);
 }
 
 struct pipe_fence_handle *
@@ -111,7 +112,6 @@ etna_fence_create(struct pipe_context *pctx, int fence_fd)
 
    pipe_reference_init(&fence->reference, 1);
 
-   fence->ctx = ctx;
    fence->screen = ctx->screen;
    fence->timestamp = etna_cmd_stream_timestamp(ctx->stream);
    fence->fence_fd = fence_fd;