@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ rotatingRotatingCollisions(const CollisionRect &a, const CollisionRect &b,
|
||||
std::vector<float> 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.
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#include <mbgl/util/threadpool.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
|
||||
using namespace mbgl::util;
|
||||
|
||||
std::unique_ptr<Threadpool> mbgl::util::threadpool = std::make_unique<Threadpool>(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<Worker *>(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;
|
||||
}
|
||||
Reference in New Issue
Block a user