Move the LeafThread setup to its own generic function.

This is for threading base-vis.
This commit is contained in:
Bill Currie 2013-03-18 21:11:46 +09:00
parent cb096c601d
commit 7e40981dcd

View file

@ -467,6 +467,41 @@ WatchThread (void *_thread)
} }
#endif #endif
static void
RunThreads (void *(*thread_func) (void *))
{
#ifdef USE_PTHREADS
pthread_t work_threads[MAX_THREADS + 1];
void *status;
int i;
if (options.threads > 1) {
working = calloc (options.threads, sizeof (int));
for (i = 0; i < options.threads; i++) {
if (pthread_create (&work_threads[i], &threads_attrib,
thread_func, (void *) (intptr_t) i) == -1)
Sys_Error ("pthread_create failed");
}
if (pthread_create (&work_threads[i], &threads_attrib,
WatchThread, (void *) (intptr_t) i) == -1)
Sys_Error ("pthread_create failed");
for (i = 0; i < options.threads; i++) {
if (pthread_join (work_threads[i], &status) == -1)
Sys_Error ("pthread_join failed");
}
if (pthread_join (work_threads[i], &status) == -1)
Sys_Error ("pthread_join failed");
free (working);
} else {
thread_func (0);
}
#else
LeafThread (0);
#endif
}
static int static int
CompressRow (byte *vis, byte *dest) CompressRow (byte *vis, byte *dest)
{ {
@ -574,38 +609,7 @@ CalcPortalVis (void)
} }
return; return;
} }
RunThreads (LeafThread);
#ifdef USE_PTHREADS
{
pthread_t work_threads[MAX_THREADS + 1];
void *status;
if (options.threads > 1) {
working = calloc (options.threads, sizeof (int));
for (i = 0; i < options.threads; i++) {
if (pthread_create (&work_threads[i], &threads_attrib,
LeafThread, (void *) (intptr_t) i) == -1)
Sys_Error ("pthread_create failed");
}
if (pthread_create (&work_threads[i], &threads_attrib,
WatchThread, (void *) (intptr_t) i) == -1)
Sys_Error ("pthread_create failed");
for (i = 0; i < options.threads; i++) {
if (pthread_join (work_threads[i], &status) == -1)
Sys_Error ("pthread_join failed");
}
if (pthread_join (work_threads[i], &status) == -1)
Sys_Error ("pthread_join failed");
free (working);
} else {
LeafThread (0);
}
}
#else
LeafThread (0);
#endif
if (options.verbosity > 0) { if (options.verbosity > 0) {
printf ("portalcheck: %i portaltest: %i portalpass: %i\n", printf ("portalcheck: %i portaltest: %i portalpass: %i\n",