mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
don't do threading if only 1 thread is used and add another state to
vstatus_t for better portal state checking
This commit is contained in:
parent
528eec1e12
commit
ee61eaebbb
3 changed files with 29 additions and 22 deletions
|
@ -36,8 +36,8 @@
|
|||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
extern pthread_mutex_t *my_mutex;
|
||||
#define LOCK pthread_mutex_lock (my_mutex)
|
||||
#define UNLOCK pthread_mutex_unlock (my_mutex)
|
||||
#define LOCK do {if (options.threads > 1) pthread_mutex_lock (my_mutex); } while (0)
|
||||
#define UNLOCK do {if (options.threads > 1) pthread_mutex_unlock (my_mutex); } while (0)
|
||||
#else
|
||||
#define LOCK
|
||||
#define UNLOCK
|
||||
|
@ -62,6 +62,7 @@ typedef struct {
|
|||
|
||||
typedef enum {
|
||||
stat_none,
|
||||
stat_selected,
|
||||
stat_working,
|
||||
stat_done
|
||||
} vstatus_t;
|
||||
|
|
|
@ -357,9 +357,11 @@ PortalFlow (portal_t *p)
|
|||
{
|
||||
threaddata_t data;
|
||||
|
||||
if (p->status != stat_working)
|
||||
LOCK;
|
||||
if (p->status != stat_selected)
|
||||
Sys_Error ("PortalFlow: reflowed");
|
||||
p->status = stat_working;
|
||||
UNLOCK;
|
||||
|
||||
p->visbits = calloc (1, bitbytes);
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ GetNextPortal (void)
|
|||
}
|
||||
|
||||
if (p)
|
||||
p->status = stat_working;
|
||||
p->status = stat_selected;
|
||||
|
||||
UNLOCK;
|
||||
|
||||
|
@ -388,26 +388,30 @@ CalcPortalVis (void)
|
|||
void *status;
|
||||
pthread_attr_t attrib;
|
||||
|
||||
my_mutex = malloc (sizeof (*my_mutex));
|
||||
if (pthread_mutex_init (my_mutex, 0) == -1)
|
||||
Sys_Error ("pthread_mutex_init failed");
|
||||
if (pthread_attr_init (&attrib) == -1)
|
||||
Sys_Error ("pthread_attr_create failed");
|
||||
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
|
||||
Sys_Error ("pthread_attr_setstacksize failed");
|
||||
for (i = 0; i < options.threads; i++) {
|
||||
if (pthread_create (&work_threads[i], &attrib, LeafThread,
|
||||
(void *) i) == -1)
|
||||
Sys_Error ("pthread_create failed");
|
||||
}
|
||||
if (options.threads > 1) {
|
||||
my_mutex = malloc (sizeof (*my_mutex));
|
||||
if (pthread_mutex_init (my_mutex, 0) == -1)
|
||||
Sys_Error ("pthread_mutex_init failed");
|
||||
if (pthread_attr_init (&attrib) == -1)
|
||||
Sys_Error ("pthread_attr_create failed");
|
||||
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
|
||||
Sys_Error ("pthread_attr_setstacksize failed");
|
||||
for (i = 0; i < options.threads; i++) {
|
||||
if (pthread_create (&work_threads[i], &attrib, LeafThread,
|
||||
(void *) 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");
|
||||
}
|
||||
for (i = 0; i < options.threads; i++) {
|
||||
if (pthread_join (work_threads[i], &status) == -1)
|
||||
Sys_Error ("pthread_join failed");
|
||||
}
|
||||
|
||||
if (pthread_mutex_destroy (my_mutex) == -1)
|
||||
Sys_Error ("pthread_mutex_destroy failed");
|
||||
if (pthread_mutex_destroy (my_mutex) == -1)
|
||||
Sys_Error ("pthread_mutex_destroy failed");
|
||||
} else {
|
||||
LeafThread (0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
LeafThread (0);
|
||||
|
|
Loading…
Reference in a new issue