[Mesa-dev] [PATCH 5/4] gallium/util: replace pipe_thread_create() with u_thread_create()

Timothy Arceri tarceri at itsqueeze.com
Wed Mar 8 23:09:56 UTC 2017


They do the same thing we are just moving the function to be
accessible to all of Mesa.
---
 src/gallium/auxiliary/os/os_thread.h         | 28 +---------------------------
 src/gallium/drivers/ddebug/dd_context.c      |  2 +-
 src/gallium/drivers/llvmpipe/lp_rast.c       |  2 +-
 src/gallium/drivers/radeon/r600_gpu_load.c   |  2 +-
 src/gallium/drivers/rbug/rbug_core.c         |  2 +-
 src/gallium/state_trackers/nine/nine_state.c |  2 +-
 src/gallium/tests/unit/pipe_barrier_test.c   |  2 +-
 7 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
index 2292123..468fbfe 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -32,48 +32,22 @@
  * thread-specific data functions.
  */
 
 
 #ifndef OS_THREAD_H_
 #define OS_THREAD_H_
 
 
 #include "pipe/p_compiler.h"
 #include "util/u_debug.h" /* for assert */
+#include "util/u_thread.h"
 
-#include "c11/threads.h"
-
-#ifdef HAVE_PTHREAD
-#include <signal.h>
-#endif
-
-
-static inline thrd_t pipe_thread_create(int (*routine)(void *), void *param)
-{
-   thrd_t thread;
-#ifdef HAVE_PTHREAD
-   sigset_t saved_set, new_set;
-   int ret;
-
-   sigfillset(&new_set);
-   pthread_sigmask(SIG_SETMASK, &new_set, &saved_set);
-   ret = thrd_create( &thread, routine, param );
-   pthread_sigmask(SIG_SETMASK, &saved_set, NULL);
-#else
-   int ret;
-   ret = thrd_create( &thread, routine, param );
-#endif
-   if (ret)
-      return 0;
-
-   return thread;
-}
 
 static inline void pipe_thread_setname( const char *name )
 {
 #if defined(HAVE_PTHREAD)
 #  if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__) && \
       (__GLIBC__ >= 3 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 12))
    pthread_setname_np(pthread_self(), name);
 #  endif
 #endif
    (void)name;
diff --git a/src/gallium/drivers/ddebug/dd_context.c b/src/gallium/drivers/ddebug/dd_context.c
index eae128a..171afd2 100644
--- a/src/gallium/drivers/ddebug/dd_context.c
+++ b/src/gallium/drivers/ddebug/dd_context.c
@@ -864,21 +864,21 @@ dd_context_create(struct dd_screen *dscreen, struct pipe_context *pipe)
                                            PIPE_TRANSFER_READ_WRITE |
                                            PIPE_TRANSFER_PERSISTENT |
                                            PIPE_TRANSFER_COHERENT,
                                            &dctx->fence_transfer);
       if (!dctx->mapped_fence)
          goto fail;
 
       *dctx->mapped_fence = 0;
 
       (void) mtx_init(&dctx->mutex, mtx_plain);
-      dctx->thread = pipe_thread_create(dd_thread_pipelined_hang_detect, dctx);
+      dctx->thread = u_thread_create(dd_thread_pipelined_hang_detect, dctx);
       if (!dctx->thread) {
          mtx_destroy(&dctx->mutex);
          goto fail;
       }
    }
 
    return &dctx->base;
 
 fail:
    if (dctx) {
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index 678ef0b..d746778 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -858,21 +858,21 @@ thread_function(void *init_data)
  */
 static void
 create_rast_threads(struct lp_rasterizer *rast)
 {
    unsigned i;
 
    /* NOTE: if num_threads is zero, we won't use any threads */
    for (i = 0; i < rast->num_threads; i++) {
       pipe_semaphore_init(&rast->tasks[i].work_ready, 0);
       pipe_semaphore_init(&rast->tasks[i].work_done, 0);
-      rast->threads[i] = pipe_thread_create(thread_function,
+      rast->threads[i] = u_thread_create(thread_function,
                                             (void *) &rast->tasks[i]);
    }
 }
 
 
 
 /**
  * Create new lp_rasterizer.  If num_threads is zero, don't create any
  * new threads, do rendering synchronously.
  * \param num_threads  number of rasterizer threads to create
diff --git a/src/gallium/drivers/radeon/r600_gpu_load.c b/src/gallium/drivers/radeon/r600_gpu_load.c
index 1b51af4..3b45545 100644
--- a/src/gallium/drivers/radeon/r600_gpu_load.c
+++ b/src/gallium/drivers/radeon/r600_gpu_load.c
@@ -176,21 +176,21 @@ void r600_gpu_load_kill_thread(struct r600_common_screen *rscreen)
 
 static uint64_t r600_read_mmio_counter(struct r600_common_screen *rscreen,
 				       unsigned busy_index)
 {
 	/* Start the thread if needed. */
 	if (!rscreen->gpu_load_thread) {
 		mtx_lock(&rscreen->gpu_load_mutex);
 		/* Check again inside the mutex. */
 		if (!rscreen->gpu_load_thread)
 			rscreen->gpu_load_thread =
-				pipe_thread_create(r600_gpu_load_thread, rscreen);
+				u_thread_create(r600_gpu_load_thread, rscreen);
 		mtx_unlock(&rscreen->gpu_load_mutex);
 	}
 
 	unsigned busy = p_atomic_read(&rscreen->mmio_counters.array[busy_index]);
 	unsigned idle = p_atomic_read(&rscreen->mmio_counters.array[busy_index + 1]);
 
 	return busy | ((uint64_t)idle << 32);
 }
 
 static unsigned r600_end_mmio_counter(struct r600_common_screen *rscreen,
diff --git a/src/gallium/drivers/rbug/rbug_core.c b/src/gallium/drivers/rbug/rbug_core.c
index d09c4b5..64c2d63 100644
--- a/src/gallium/drivers/rbug/rbug_core.c
+++ b/src/gallium/drivers/rbug/rbug_core.c
@@ -850,21 +850,21 @@ rbug_thread(void *void_tr_rbug)
 
 struct rbug_rbug *
 rbug_start(struct rbug_screen *rb_screen)
 {
    struct rbug_rbug *tr_rbug = CALLOC_STRUCT(rbug_rbug);
    if (!tr_rbug)
       return NULL;
 
    tr_rbug->rb_screen = rb_screen;
    tr_rbug->running = TRUE;
-   tr_rbug->thread = pipe_thread_create(rbug_thread, tr_rbug);
+   tr_rbug->thread = u_thread_create(rbug_thread, tr_rbug);
 
    return tr_rbug;
 }
 
 void
 rbug_stop(struct rbug_rbug *tr_rbug)
 {
    if (!tr_rbug)
       return;
 
diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c
index 47a715d..ef33942 100644
--- a/src/gallium/state_trackers/nine/nine_state.c
+++ b/src/gallium/state_trackers/nine/nine_state.c
@@ -156,21 +156,21 @@ nine_csmt_create( struct NineDevice9 *This )
     (void) mtx_init(&ctx->mutex_processed, mtx_plain);
     (void) mtx_init(&ctx->thread_running, mtx_plain);
     (void) mtx_init(&ctx->thread_resume, mtx_plain);
 
 #if DEBUG
     pipe_thread_setname("Main thread");
 #endif
 
     ctx->device = This;
 
-    ctx->worker = pipe_thread_create(nine_csmt_worker, ctx);
+    ctx->worker = u_thread_create(nine_csmt_worker, ctx);
     if (!ctx->worker) {
         nine_queue_delete(ctx->pool);
         FREE(ctx);
         return NULL;
     }
 
     DBG("Returning context %p\n", ctx);
 
     return ctx;
 }
diff --git a/src/gallium/tests/unit/pipe_barrier_test.c b/src/gallium/tests/unit/pipe_barrier_test.c
index f77f1e1..58ad7e2 100644
--- a/src/gallium/tests/unit/pipe_barrier_test.c
+++ b/src/gallium/tests/unit/pipe_barrier_test.c
@@ -106,21 +106,21 @@ int main(int argc, char *argv[])
 
    // Disable buffering
    setbuf(stdout, NULL);
 
    LOG("pipe_barrier_test starting\n");
 
    pipe_barrier_init(&barrier, NUM_THREADS);
 
    for (i = 0; i < NUM_THREADS; i++) {
       thread_ids[i] = i;
-      threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]);
+      threads[i] = u_thread_create(thread_function, (void *) &thread_ids[i]);
    }
 
    for (i = 0; i < NUM_THREADS; i++ ) {
       thrd_join(threads[i], NULL);
    }
 
    CHECK(p_atomic_read(&proceeded) == NUM_THREADS);
 
    pipe_barrier_destroy(&barrier);
 
-- 
2.9.3



More information about the mesa-dev mailing list