Files
MapLibreParticleLab/include/mbgl/storage/request.hpp
Konstantin Käfer 4e3503ea6c [core] do not use std::atomic_* with shared_ptrs
It's not implemented in GCC 4.9.2's stdlib (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57250). Instead, we're now always using a mutex to protect access; we previously created a mutex only on cancelation, but since we're always canceling now, it makes sense to allocate it right away.
2015-10-26 15:54:27 +01:00

53 lines
1.0 KiB
C++

#ifndef MBGL_STORAGE_DEFAULT_REQUEST
#define MBGL_STORAGE_DEFAULT_REQUEST
#include <mbgl/storage/resource.hpp>
#include <mbgl/util/util.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mutex>
#include <thread>
#include <functional>
#include <memory>
typedef struct uv_loop_s uv_loop_t;
namespace uv { class async; }
namespace mbgl {
class Response;
class Request : private util::noncopyable {
public:
using Callback = std::function<void(const Response &)>;
Request(const Resource &resource, uv_loop_t *loop, Callback callback);
public:
// May be called from any thread.
void notify(const std::shared_ptr<const Response> &response);
void destruct();
// May be called only from the thread the Request was created in.
void cancel();
private:
~Request();
void notifyCallback();
private:
std::mutex mtx;
bool canceled = false;
bool confirmed = false;
const std::unique_ptr<uv::async> async;
Callback callback;
std::shared_ptr<const Response> response;
public:
const Resource resource;
};
}
#endif