fix atomic
This commit is contained in:
@ -33,16 +33,18 @@ public:
|
|||||||
NVME
|
NVME
|
||||||
};
|
};
|
||||||
|
|
||||||
struct
|
struct ShredSpeed
|
||||||
{
|
{
|
||||||
time_t u32ShredTimeDelta;
|
time_t u32ShredTimeDelta;
|
||||||
std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp;
|
std::chrono::time_point<std::chrono::system_clock>
|
||||||
|
chronoShredTimestamp;
|
||||||
unsigned long ulWrittenBytes;
|
unsigned long ulWrittenBytes;
|
||||||
unsigned long ulSpeedMetricBytesWritten;
|
unsigned long ulSpeedMetricBytesWritten;
|
||||||
} sShredSpeed;
|
};
|
||||||
|
|
||||||
std::atomic<TaskState> state;
|
std::atomic<TaskState> state;
|
||||||
std::atomic<ConnectionType> connectionType;
|
std::atomic<ConnectionType> connectionType;
|
||||||
|
std::atomic<ShredSpeed> sShredSpeed;
|
||||||
|
|
||||||
bool bWasShredded = false; // all shred iterations done
|
bool bWasShredded = false; // all shred iterations done
|
||||||
bool bWasShredStarted = false; // shred was atleast once started
|
bool bWasShredStarted = false; // shred was atleast once started
|
||||||
@ -76,6 +78,18 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
|
// Copy constructor
|
||||||
|
Drive(const Drive &other);
|
||||||
|
|
||||||
|
// Copy assignment operator
|
||||||
|
Drive &operator=(const Drive &other);
|
||||||
|
|
||||||
|
// Move constructor
|
||||||
|
Drive(Drive &&other) noexcept;
|
||||||
|
|
||||||
|
// Move assignment operator
|
||||||
|
Drive &operator=(Drive &&other) noexcept;
|
||||||
|
|
||||||
Drive(std::string path)
|
Drive(std::string path)
|
||||||
{
|
{
|
||||||
this->sPath = path;
|
this->sPath = path;
|
||||||
|
|||||||
2
makefile
2
makefile
@ -18,7 +18,7 @@ DCOMPILE_FLAGS = -D DEBUG
|
|||||||
# Add additional include paths
|
# Add additional include paths
|
||||||
INCLUDES = include
|
INCLUDES = include
|
||||||
# General linker settings
|
# General linker settings
|
||||||
LINK_FLAGS = -Llib -lpthread -lncurses -ltfng
|
LINK_FLAGS = -Llib -lpthread -lncurses -ltfng -latomic
|
||||||
|
|
||||||
# Doc
|
# Doc
|
||||||
DOCDIR = doc
|
DOCDIR = doc
|
||||||
|
|||||||
@ -8,6 +8,94 @@
|
|||||||
#include "../include/reHDD.h"
|
#include "../include/reHDD.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Copy constructor
|
||||||
|
Drive::Drive(const Drive &other)
|
||||||
|
: state(other.state.load()),
|
||||||
|
connectionType(other.connectionType.load()),
|
||||||
|
sShredSpeed(other.sShredSpeed.load()),
|
||||||
|
bWasShredded(other.bWasShredded),
|
||||||
|
bWasShredStarted(other.bWasShredStarted),
|
||||||
|
bWasChecked(other.bWasChecked),
|
||||||
|
bWasDeleted(other.bWasDeleted),
|
||||||
|
bIsOffline(other.bIsOffline),
|
||||||
|
u32DriveChecksumAfterShredding(other.u32DriveChecksumAfterShredding),
|
||||||
|
sPath(other.sPath),
|
||||||
|
u32Timestamp(other.u32Timestamp),
|
||||||
|
d32TaskPercentage(other.d32TaskPercentage),
|
||||||
|
u32TimestampTaskStart(other.u32TimestampTaskStart),
|
||||||
|
u32TaskDuration(other.u32TaskDuration),
|
||||||
|
sSmartData(other.sSmartData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy assignment operator
|
||||||
|
Drive &Drive::operator=(const Drive &other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
{
|
||||||
|
state = other.state.load();
|
||||||
|
connectionType = other.connectionType.load();
|
||||||
|
sShredSpeed = other.sShredSpeed.load();
|
||||||
|
bWasShredded = other.bWasShredded;
|
||||||
|
bWasShredStarted = other.bWasShredStarted;
|
||||||
|
bWasChecked = other.bWasChecked;
|
||||||
|
bWasDeleted = other.bWasDeleted;
|
||||||
|
bIsOffline = other.bIsOffline;
|
||||||
|
u32DriveChecksumAfterShredding = other.u32DriveChecksumAfterShredding;
|
||||||
|
sPath = other.sPath;
|
||||||
|
u32Timestamp = other.u32Timestamp;
|
||||||
|
d32TaskPercentage = other.d32TaskPercentage;
|
||||||
|
u32TimestampTaskStart = other.u32TimestampTaskStart;
|
||||||
|
u32TaskDuration = other.u32TaskDuration;
|
||||||
|
sSmartData = other.sSmartData;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move constructor
|
||||||
|
Drive::Drive(Drive &&other) noexcept
|
||||||
|
: state(other.state.load()),
|
||||||
|
connectionType(other.connectionType.load()),
|
||||||
|
sShredSpeed(other.sShredSpeed.load()),
|
||||||
|
bWasShredded(other.bWasShredded),
|
||||||
|
bWasShredStarted(other.bWasShredStarted),
|
||||||
|
bWasChecked(other.bWasChecked),
|
||||||
|
bWasDeleted(other.bWasDeleted),
|
||||||
|
bIsOffline(other.bIsOffline),
|
||||||
|
u32DriveChecksumAfterShredding(other.u32DriveChecksumAfterShredding),
|
||||||
|
sPath(std::move(other.sPath)),
|
||||||
|
u32Timestamp(other.u32Timestamp),
|
||||||
|
d32TaskPercentage(other.d32TaskPercentage),
|
||||||
|
u32TimestampTaskStart(other.u32TimestampTaskStart),
|
||||||
|
u32TaskDuration(other.u32TaskDuration),
|
||||||
|
sSmartData(std::move(other.sSmartData))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move assignment operator
|
||||||
|
Drive &Drive::operator=(Drive &&other) noexcept
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
{
|
||||||
|
state = other.state.load();
|
||||||
|
connectionType = other.connectionType.load();
|
||||||
|
sShredSpeed = other.sShredSpeed.load();
|
||||||
|
bWasShredded = other.bWasShredded;
|
||||||
|
bWasShredStarted = other.bWasShredStarted;
|
||||||
|
bWasChecked = other.bWasChecked;
|
||||||
|
bWasDeleted = other.bWasDeleted;
|
||||||
|
bIsOffline = other.bIsOffline;
|
||||||
|
u32DriveChecksumAfterShredding = other.u32DriveChecksumAfterShredding;
|
||||||
|
sPath = std::move(other.sPath);
|
||||||
|
u32Timestamp = other.u32Timestamp;
|
||||||
|
d32TaskPercentage = other.d32TaskPercentage;
|
||||||
|
u32TimestampTaskStart = other.u32TimestampTaskStart;
|
||||||
|
u32TaskDuration = other.u32TaskDuration;
|
||||||
|
sSmartData = std::move(other.sSmartData);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
string Drive::getPath(void)
|
string Drive::getPath(void)
|
||||||
{
|
{
|
||||||
return sPath;
|
return sPath;
|
||||||
|
|||||||
@ -359,8 +359,8 @@ void reHDD::searchDrives(std::list<Drive> *plistDrives)
|
|||||||
"Drive found: " + tmpDrive.getPath() +
|
"Drive found: " + tmpDrive.getPath() +
|
||||||
" (type: " +
|
" (type: " +
|
||||||
(tmpDrive.connectionType == Drive::ConnectionType::USB ? "USB" : tmpDrive.connectionType == Drive::ConnectionType::SATA ? "SATA"
|
(tmpDrive.connectionType == Drive::ConnectionType::USB ? "USB" : tmpDrive.connectionType == Drive::ConnectionType::SATA ? "SATA"
|
||||||
: tmpDrive.connectionType == Drive::ConnectionType::NVME ? "NVME"
|
: tmpDrive.connectionType == Drive::ConnectionType::NVME ? "NVME"
|
||||||
: "UNKNOWN") +
|
: "UNKNOWN") +
|
||||||
")");
|
")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,13 +571,15 @@ void reHDD::updateShredMetrics(list<Drive> *plistDrives)
|
|||||||
Drive *pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator>(it);
|
Drive *pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator>(it);
|
||||||
// set metrics for calculating shred speed
|
// set metrics for calculating shred speed
|
||||||
std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now();
|
std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now();
|
||||||
time_t u32ShredTimeDelta = (chronoCurrentTimestamp - pTmpDrive->sShredSpeed.chronoShredTimestamp).count();
|
auto shredSpeed = pTmpDrive->sShredSpeed.load();
|
||||||
|
time_t u32ShredTimeDelta = (chronoCurrentTimestamp - shredSpeed.chronoShredTimestamp).count();
|
||||||
if (u32ShredTimeDelta > METRIC_THRESHOLD)
|
if (u32ShredTimeDelta > METRIC_THRESHOLD)
|
||||||
{
|
{
|
||||||
pTmpDrive->sShredSpeed.u32ShredTimeDelta = u32ShredTimeDelta;
|
shredSpeed.u32ShredTimeDelta = u32ShredTimeDelta;
|
||||||
pTmpDrive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();
|
shredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();
|
||||||
pTmpDrive->sShredSpeed.ulWrittenBytes = pTmpDrive->sShredSpeed.ulSpeedMetricBytesWritten;
|
shredSpeed.ulWrittenBytes = shredSpeed.ulSpeedMetricBytesWritten;
|
||||||
pTmpDrive->sShredSpeed.ulSpeedMetricBytesWritten = 0U;
|
shredSpeed.ulSpeedMetricBytesWritten = 0U;
|
||||||
|
pTmpDrive->sShredSpeed.store(shredSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -286,7 +286,9 @@ unsigned int Shred::uiCalcChecksum(fileDescriptor file, Drive *drive, int *ipSig
|
|||||||
ulDriveByteCounter += iReadBytes;
|
ulDriveByteCounter += iReadBytes;
|
||||||
ulDriveByteOverallCount += iReadBytes;
|
ulDriveByteOverallCount += iReadBytes;
|
||||||
d32Percent = this->calcProgress();
|
d32Percent = this->calcProgress();
|
||||||
drive->sShredSpeed.ulSpeedMetricBytesWritten += iReadBytes;
|
auto shredSpeed = drive->sShredSpeed.load();
|
||||||
|
shredSpeed.ulSpeedMetricBytesWritten += iReadBytes;
|
||||||
|
drive->sShredSpeed.store(shredSpeed);
|
||||||
|
|
||||||
#ifdef LOG_LEVEL_HIGH
|
#ifdef LOG_LEVEL_HIGH
|
||||||
Logger::logThis()->info("Shred-Task (Checksum): ByteCount: " + to_string(ulDriveByteCounter) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
|
Logger::logThis()->info("Shred-Task (Checksum): ByteCount: " + to_string(ulDriveByteCounter) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
|
||||||
|
|||||||
23
src/tui.cpp
23
src/tui.cpp
@ -99,9 +99,9 @@ void TUI::updateTUI(list<Drive> *plistDrives, uint8_t u8SelectedEntry)
|
|||||||
string sSpeed = " ";
|
string sSpeed = " ";
|
||||||
string sTime = " ";
|
string sTime = " ";
|
||||||
string sTemp = it->sTemperatureToText();
|
string sTemp = it->sTemperatureToText();
|
||||||
string sConnection = (it->connectionType == Drive::USB ? "USB" : it->connectionType == Drive::SATA ? "SATA"
|
string sConnection = (it->connectionType == Drive::ConnectionType::USB ? "USB" : it->connectionType == Drive::ConnectionType::SATA ? "SATA"
|
||||||
: it->connectionType == Drive::NVME ? "NVME"
|
: it->connectionType == Drive::ConnectionType::NVME ? "NVME"
|
||||||
: "");
|
: "");
|
||||||
|
|
||||||
bool bSelectedEntry = false;
|
bool bSelectedEntry = false;
|
||||||
|
|
||||||
@ -123,29 +123,38 @@ void TUI::updateTUI(list<Drive> *plistDrives, uint8_t u8SelectedEntry)
|
|||||||
switch (it->state)
|
switch (it->state)
|
||||||
{
|
{
|
||||||
case Drive::TaskState::SHRED_ACTIVE:
|
case Drive::TaskState::SHRED_ACTIVE:
|
||||||
|
{
|
||||||
stream << fixed << setprecision(3) << (it->getTaskPercentage());
|
stream << fixed << setprecision(3) << (it->getTaskPercentage());
|
||||||
sState = "Shredding: " + stream.str() + "%";
|
sState = "Shredding: " + stream.str() + "%";
|
||||||
|
|
||||||
it->calculateTaskDuration();
|
it->calculateTaskDuration();
|
||||||
sTime = this->formatTimeDuration(it->getTaskDuration());
|
sTime = this->formatTimeDuration(it->getTaskDuration());
|
||||||
sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes);
|
auto shredSpeed = it->sShredSpeed.load();
|
||||||
|
sSpeed = this->formatSpeed(shredSpeed.u32ShredTimeDelta, shredSpeed.ulWrittenBytes);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Drive::TaskState::CHECK_ACTIVE:
|
case Drive::TaskState::CHECK_ACTIVE:
|
||||||
|
{
|
||||||
stream << fixed << setprecision(3) << (it->getTaskPercentage());
|
stream << fixed << setprecision(3) << (it->getTaskPercentage());
|
||||||
sState = "Checking: " + stream.str() + "%";
|
sState = "Checking: " + stream.str() + "%";
|
||||||
it->calculateTaskDuration();
|
it->calculateTaskDuration();
|
||||||
sTime = this->formatTimeDuration(it->getTaskDuration());
|
sTime = this->formatTimeDuration(it->getTaskDuration());
|
||||||
sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes);
|
auto shredSpeed = it->sShredSpeed.load();
|
||||||
|
sSpeed = this->formatSpeed(shredSpeed.u32ShredTimeDelta, shredSpeed.ulWrittenBytes);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Drive::TaskState::DELETE_ACTIVE:
|
case Drive::TaskState::DELETE_ACTIVE:
|
||||||
|
{
|
||||||
|
|
||||||
sState = "Deleting ...";
|
sState = "Deleting ...";
|
||||||
it->calculateTaskDuration();
|
it->calculateTaskDuration();
|
||||||
sTime = this->formatTimeDuration(it->getTaskDuration());
|
sTime = this->formatTimeDuration(it->getTaskDuration());
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Drive::TaskState::NONE:
|
case Drive::TaskState::NONE:
|
||||||
case Drive::TaskState::SHRED_SELECTED:
|
case Drive::TaskState::SHRED_SELECTED:
|
||||||
case Drive::TaskState::DELETE_SELECTED:
|
case Drive::TaskState::DELETE_SELECTED:
|
||||||
|
{
|
||||||
if (it->bWasDeleted)
|
if (it->bWasDeleted)
|
||||||
{
|
{
|
||||||
sState = "DELETED"; // mark drive as deleted previously
|
sState = "DELETED"; // mark drive as deleted previously
|
||||||
@ -172,8 +181,8 @@ void TUI::updateTUI(list<Drive> *plistDrives, uint8_t u8SelectedEntry)
|
|||||||
wrefresh(dialog);
|
wrefresh(dialog);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Drive::TaskState::FROZEN:
|
case Drive::TaskState::FROZEN:
|
||||||
stream << fixed << setprecision(3) << (it->getTaskPercentage());
|
stream << fixed << setprecision(3) << (it->getTaskPercentage());
|
||||||
#ifdef FROZEN_ALERT
|
#ifdef FROZEN_ALERT
|
||||||
|
|||||||
Reference in New Issue
Block a user