Removed POSIX dependence.

This commit is contained in:
Cubitect 2018-08-01 17:51:17 +02:00
parent 5127be24a4
commit f3243ca3fc
5 changed files with 81 additions and 20 deletions

View File

@ -8,6 +8,7 @@
#include "finders.h"
#include "generator.h"
#define SEED_BUF_LEN 0x10000
@ -16,7 +17,12 @@ struct compactinfo_t
int64_t seedStart, seedEnd;
};
void *searchCompactBiomesThread(void *data)
#ifdef USE_PTHREAD
static void *searchCompactBiomesThread(void *data)
#else
static DWORD WINAPI searchCompactBiomesThread(LPVOID data)
#endif
{
struct compactinfo_t info = *(struct compactinfo_t *)data;
@ -53,7 +59,10 @@ void *searchCompactBiomesThread(void *data)
free(seeds);
return NULL;
#ifdef USE_PTHREAD
pthread_exit(NULL);
#endif
return 0;
}
@ -70,7 +79,7 @@ int main(int argc, char *argv[])
printf("Starting search through seeds %"PRId64 " to %"PRId64", using %u threads.\n", seedStart, seedEnd, threads);
pthread_t threadID[threads];
thread_id_t threadID[threads];
struct compactinfo_t info[threads];
for (t = 0; t < threads; t++)
@ -81,6 +90,8 @@ int main(int argc, char *argv[])
}
info[threads-1].seedEnd = seedEnd;
#ifdef USE_PTHREAD
for (t = 0; t < threads; t++)
{
pthread_create(&threadID[t], NULL, searchCompactBiomesThread, (void*)&info[t]);
@ -91,6 +102,17 @@ int main(int argc, char *argv[])
pthread_join(threadID[t], NULL);
}
#else
for (t = 0; t < threads; t++)
{
threadID[t] = CreateThread(NULL, 0, searchCompactBiomesThread, (LPVOID)&info[t], 0, NULL);
}
WaitForMultipleObjects(threads, threadID, TRUE, INFINITE);
#endif
return 0;
}

View File

@ -2,7 +2,6 @@
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <math.h>
@ -488,8 +487,11 @@ int countBlocksInSpawnRange(Pos p[4], const int ax, const int ay, const int az)
return best;
}
#ifdef USE_PTHREAD
static void *search4QuadBasesThread(void *data)
#else
static DWORD WINAPI search4QuadBasesThread(LPVOID data)
#endif
{
quad_threadinfo_t info = *(quad_threadinfo_t*)data;
@ -595,14 +597,17 @@ static void *search4QuadBasesThread(void *data)
fclose(fp);
free(lowerBits);
return NULL;
#ifdef USE_PTHREAD
pthread_exit(NULL);
#endif
return 0;
}
void search4QuadBases(const char *fnam, const int threads,
const StructureConfig structureConfig, const int quality)
{
pthread_t threadID[threads];
thread_id_t threadID[threads];
quad_threadinfo_t info[threads];
int64_t t;
@ -616,6 +621,9 @@ void search4QuadBases(const char *fnam, const int threads,
info[t].sconf = structureConfig;
}
#ifdef USE_PTHREAD
for (t = 0; t < threads; t++)
{
pthread_create(&threadID[t], NULL, search4QuadBasesThread, (void*)&info[t]);
@ -626,6 +634,19 @@ void search4QuadBases(const char *fnam, const int threads,
pthread_join(threadID[t], NULL);
}
#else
for (t = 0; t < threads; t++)
{
threadID[t] = CreateThread(NULL, 0, search4QuadBasesThread, (LPVOID)&info[t], 0, NULL);
}
WaitForMultipleObjects(threads, threadID, TRUE, INFINITE);
#endif
// merge thread parts
char fnamThread[256];

View File

@ -4,9 +4,21 @@
#include "generator.h"
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#ifdef _WIN32
#include <Windows.h>
typedef HANDLE thread_id_t;
#else
#define USE_PTHREAD
#include <pthread.h>
typedef pthread_t thread_id_t;
#endif
#define SEED_BASE_MAX (1LL << 48)
#define PI 3.141592653589793

View File

@ -46,7 +46,7 @@ enum BiomeType
enum BiomeTempCategory
{
Oceanic, Warm, Lush, Cold, Freezing, Unknown
Oceanic, Warm, Lush, Cold, Freezing, UnknownTemp
};

View File

@ -1,7 +1,13 @@
CC = gcc
LDFLAGS = -lm -pthread
override LDFLAGS = -lm
override CFLAGS += -Wall -fwrapv -march=native
ifeq ($(OS),Windows_NT)
override CFLAGS += -D_WIN32
else
override LDFLAGS += -lX11 -pthread
endif
.PHONY : all debug clean
all: CFLAGS += -O3