Thread safety fix for decoding quadkeys to coordinates

This commit is contained in:
Eric Fischer
2018-05-18 14:45:03 -07:00
parent 5494b7da3d
commit 02cb3a3fb8
+4 -3
View File
@@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <atomic>
#include "projection.hpp" #include "projection.hpp"
struct projection projections[] = { struct projection projections[] = {
@@ -107,11 +108,11 @@ unsigned long long encode(unsigned int wx, unsigned int wy) {
return out; return out;
} }
static unsigned char decodex[256]; static std::atomic<unsigned char> decodex[256];
static unsigned char decodey[256]; static std::atomic<unsigned char> decodey[256];
void decode(unsigned long long index, unsigned *wx, unsigned *wy) { void decode(unsigned long long index, unsigned *wx, unsigned *wy) {
static int initialized = 0; static std::atomic<int> initialized(0);
if (!initialized) { if (!initialized) {
for (size_t ix = 0; ix < 256; ix++) { for (size_t ix = 0; ix < 256; ix++) {
size_t xx = 0, yy = 0; size_t xx = 0, yy = 0;