diff --git a/flatgeobuf.cpp b/flatgeobuf.cpp index 0958c746..88375f75 100644 --- a/flatgeobuf.cpp +++ b/flatgeobuf.cpp @@ -302,7 +302,7 @@ void fgbRunQueue() { } for (size_t i = 0; i < CPUS; i++) { - if (pthread_create(&pthreads[i], NULL, fgb_run_parse_feature, &qra[i]) != 0) { + if (pthread_create_wrap(&pthreads[i], NULL, fgb_run_parse_feature, &qra[i]) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } @@ -396,4 +396,4 @@ void parse_flatgeobuf(std::vector *sst, const char * } fgbRunQueue(); -} \ No newline at end of file +} diff --git a/geobuf.cpp b/geobuf.cpp index 65b15991..44c8be1e 100644 --- a/geobuf.cpp +++ b/geobuf.cpp @@ -464,7 +464,7 @@ void runQueue() { } for (size_t i = 0; i < CPUS; i++) { - if (pthread_create(&pthreads[i], NULL, run_parse_feature, &qra[i]) != 0) { + if (pthread_create_wrap(&pthreads[i], NULL, run_parse_feature, &qra[i]) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } diff --git a/main.cpp b/main.cpp index 5421b6dc..408fe2dc 100644 --- a/main.cpp +++ b/main.cpp @@ -468,7 +468,7 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const } for (size_t i = 0; i < CPUS; i++) { - if (pthread_create(&pthreads[i], NULL, run_parse_json, &pja[i]) != 0) { + if (pthread_create_wrap(&pthreads[i], NULL, run_parse_json, &pja[i]) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } @@ -682,7 +682,7 @@ void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::ato rpa->want_dist = want_dist; rpa->filters = filters; - if (pthread_create(parallel_parser, NULL, run_read_parallel, rpa) != 0) { + if (pthread_create_wrap(parallel_parser, NULL, run_read_parallel, rpa) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } @@ -877,7 +877,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split } for (size_t a = 0; a < CPUS; a++) { - if (pthread_create(&pthreads[a], NULL, run_sort, &args[a]) != 0) { + if (pthread_create_wrap(&pthreads[a], NULL, run_sort, &args[a]) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } @@ -2789,6 +2789,7 @@ int main(int argc, char **argv) { {"check-polygons", no_argument, &additional[A_DEBUG_POLYGON], 1}, {"no-polygon-splitting", no_argument, &prevent[P_POLYGON_SPLIT], 1}, {"prefer-radix-sort", no_argument, &additional[A_PREFER_RADIX_SORT], 1}, + {"single-threaded", no_argument, &prevent[P_THREADS], 1}, {"help", no_argument, 0, 'H'}, {0, 0, 0, 0}, @@ -3451,3 +3452,16 @@ bool progress_time() { return false; } } + +static void *donothing(void *arg) { + return arg; +} + +int pthread_create_wrap(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { + if (prevent[P_THREADS]) { + void *ret = start_routine(arg); + return pthread_create(thread, attr, donothing, ret); + } else { + return pthread_create(thread, attr, start_routine, arg); + } +} diff --git a/main.hpp b/main.hpp index 1232081a..7c767cbd 100644 --- a/main.hpp +++ b/main.hpp @@ -72,4 +72,6 @@ bool progress_time(); #define MAX_ZOOM 24 +int pthread_create_wrap(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); + #endif diff --git a/options.hpp b/options.hpp index b0952b57..ed85d887 100644 --- a/options.hpp +++ b/options.hpp @@ -44,6 +44,7 @@ #define P_REVERSE_SOURCE_POLYGON_WINDING ((int) 'W') #define P_EMPTY_CSV_COLUMNS ((int) 'e') #define P_BASEZOOM_ABOVE_MAXZOOM ((int) 'b') +#define P_THREADS ((int) 'T') extern int prevent[256]; extern int additional[256]; diff --git a/text.cpp b/text.cpp index bebc64cc..d55ca32f 100644 --- a/text.cpp +++ b/text.cpp @@ -141,6 +141,10 @@ std::string format_commandline(int argc, char **argv) { std::string out; for (int i = 0; i < argc; i++) { + if (std::string(argv[i]) == "-pT") { + continue; + } + bool need_quote = false; for (char *cp = argv[i]; *cp != '\0'; cp++) { if (!isalpha(*cp) && !isdigit(*cp) && diff --git a/tile.cpp b/tile.cpp index e61ff53b..369c26d4 100644 --- a/tile.cpp +++ b/tile.cpp @@ -2225,8 +2225,8 @@ long long write_tile(FILE *geoms, std::atomic *geompos_in, char *meta args[i].shared_nodes = &shared_nodes; if (tasks > 1) { - if (pthread_create(&pthreads[i], NULL, partial_feature_worker, &args[i]) != 0) { - perror("pthread_create"); + if (pthread_create_wrap(&pthreads[i], NULL, partial_feature_worker, &args[i]) != 0) { + perror("pthread_create_wrap"); exit(EXIT_FAILURE); } } else { @@ -2980,8 +2980,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo args[thread].still_dropping = false; args[thread].strategy = &strategy; - if (pthread_create(&pthreads[thread], NULL, run_thread, &args[thread]) != 0) { - perror("pthread_create"); + if (pthread_create_wrap(&pthreads[thread], NULL, run_thread, &args[thread]) != 0) { + perror("pthread_create_wrap"); exit(EXIT_FAILURE); } }