25 using namespace folly;
36 scheduler = std::make_shared<folly::FunctionScheduler>();
41 const std::shared_ptr<folly::FunctionScheduler>& getScheduler() {
50 std::shared_ptr<folly::FunctionScheduler>
scheduler;
55 return new PollerContext();
60 return new bool(
false);
63 constexpr std::chrono::milliseconds FilePoller::kDefaultPollInterval;
65 FilePoller::FilePoller(std::chrono::milliseconds pollInterval) {
69 FilePoller::~FilePoller() {
stop(); }
72 auto context = contextSingleton.try_get();
74 LOG(ERROR) <<
"Poller context requested after destruction.";
77 pollerId_ =
context->getNextId();
78 scheduler_ =
context->getScheduler();
79 scheduler_->addFunction(
80 [
this] { this->checkFiles(); },
82 folly::to<std::string>(pollerId_));
87 scheduler_->cancelFunctionAndWait(
88 folly::to<std::string>(pollerId_));
93 std::lock_guard<std::mutex> lg(filesMutex_);
95 for (
auto& fData : fileDatum_) {
96 auto modData = getFileModData(fData.first);
97 auto& fileData = fData.second;
98 if (fileData.condition(fileData.modData, modData) && fileData.yCob) {
100 }
else if (fileData.nCob) {
103 fileData.modData = modData;
107 void FilePoller::initFileData(
110 auto modData = getFileModData(fName);
111 fData.modData.exists = modData.exists;
112 fData.modData.modTime = modData.modTime;
115 void FilePoller::addFileToTrack(
120 if (fileName.empty()) {
124 if (ThreadProtector::inPollerThread()) {
125 LOG(ERROR) <<
"Adding files from a callback is disallowed";
128 std::lock_guard<std::mutex> lg(filesMutex_);
129 fileDatum_[fileName] =
FileData(yCob, nCob, condition);
130 initFileData(fileName, fileDatum_[fileName]);
134 if (fileName.empty()) {
138 if (ThreadProtector::inPollerThread()) {
139 LOG(ERROR) <<
"Adding files from a callback is disallowed";
142 std::lock_guard<std::mutex> lg(filesMutex_);
143 fileDatum_.erase(fileName);
149 int ret = stat(path.c_str(), &
info);
std::function< bool(const FileModificationData &, const FileModificationData &)> Condition
std::atomic< uint64_t > nextPollerId
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
std::shared_ptr< folly::FunctionScheduler > scheduler
void init(int *argc, char ***argv, bool removeFlags)
std::function< void()> Cob