From 1fa3a3e85ae9ca247b61cd6bede0948dec0a641a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:46:20 +0200 Subject: [PATCH 1/4] add a few fixes for gcc fixes #437 --- include/mbgl/text/collision.hpp | 3 ++- include/mbgl/text/types.hpp | 2 +- include/mbgl/util/threadpool.hpp | 1 + include/mbgl/util/utf.hpp | 6 ++---- include/mbgl/util/vec.hpp | 2 +- src/text/collision.cpp | 4 ++-- src/text/rotation_range.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/mbgl/text/collision.hpp b/include/mbgl/text/collision.hpp index 7e65e979d..8eec30f21 100644 --- a/include/mbgl/text/collision.hpp +++ b/include/mbgl/text/collision.hpp @@ -5,8 +5,9 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" +#ifdef __clang__ #pragma GCC diagnostic ignored "-Wdeprecated-register" -#ifndef __clang__ +#else #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif diff --git a/include/mbgl/text/types.hpp b/include/mbgl/text/types.hpp index e2539bff6..dbb483ea8 100644 --- a/include/mbgl/text/types.hpp +++ b/include/mbgl/text/types.hpp @@ -101,7 +101,7 @@ struct PlacementProperty { : zoom(zoom), rotationRange(rotationRange) {} inline operator bool() const { - return !isnan(zoom) && zoom != std::numeric_limits::infinity() && + return !std::isnan(zoom) && zoom != std::numeric_limits::infinity() && rotationRange[0] != rotationRange[1]; } diff --git a/include/mbgl/util/threadpool.hpp b/include/mbgl/util/threadpool.hpp index 497d4e308..ff913ec50 100644 --- a/include/mbgl/util/threadpool.hpp +++ b/include/mbgl/util/threadpool.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace mbgl { namespace util { diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index 5dfc4ad2d..fa21df74c 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -4,11 +4,9 @@ #include // g++/libstdc++ is missing c++11 codecvt support -#ifdef __linux__ -#pragma GCC diagnostic push #ifndef __clang__ +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#endif #include #pragma GCC diagnostic pop #else @@ -20,7 +18,7 @@ namespace mbgl { namespace util { -#ifdef __linux__ +#ifndef __clang__ class utf8_to_utf32 { public: diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp index 0b9bf63d5..a5fbee477 100644 --- a/include/mbgl/util/vec.hpp +++ b/include/mbgl/util/vec.hpp @@ -71,7 +71,7 @@ struct vec2 { template::has_quiet_NaN, int>::type = 0> inline operator bool() const { - return !isnan(x) && !isnan(y); + return !std::isnan(x) && !std::isnan(y); } template::has_quiet_NaN, int>::type = 0> diff --git a/src/text/collision.cpp b/src/text/collision.cpp index 89e91d684..6326bea82 100644 --- a/src/text/collision.cpp +++ b/src/text/collision.cpp @@ -166,10 +166,10 @@ float Collision::getPlacementScale(const GlyphBoxes &glyphs, float minPlacementS float s4 = (ob.br.y - nb.tl.y + padding) / (na.y - oa.y); // scale at which new box is to the bottom of old box - if (isnan(s1) || isnan(s2)) { + if (std::isnan(s1) || std::isnan(s2)) { s1 = s2 = 1; } - if (isnan(s3) || isnan(s4)) { + if (std::isnan(s3) || std::isnan(s4)) { s3 = s4 = 1; } diff --git a/src/text/rotation_range.cpp b/src/text/rotation_range.cpp index 3ebdfe91c..664ea9c70 100644 --- a/src/text/rotation_range.cpp +++ b/src/text/rotation_range.cpp @@ -95,7 +95,7 @@ rotatingRotatingCollisions(const CollisionRect &a, const CollisionRect &b, std::vector f; for (size_t i = 0; i < c.size(); i++) { // Check if they are close enough to collide - if (!isnan(c[i]) && d_sq <= e[i]) { + if (!std::isnan(c[i]) && d_sq <= e[i]) { // So far, angles have been calulated as relative to the vector // between anchors. // Convert the angles to angles from north. From 6730beec0e7d515339a82e80263b9323c665f77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:51:10 +0200 Subject: [PATCH 2/4] remove unused threadpool class --- include/mbgl/util/threadpool.hpp | 46 --------------------------- src/util/threadpool.cpp | 54 -------------------------------- 2 files changed, 100 deletions(-) delete mode 100644 include/mbgl/util/threadpool.hpp delete mode 100644 src/util/threadpool.cpp diff --git a/include/mbgl/util/threadpool.hpp b/include/mbgl/util/threadpool.hpp deleted file mode 100644 index ff913ec50..000000000 --- a/include/mbgl/util/threadpool.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MBGL_UTIL_THREADPOOL -#define MBGL_UTIL_THREADPOOL - -#include -#include -#include -#include - -namespace mbgl { -namespace util { - -class Threadpool { -private: - class Worker { - public: - Worker(Threadpool& pool); - ~Worker(); - static void *loop(void *ptr); - - private: - Threadpool& pool; - pthread_t thread; - }; - -public: - Threadpool(int max_workers = 4); - typedef void (*Callback)(void *); - void add(Callback callback, void *data); - -private: - typedef std::pair Task; - const int max_workers; - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t condition = PTHREAD_COND_INITIALIZER; - std::forward_list workers; - int worker_count = 0; - std::queue tasks; -}; - -extern std::unique_ptr threadpool; - -} -} - -#endif - diff --git a/src/util/threadpool.cpp b/src/util/threadpool.cpp deleted file mode 100644 index f19032ee0..000000000 --- a/src/util/threadpool.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -using namespace mbgl::util; - -std::unique_ptr mbgl::util::threadpool = std::make_unique(std::thread::hardware_concurrency()); - -Threadpool::Threadpool(int max_workers) - : max_workers(max_workers) { -} - -void Threadpool::add(Callback callback, void *data) { - if (worker_count < max_workers) { - worker_count++; - workers.emplace_front(*this); - } - - pthread_mutex_lock(&mutex); - tasks.push(std::make_pair(callback, data)); - pthread_mutex_unlock(&mutex); - pthread_cond_signal(&condition); -} - -Threadpool::Worker::Worker(Threadpool& pool) - : pool(pool) { - pthread_create(&thread, nullptr, loop, (void *)this); -} - -Threadpool::Worker::~Worker() { - pthread_cancel(thread); -} - - -void *Threadpool::Worker::loop(void *ptr) { - Worker *worker = static_cast(ptr); - Threadpool& pool = worker->pool; - - pthread_mutex_lock(&pool.mutex); - while (true) { - if (pool.tasks.size()) { - Threadpool::Task task = pool.tasks.front(); - pool.tasks.pop(); - pthread_mutex_unlock(&pool.mutex); - task.first(task.second); - pthread_mutex_lock(&pool.mutex); - } else { - pthread_cond_wait(&pool.condition, &pool.mutex); - } - } - - return nullptr; -} From 178d8ca62d2b6a89b1ee9bcb6f8806d4494395b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 16:03:02 +0200 Subject: [PATCH 3/4] also use boost codecvt on linux --- include/mbgl/util/utf.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index fa21df74c..503fff8b1 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -4,12 +4,13 @@ #include // g++/libstdc++ is missing c++11 codecvt support -#ifndef __clang__ +#if ! defined(__clang__) || defined(__linux__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #include #pragma GCC diagnostic pop #else +// Assume that codecvt is present on clang on non-linux systems #include #include #endif From f4929b0e6ffe671fc8e73683bf565922b18800c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 16:22:41 +0200 Subject: [PATCH 4/4] use correct implementation --- include/mbgl/util/utf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index 503fff8b1..bb6317912 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -19,7 +19,7 @@ namespace mbgl { namespace util { -#ifndef __clang__ +#if ! defined(__clang__) || defined(__linux__) class utf8_to_utf32 { public: