Commit 348e5959 authored by Paweł Wegner's avatar Paweł Wegner

IThreadPool: use GenericCallback.

parent f675c5ca
......@@ -416,9 +416,7 @@ ICloudProvider::Pointer CloudContext::provider(const std::string& name,
ThreadPoolWrapper(std::shared_ptr<IThreadPool> thread_pool)
: thread_pool_(thread_pool) {}
void schedule(std::function<void()> f) override {
thread_pool_->schedule(f);
}
void schedule(const Task& f) override { thread_pool_->schedule(f); }
private:
std::shared_ptr<IThreadPool> thread_pool_;
......
......@@ -65,9 +65,7 @@ IHttpRequest::Pointer HttpWrapper::create(const std::string &url,
return http_->create(url, method, follow_redirect);
}
void ThreadPoolWrapper::schedule(std::function<void()> f) {
thread_pool_->schedule(f);
}
void ThreadPoolWrapper::schedule(const Task &f) { thread_pool_->schedule(f); }
IHttpServer::IResponse::Pointer HttpServerCallback::handle(
const IHttpServer::IRequest &request) {
......
......@@ -35,7 +35,7 @@ class ThreadPoolWrapper : public IThreadPool {
ThreadPoolWrapper(std::shared_ptr<IThreadPool> thread_pool)
: thread_pool_(thread_pool) {}
void schedule(std::function<void()> f) override;
void schedule(const Task &f) override;
private:
std::shared_ptr<IThreadPool> thread_pool_;
......
......@@ -29,6 +29,8 @@
#include <string>
#include <unordered_map>
#include "IRequest.h"
namespace cloudstorage {
class IHttpRequest {
......@@ -38,7 +40,7 @@ class IHttpRequest {
using Pointer = std::shared_ptr<IHttpRequest>;
using GetParameters = std::unordered_map<std::string, std::string>;
using HeaderParameters = std::unordered_map<std::string, std::string>;
using CompleteCallback = std::function<void(Response)>;
using CompleteCallback = GenericCallback<Response>;
struct Response {
int http_code_;
......
......@@ -28,6 +28,8 @@
#include <string>
#include <unordered_map>
#include "IRequest.h"
namespace cloudstorage {
class IHttpServer {
......@@ -42,7 +44,7 @@ class IHttpServer {
public:
using Pointer = std::unique_ptr<IResponse>;
using Headers = std::unordered_map<std::string, std::string>;
using CompletedCallback = std::function<void()>;
using CompletedCallback = GenericCallback<>;
static constexpr int UnknownSize = -1;
......
......@@ -226,7 +226,7 @@ class GenericCallback {
GenericCallback(typename IGenericCallback<Arguments...>::Pointer functor)
: functor_(functor) {}
operator bool() const { return functor_; }
operator bool() const { return static_cast<bool>(functor_); }
void operator()(Arguments... d) const { functor_->done(d...); }
......
......@@ -26,17 +26,20 @@
#include <functional>
#include <memory>
#include "IRequest.h"
namespace cloudstorage {
class IThreadPool {
public:
using Pointer = std::unique_ptr<IThreadPool>;
using Task = GenericCallback<>;
virtual ~IThreadPool() = default;
static Pointer create(uint32_t thread_count);
virtual void schedule(std::function<void()> f) = 0;
virtual void schedule(const Task& f) = 0;
};
} // namespace cloudstorage
......
......@@ -33,7 +33,7 @@ IThreadPool::Pointer IThreadPool::create(uint32_t cnt) {
ThreadPool::ThreadPool(uint32_t thread_count) : worker_(thread_count) {}
void ThreadPool::schedule(std::function<void()> f) {
void ThreadPool::schedule(const Task& f) {
auto it = std::min_element(worker_.begin(), worker_.end(),
[](const Worker& w1, const Worker& w2) {
std::unique_lock<std::mutex> l1(w1.mutex_);
......
......@@ -35,7 +35,7 @@ class ThreadPool : public IThreadPool {
public:
ThreadPool(uint32_t thread_count);
void schedule(std::function<void()> f) override;
void schedule(const Task& f) override;
private:
struct Worker {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment