mirror of https://github.com/djcb/mu.git
indexer: fix some threading issues with Progress
Make it a const object with atomic members.
This commit is contained in:
parent
a628f214a1
commit
18ddbe06e6
|
@ -284,7 +284,7 @@ Indexer::Private::cleanup()
|
|||
void
|
||||
Indexer::Private::scan_worker()
|
||||
{
|
||||
progress_ = {};
|
||||
progress_.reset();
|
||||
|
||||
if (conf_.scan) {
|
||||
g_debug("starting scanner");
|
||||
|
@ -410,7 +410,7 @@ Indexer::is_running() const
|
|||
return priv_->state_ != IndexState::Idle;
|
||||
}
|
||||
|
||||
Indexer::Progress
|
||||
const Indexer::Progress&
|
||||
Indexer::progress() const
|
||||
{
|
||||
priv_->progress_.running = priv_->state_ == IndexState::Idle ? false : true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2021 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
|
@ -20,6 +20,7 @@
|
|||
#ifndef MU_INDEXER_HH__
|
||||
#define MU_INDEXER_HH__
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
|
@ -88,20 +89,26 @@ public:
|
|||
|
||||
// Object describing current progress
|
||||
struct Progress {
|
||||
bool running{}; /**< Is an index operation in progress? */
|
||||
size_t checked{}; /**< Number of messages checked for changes */
|
||||
size_t updated{}; /**< Number of messages (re)parsed & added/updated to store */
|
||||
size_t removed{}; /**< Number of message removed from store */
|
||||
void reset()
|
||||
{
|
||||
running = false;
|
||||
checked = updated = removed = 0;
|
||||
}
|
||||
|
||||
std::atomic<bool> running{}; /**< Is an index operation in progress? */
|
||||
std::atomic<size_t> checked{}; /**< Number of messages checked for changes */
|
||||
std::atomic<size_t> updated{}; /**< Number of messages (re)parsed/added/updated */
|
||||
std::atomic<size_t> removed{}; /**< Number of message removed from store */
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an object describing the current progress. The progress object
|
||||
* describes the most recent indexing job, and is reset up a fresh
|
||||
* describes the most recent indexing job, and is reset upon a fresh
|
||||
* start().
|
||||
*
|
||||
* @return a progress object.
|
||||
*/
|
||||
Progress progress() const;
|
||||
const Progress& progress() const;
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
|
|
Loading…
Reference in New Issue