Skip to content

Commit 6032eeb

Browse files
committed
Fixed non-pthread platforms
1 parent 0d06698 commit 6032eeb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

unittest/unittest.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,33 @@
2222
#include <stdio.h>
2323
#include <math.h>
2424
#include <time.h>
25+
26+
#define USE_PTHREADS // Please change this to #undef USE_PTHREADS if your platform does not support pthread.h!
27+
// #undef USE_PTHREADS
28+
29+
#ifdef USE_PTHREADS
2530
#include <pthread.h>
31+
#else
32+
#define pthread_mutex_lock(ignore) // Fake implementation of pthread.
33+
#define pthread_mutex_unlock(ignore)
34+
#define pthread_mutex_t int
35+
#define PTHREAD_MUTEX_INITIALIZER 0
36+
#define pthread_t int
37+
#define pthread_join(ignore1, ignore2) 0
38+
#define pthread_create(ignore1, ignore2, func, context) func(context)
39+
#endif
2640

2741
#include "../mapcodelib/mapcoder.c"
2842
#include "../mapcodelib/mapcode_countrynames_short.h"
2943
#include "test_territories.c"
3044
#include "decode_test.h"
3145

3246
#define MAXLINESIZE 1024
47+
#ifdef USE_PTHREADS
3348
#define MAX_THREADS 16 // Optimal: not too much, approx. nr of cores * 2, better no more than 32.
34-
49+
#else
50+
#define MAX_THREADS 1
51+
#endif
3552

3653
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
3754
int nrErrors = 0;
@@ -563,6 +580,7 @@ void *execute_test_around(void *context) {
563580
return 0;
564581
}
565582

583+
566584
// test around all centers and corners of all territory rectangles
567585
int re_encode_tests() {
568586
int nrTests = 0;

0 commit comments

Comments
 (0)