get qfvis working, including pthreads

This commit is contained in:
Bill Currie 2002-09-12 06:48:05 +00:00
parent c2053c4d07
commit 774b0adc2b
4 changed files with 37 additions and 29 deletions

View file

@ -145,12 +145,12 @@ AC_CHECK_HEADERS(
dmedia/cdaudio.h dpmi.h dsound.h errno.h execinfo.h fcntl.h io.h \
libc.h limits.h linux/cdrom.h linux/joystick.h linux/soundcard.h \
machine/soundcard.h malloc.h math.h mgraph.h _mingw.h netdb.h \
netinet/in.h process.h pwd.h rpc/types.h setjmp.h signal.h stdarg.h \
stdio.h stdlib.h string.h strings.h sys/asoundlib.h sys/audioio.h \
sys/filio.h sys/ioctl.h sys/io.h sys/ipc.h sys/mman.h sys/param.h \
sys/poll.h sys/shm.h sys/signal.h sys/socket.h sys/soundcard.h \
sys/stat.h sys/time.h sys/types.h sys/uio.h termios.h time.h unistd.h \
vgakeyboard.h vgamouse.h windows.h winsock.h
netinet/in.h process.h pthread.h pwd.h rpc/types.h setjmp.h signal.h \
stdarg.h stdio.h stdlib.h string.h strings.h sys/asoundlib.h \
sys/audioio.h sys/filio.h sys/ioctl.h sys/io.h sys/ipc.h sys/mman.h \
sys/param.h sys/poll.h sys/shm.h sys/signal.h sys/socket.h \
sys/soundcard.h sys/stat.h sys/time.h sys/types.h sys/uio.h termios.h \
time.h unistd.h vgakeyboard.h vgamouse.h windows.h winsock.h
)
if test "x$mingw" = xyes; then
AC_MSG_CHECKING(for fnmatch.h)
@ -160,6 +160,11 @@ else
AC_CHECK_HEADERS(fnmatch.h)
fi
if test "x$ac_cv_header_pthread_h" = "xyes"; then
PTHREAD_FLAGS=-pthread
fi
AC_SUBST(PTHREAD_FLAGS)
dnl ==================================================================
dnl Checks for typedefs, structures, and compiler characteristics
dnl ==================================================================

View file

@ -3,6 +3,7 @@ AUTOMAKE_OPTIONS= foreign
QFVIS_LIBS=@QFVIS_LIBS@
QFVIS_DEPS=@QFVIS_DEPS@
QFVIS_INCS=@QFVIS_INCS@
PTHREAD_FLAGS=@PTHREAD_FLAGS@
INCLUDES= -I$(top_srcdir)/include $(QFVIS_INCS)
@ -10,5 +11,6 @@ bin_PROGRAMS= qfvis
qfvis_SOURCES= flow.c options.c qfvis.c soundphs.c
qfvis_LDFLAGS= $(PTHREAD_FLAGS)
qfvis_LDADD= $(QFVIS_LIBS)
qfvis_DEPENDENCIES= $(QFVIS_DEPS)

View file

@ -94,6 +94,7 @@ DecodeArgs (int argc, char **argv)
options.verbosity = 0;
options.bspfile = NULL;
options.threads = 1;
while ((c = getopt_long (argc, argv, short_options, long_options, 0))
!= EOF) {

View file

@ -46,6 +46,9 @@ static const char rcsid[] =
#include <getopt.h>
#include <errno.h>
#include <stdlib.h>
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#include "QF/cmd.h"
#include "QF/bspfile.h"
@ -60,11 +63,8 @@ static const char rcsid[] =
#define MAX_THREADS 4
#ifdef __alpha
#ifdef HAVE_PTHREAD_H
pthread_mutex_t *my_mutex;
int numthreads = 4;
#else
int numthreads = 1;
#endif
options_t options;
@ -358,11 +358,7 @@ GetNextPortal (void)
return p;
}
#ifdef __alpha
pthread_addr_t LeafThread (pthread_addr_t thread)
#else
void *LeafThread (int thread)
#endif
void *LeafThread (void *thread)
{
portal_t *portal;
@ -491,33 +487,32 @@ CalcPortalVis (void)
}
leafon = 0;
#ifdef __alpha
#ifdef HAVE_PTHREAD_H
{
pthread_t work_threads[MAX_THREADS];
pthread_addr_t status;
void *status;
pthread_attr_t attrib;
pthread_mutexattr_t mattrib;
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");
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_settype (&mattrib, PTHREAD_MUTEX_ADAPTIVE_NP) == -1)
// fprintf (stderr, "pthread_mutexattr_setkind_np failed");
if (pthread_mutex_init (my_mutex, &mattrib) == -1)
fprintf (stderr, "pthread_mutex_init failed");
if (pthread_attr_create (&attrib) == -1)
if (pthread_attr_init (&attrib) == -1)
fprintf (stderr, "pthread_attr_create 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, LeafThread,
(pthread_addr_t) i) == -1)
for (i = 0; i < options.threads; i++) {
if (pthread_create (&work_threads[i], &attrib, LeafThread,
(void *) i) == -1)
fprintf (stderr, "pthread_create failed");
}
for (i = 0; i < numthreads; i++) {
for (i = 0; i < options.threads; i++) {
if (pthread_join (work_threads[i], &status) == -1)
fprintf (stderr, "pthread_join failed");
}
@ -526,7 +521,7 @@ CalcPortalVis (void)
fprintf (stderr, "pthread_mutex_destroy failed");
}
#else
LeafThread (0);
LeafThread (0);
#endif
if (options.verbosity >= 0) {
@ -847,6 +842,7 @@ int
main (int argc, char **argv)
{
double start, stop;
dstring_t *portalfile = dstring_new ();
start = Sys_DoubleTime ();
@ -865,7 +861,11 @@ main (int argc, char **argv)
LoadBSPFile (options.bspfile);
// LoadPortals (portalfile);
portalfile->size = strlen (options.bspfile) + 1;
dstring_adjust (portalfile);
COM_StripExtension (options.bspfile, portalfile->str);
dstring_appendstr (portalfile, ".prt");
LoadPortals (portalfile->str);
// uncompressed = malloc (bitbytes * portalleafs);
// memset (uncompressed, 0, bitbytes * portalleafs);