mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +01:00
Get idle counters at once (#294)
to avoid a race with usage==0 & openCount>0
This commit is contained in:
parent
efbdd29716
commit
618db2374c
@ -74,20 +74,15 @@ void EncFS_Context::setRoot(const std::shared_ptr<DirNode> &r) {
|
||||
|
||||
bool EncFS_Context::isMounted() { return root.get() != nullptr; }
|
||||
|
||||
int EncFS_Context::getAndResetUsageCounter() {
|
||||
void EncFS_Context::getAndResetUsageCounter(int *usage, int *openCount) {
|
||||
Lock lock(contextMutex);
|
||||
|
||||
int count = usageCount;
|
||||
*usage = usageCount;
|
||||
usageCount = 0;
|
||||
|
||||
return count;
|
||||
*openCount = openFiles.size();
|
||||
}
|
||||
|
||||
int EncFS_Context::openFileCount() const {
|
||||
Lock lock(contextMutex);
|
||||
|
||||
return openFiles.size();
|
||||
}
|
||||
std::shared_ptr<FileNode> EncFS_Context::lookupNode(const char *path) {
|
||||
Lock lock(contextMutex);
|
||||
|
||||
|
@ -44,9 +44,8 @@ class EncFS_Context {
|
||||
|
||||
std::shared_ptr<FileNode> lookupNode(const char *path);
|
||||
|
||||
int getAndResetUsageCounter();
|
||||
int openFileCount() const;
|
||||
|
||||
void getAndResetUsageCounter(int *usage, int *openCount);
|
||||
|
||||
FileNode *putNode(const char *path, std::shared_ptr<FileNode> &&node);
|
||||
|
||||
void eraseNode(const char *path, FileNode *fnode);
|
||||
|
@ -718,15 +718,19 @@ static void *idleMonitor(void *_arg) {
|
||||
pthread_mutex_lock(&ctx->wakeupMutex);
|
||||
|
||||
while (ctx->running) {
|
||||
int usage = ctx->getAndResetUsageCounter();
|
||||
int usage, openCount;
|
||||
ctx->getAndResetUsageCounter(&usage, &openCount);
|
||||
|
||||
if (usage == 0 && ctx->isMounted())
|
||||
++idleCycles;
|
||||
else
|
||||
else {
|
||||
if (idleCycles >= timeoutCycles)
|
||||
RLOG(INFO) << "Filesystem no longer inactive: "
|
||||
<< arg->opts->mountPoint;
|
||||
idleCycles = 0;
|
||||
}
|
||||
|
||||
if (idleCycles >= timeoutCycles) {
|
||||
int openCount = ctx->openFileCount();
|
||||
if (openCount == 0) {
|
||||
if (unmountFS(ctx)) {
|
||||
// wait for main thread to wake us up
|
||||
|
Loading…
Reference in New Issue
Block a user