mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 18:01:15 +00:00
get qflight (maybe:) working with threads
This commit is contained in:
parent
4d9fb73b29
commit
c1c68830c5
4 changed files with 24 additions and 19 deletions
|
@ -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 <pthread.h>
|
||||
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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -42,12 +42,13 @@ static const char rcsid[] =
|
|||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue