Thread<T> is a generic thread management object that starts a thread, creates an object T in that thread and calls its .start() function. When the Thread<T> object is destructed (which must happen in the thread that created it), it'll call the object's .stop() function, and wait for thread termination. The .stop() function must somehow get the thread to terminate. Note that object T's constructor/destructor/start()/stop() must be protected/private, and Thread<T> must be declared as a friend class. All public functions may be called from any thread and are exposed through operator->(). RunLoop encapsulates a libuv runloop and has a facility of dispatching function objects to the thread. It can be used either as a worker thread class by itself, or it can be derived from. This commit converts SQLiteCache to derive from RunLoop and removes the custom code used previously for managing the cache thread.
28 lines
600 B
C++
28 lines
600 B
C++
#ifndef MBGL_STORAGE_FILE_CACHE
|
|
#define MBGL_STORAGE_FILE_CACHE
|
|
|
|
#include <mbgl/util/noncopyable.hpp>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
namespace mbgl {
|
|
|
|
struct Resource;
|
|
class Response;
|
|
|
|
class FileCache : private util::noncopyable {
|
|
public:
|
|
virtual ~FileCache() = default;
|
|
|
|
enum class Hint : uint8_t { Full, Refresh, No };
|
|
using Callback = std::function<void(std::unique_ptr<Response>)>;
|
|
|
|
virtual void get(const Resource &resource, Callback callback) = 0;
|
|
virtual void put(const Resource &resource, std::shared_ptr<const Response> response, Hint hint) = 0;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|