move requests to global threadpool

This commit is contained in:
Konstantin Käfer
2014-03-03 12:55:32 +01:00
parent c076da0ae2
commit f850856cec
5 changed files with 25 additions and 26 deletions

View File

@@ -39,8 +39,13 @@ public:
glfwSetWindowUserPointer(window, this);
glfwMakeContextCurrent(window);
int width, height;
glfwGetWindowSize(window, &width, &height);
int fb_width, fb_height;
glfwGetFramebufferSize(window, &fb_width, &fb_height);
settings.load();
map.setup();
map.setup((double)fb_width / width);
resize(window, 0, 0);

View File

@@ -9,7 +9,6 @@
using namespace llmr::platform;
llmr::util::Threadpool *Request::pool = nullptr;
CURLSH *Request::curl_share = nullptr;
pthread_mutex_t Request::curl_share_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -28,16 +27,10 @@ size_t Request::curl_write_callback(void *contents, size_t size, size_t nmemb, v
int Request::curl_progress_callback(void *ptr, double dltotal, double dlnow, double ultotal, double ulnow) {
Request *req = static_cast<Request *>(ptr);
bool cancel = req->cancelled;
if (cancel) {
fprintf(stderr, "cancel download %s\n", req->url.c_str());
}
return cancel;
return req->cancelled;
}
void Request::initialize() {
pool = new llmr::util::Threadpool();
// curl init
curl_global_init(CURL_GLOBAL_ALL);
curl_share = curl_share_init();
@@ -46,7 +39,6 @@ void Request::initialize() {
}
void Request::finish() {
delete pool;
curl_share_cleanup(curl_share);
}
@@ -56,8 +48,7 @@ Request::Request(std::string url, std::function<void(platform::Response&)> bg, s
url(url),
background_function(bg),
foreground_callback(fg) {
assert(pool);
pool->add(request, this);
llmr::util::threadpool->add(request, this);
}
void Request::request(void *ptr) {

View File

@@ -7,11 +7,6 @@
namespace llmr {
namespace util {
class Threadpool;
}
namespace platform {
struct Response;
@@ -40,7 +35,6 @@ public:
const std::function<void()> foreground_callback;
private:
static util::Threadpool* pool;
static CURLSH *curl_share;
static pthread_mutex_t curl_share_mutex;
};