get qflight (maybe:) working with threads
This commit is contained in:
parent
4d9fb73b29
commit
c1c68830c5
|
@ -29,7 +29,11 @@
|
||||||
#ifndef __threads_h
|
#ifndef __threads_h
|
||||||
#define __threads_h
|
#define __threads_h
|
||||||
|
|
||||||
#ifdef __alpha
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREAD_H
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
extern pthread_mutex_t *my_mutex;
|
extern pthread_mutex_t *my_mutex;
|
||||||
#define LOCK pthread_mutex_lock (my_mutex)
|
#define LOCK pthread_mutex_lock (my_mutex)
|
||||||
|
@ -41,7 +45,7 @@ extern pthread_mutex_t *my_mutex;
|
||||||
|
|
||||||
extern int numthreads;
|
extern int numthreads;
|
||||||
|
|
||||||
typedef void (threadfunc_t) (void *);
|
typedef void *(threadfunc_t) (void *);
|
||||||
|
|
||||||
void InitThreads (void);
|
void InitThreads (void);
|
||||||
void RunThreadsOn (threadfunc_t func);
|
void RunThreadsOn (threadfunc_t func);
|
||||||
|
|
|
@ -3,6 +3,7 @@ AUTOMAKE_OPTIONS= foreign
|
||||||
QFLIGHT_LIBS=@QFLIGHT_LIBS@
|
QFLIGHT_LIBS=@QFLIGHT_LIBS@
|
||||||
QFLIGHT_DEPS=@QFLIGHT_DEPS@
|
QFLIGHT_DEPS=@QFLIGHT_DEPS@
|
||||||
QFLIGHT_INCS=@QFLIGHT_INCS@
|
QFLIGHT_INCS=@QFLIGHT_INCS@
|
||||||
|
PTHREAD_FLAGS=@PTHREAD_FLAGS@
|
||||||
|
|
||||||
INCLUDES= -I$(top_srcdir)/include $(QFLIGHT_INCS)
|
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_SOURCES= entities.c ltface.c options.c qflight.c threads.c trace.c
|
||||||
|
|
||||||
|
qflight_LDFLAGS= $(PTHREAD_FLAGS)
|
||||||
qflight_LDADD= $(QFLIGHT_LIBS)
|
qflight_LDADD= $(QFLIGHT_LIBS)
|
||||||
qflight_DEPENDENCIES= $(QFLIGHT_DEPS)
|
qflight_DEPENDENCIES= $(QFLIGHT_DEPS)
|
||||||
|
|
|
@ -92,7 +92,7 @@ GetFileSpace (int size)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void *
|
||||||
LightThread (void *junk)
|
LightThread (void *junk)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -102,7 +102,7 @@ LightThread (void *junk)
|
||||||
i = bspfileface++;
|
i = bspfileface++;
|
||||||
UNLOCK;
|
UNLOCK;
|
||||||
if (i >= bsp->numfaces)
|
if (i >= bsp->numfaces)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
LightFace (i);
|
LightFace (i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,12 +42,13 @@ static const char rcsid[] =
|
||||||
#ifdef HAVE_STRINGS_H
|
#ifdef HAVE_STRINGS_H
|
||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "QF/qtypes.h"
|
#include "QF/qtypes.h"
|
||||||
#include "QF/qendian.h"
|
#include "QF/qendian.h"
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
|
||||||
#ifdef __alpha
|
#ifdef HAVE_PTHREAD_H
|
||||||
int numthreads = 4;
|
int numthreads = 4;
|
||||||
pthread_mutex_t *my_mutex;
|
pthread_mutex_t *my_mutex;
|
||||||
#else
|
#else
|
||||||
|
@ -57,25 +58,25 @@ int numthreads = 1;
|
||||||
void
|
void
|
||||||
InitThreads (void)
|
InitThreads (void)
|
||||||
{
|
{
|
||||||
#ifdef __alpha
|
#ifdef HAVE_PTHREAD_H
|
||||||
pthread_mutexattr_t mattrib;
|
pthread_mutexattr_t mattrib;
|
||||||
|
|
||||||
my_mutex = malloc (sizeof (*my_mutex));
|
my_mutex = malloc (sizeof (*my_mutex));
|
||||||
if (pthread_mutexattr_create (&mattrib) == -1)
|
if (pthread_mutexattr_init (&mattrib) == -1)
|
||||||
fprintf (stderr, "pthread_mutex_attr_create failed");
|
fprintf (stderr, "pthread_mutex_attr_init failed");
|
||||||
if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
|
// if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
|
||||||
fprintf (stderr, "pthread_mutexattr_setkind_np failed");
|
// fprintf (stderr, "pthread_mutexattr_setkind_np failed");
|
||||||
if (pthread_mutex_init (my_mutex, mattrib) == -1)
|
if (pthread_mutex_init (my_mutex, &mattrib) == -1)
|
||||||
fprintf (stderr, "pthread_mutex_init failed");
|
fprintf (stderr, "pthread_mutex_init failed");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RunThreadsOn (threadfunc_t func)
|
RunThreadsOn (threadfunc_t *func)
|
||||||
{
|
{
|
||||||
#ifdef __alpha
|
#ifdef HAVE_PTHREAD_H
|
||||||
pthread_t work_threads[256];
|
pthread_t work_threads[256];
|
||||||
pthread_addr_t status;
|
void *status;
|
||||||
pthread_attr_t attrib;
|
pthread_attr_t attrib;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -84,15 +85,13 @@ RunThreadsOn (threadfunc_t func)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_attr_create (&attrib) == -1)
|
if (pthread_attr_init (&attrib) == -1)
|
||||||
fprintf (stderr, "pthread_attr_create failed");
|
fprintf (stderr, "pthread_attr_init failed");
|
||||||
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
|
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
|
||||||
fprintf (stderr, "pthread_attr_setstacksize failed");
|
fprintf (stderr, "pthread_attr_setstacksize failed");
|
||||||
|
|
||||||
for (i = 0; i < numthreads; i++) {
|
for (i = 0; i < numthreads; i++) {
|
||||||
if (pthread_create (&work_threads[i], attrib,
|
if (pthread_create (&work_threads[i], &attrib, func, (void *) i) == -1)
|
||||||
(pthread_startroutine_t) func,
|
|
||||||
(pthread_addr_t) i) == -1)
|
|
||||||
fprintf (stderr, "pthread_create failed");
|
fprintf (stderr, "pthread_create failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue