dedup/inc/hasherthread.h

35 lines
573 B
C++

#pragma once
#include <functional>
#include <memory>
#include <mutex>
#include <thread>
#include "file.h"
#include "hash.h"
class HasherThread {
public:
using getNext_f = std::function<std::shared_ptr<File>()>;
using doneCallback_f = std::function<void(Hash&& h, std::shared_ptr<File>)>;
HasherThread(std::mutex& mutex, getNext_f, doneCallback_f);
~HasherThread();
void start();
void stop();
void waitfor();
private:
void threadLoop();
std::thread thread;
std::mutex& mutex;
getNext_f getNext;
doneCallback_f doneCallback;
bool shouldrun = false;
};