From 3bb87227ec440222ff3af536dd76ed392555de9c Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 19 Oct 2015 13:32:02 -0700 Subject: [PATCH] Locking for map center --- tile.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tile.cc b/tile.cc index 78c5666..58d3e3e 100644 --- a/tile.cc +++ b/tile.cc @@ -891,11 +891,21 @@ void *run_thread(void *vargs) { // return z - 1; } + if (pthread_mutex_lock(&db_lock) != 0) { + perror("pthread_mutex_lock"); + exit(EXIT_FAILURE); + } + if (z == arg->maxzoom && len > *arg->most) { *arg->midx = x; *arg->midy = y; *arg->most = len; } + + if (pthread_mutex_unlock(&db_lock) != 0) { + perror("pthread_mutex_unlock"); + exit(EXIT_FAILURE); + } } if (munmap(geomstart, arg->geom_size[j]) != 0) { @@ -1010,9 +1020,9 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo args[thread].stringpool = stringpool; args[thread].min_detail = min_detail; args[thread].basezoom = maxzoom; // XXX rename? - args[thread].file_keys = file_keys; // XXX locking + args[thread].file_keys = file_keys; // locked with var_lock args[thread].layernames = layernames; - args[thread].outdb = outdb; // XXX locking + args[thread].outdb = outdb; // locked with db_lock args[thread].droprate = droprate; args[thread].buffer = buffer; args[thread].fname = fname; @@ -1029,13 +1039,13 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo args[thread].geomfd = geomfd; args[thread].geom_size = geom_size; - args[thread].midx = midx; // XXX locking - args[thread].midy = midy; // XXX locking + args[thread].midx = midx; // locked with var_lock + args[thread].midy = midy; // locked with var_lock args[thread].maxzoom = maxzoom; args[thread].minzoom = minzoom; args[thread].full_detail = full_detail; args[thread].low_detail = low_detail; - args[thread].most = &most; // XXX locking + args[thread].most = &most; // locked with var_lock args[thread].tasks = dispatches[thread].tasks;