diff --git a/tools/qflight/include/threads.h b/tools/qflight/include/threads.h index f92452263..a794e614b 100644 --- a/tools/qflight/include/threads.h +++ b/tools/qflight/include/threads.h @@ -29,7 +29,11 @@ #ifndef __threads_h #define __threads_h -#ifdef __alpha +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_PTHREAD_H #include extern pthread_mutex_t *my_mutex; #define LOCK pthread_mutex_lock (my_mutex) @@ -41,7 +45,7 @@ extern pthread_mutex_t *my_mutex; extern int numthreads; -typedef void (threadfunc_t) (void *); +typedef void *(threadfunc_t) (void *); void InitThreads (void); void RunThreadsOn (threadfunc_t func); diff --git a/tools/qflight/source/Makefile.am b/tools/qflight/source/Makefile.am index 07d6a5770..2396caec1 100644 --- a/tools/qflight/source/Makefile.am +++ b/tools/qflight/source/Makefile.am @@ -3,6 +3,7 @@ AUTOMAKE_OPTIONS= foreign QFLIGHT_LIBS=@QFLIGHT_LIBS@ QFLIGHT_DEPS=@QFLIGHT_DEPS@ QFLIGHT_INCS=@QFLIGHT_INCS@ +PTHREAD_FLAGS=@PTHREAD_FLAGS@ INCLUDES= -I$(top_srcdir)/include $(QFLIGHT_INCS) @@ -17,5 +18,6 @@ EXTRA_PROGRAMS= qflight qflight_SOURCES= entities.c ltface.c options.c qflight.c threads.c trace.c +qflight_LDFLAGS= $(PTHREAD_FLAGS) qflight_LDADD= $(QFLIGHT_LIBS) qflight_DEPENDENCIES= $(QFLIGHT_DEPS) diff --git a/tools/qflight/source/qflight.c b/tools/qflight/source/qflight.c index 5938ee54a..a5d6ab3bf 100644 --- a/tools/qflight/source/qflight.c +++ b/tools/qflight/source/qflight.c @@ -92,7 +92,7 @@ GetFileSpace (int size) return buf; } -void +void * LightThread (void *junk) { int i; @@ -102,7 +102,7 @@ LightThread (void *junk) i = bspfileface++; UNLOCK; if (i >= bsp->numfaces) - return; + return 0; LightFace (i); } diff --git a/tools/qflight/source/threads.c b/tools/qflight/source/threads.c index ce5de8448..54a0d05d8 100644 --- a/tools/qflight/source/threads.c +++ b/tools/qflight/source/threads.c @@ -42,12 +42,13 @@ static const char rcsid[] = #ifdef HAVE_STRINGS_H # include #endif +#include #include "QF/qtypes.h" #include "QF/qendian.h" #include "threads.h" -#ifdef __alpha +#ifdef HAVE_PTHREAD_H int numthreads = 4; pthread_mutex_t *my_mutex; #else @@ -57,25 +58,25 @@ int numthreads = 1; void InitThreads (void) { -#ifdef __alpha +#ifdef HAVE_PTHREAD_H pthread_mutexattr_t mattrib; my_mutex = malloc (sizeof (*my_mutex)); - if (pthread_mutexattr_create (&mattrib) == -1) - fprintf (stderr, "pthread_mutex_attr_create failed"); - if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1) - fprintf (stderr, "pthread_mutexattr_setkind_np failed"); - if (pthread_mutex_init (my_mutex, mattrib) == -1) + if (pthread_mutexattr_init (&mattrib) == -1) + fprintf (stderr, "pthread_mutex_attr_init failed"); +// if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1) +// fprintf (stderr, "pthread_mutexattr_setkind_np failed"); + if (pthread_mutex_init (my_mutex, &mattrib) == -1) fprintf (stderr, "pthread_mutex_init failed"); #endif } void -RunThreadsOn (threadfunc_t func) +RunThreadsOn (threadfunc_t *func) { -#ifdef __alpha +#ifdef HAVE_PTHREAD_H pthread_t work_threads[256]; - pthread_addr_t status; + void *status; pthread_attr_t attrib; int i; @@ -84,15 +85,13 @@ RunThreadsOn (threadfunc_t func) return; } - if (pthread_attr_create (&attrib) == -1) - fprintf (stderr, "pthread_attr_create failed"); + if (pthread_attr_init (&attrib) == -1) + fprintf (stderr, "pthread_attr_init failed"); if (pthread_attr_setstacksize (&attrib, 0x100000) == -1) fprintf (stderr, "pthread_attr_setstacksize failed"); for (i = 0; i < numthreads; i++) { - if (pthread_create (&work_threads[i], attrib, - (pthread_startroutine_t) func, - (pthread_addr_t) i) == -1) + if (pthread_create (&work_threads[i], &attrib, func, (void *) i) == -1) fprintf (stderr, "pthread_create failed"); }