File locking refactored (#631)

Remove FileMutex and wire locking into driver subsystems.
This commit is contained in:
Ken Van Hoeylandt
2026-08-28 01:06:53 +02:00
committed by GitHub
parent 92ca046681
commit 020aa471e2
44 changed files with 766 additions and 993 deletions
-31
View File
@@ -1,13 +1,7 @@
/**
* All functions in this file can be safely called without manually applying file locks.
* For calls to C stdlib APIs such as fopen(), always lock with file::FileMutexGuard(path) first!
*/
#pragma once
#include <Tactility/TactilityCore.h>
#include <tactility/filesystem/file_mutex.h>
#include <cstdio>
#include <dirent.h>
#include <functional>
@@ -16,10 +10,6 @@
#include <sys/stat.h>
#include <vector>
/**
* @warning SD card access requires a locking mechanism:
* @warning When using this in the Tactility main project, use `file::FileMutexGuard`
*/
namespace tt::file {
/** File types for `dirent`'s `d_type`. */
@@ -49,27 +39,6 @@ struct FileCloser {
}
};
/**
* RAII lock over TactilityKernel's file_mutex.h for the file system mount that owns `path`.
* Locks in the constructor, unlocks in the destructor - no heap allocation, no virtual dispatch.
*/
class FileMutexGuard final {
FileMutex mutex {};
public:
explicit FileMutexGuard(const std::string& path) {
file_mutex_get(&mutex, path.c_str());
file_mutex_lock(&mutex);
}
~FileMutexGuard() {
file_mutex_unlock(&mutex);
}
FileMutexGuard(const FileMutexGuard&) = delete;
FileMutexGuard& operator=(const FileMutexGuard&) = delete;
};
long getSize(FILE* file);
/** Read a file and return its data.
@@ -2,13 +2,8 @@
#include <Tactility/file/File.h>
#include <tactility/filesystem/file_mutex.h>
#include <string>
/**
* @warning The functionality below does NOT safely acquire file locks. Use file::FileMutexGuard when using the functionality below.
*/
namespace tt::file {
class ObjectFileReader {
@@ -45,7 +40,6 @@ class ObjectFileWriter {
const uint32_t recordSize;
const uint32_t recordVersion;
const bool append;
FileMutex mutex {};
std::unique_ptr<FILE, FileCloser> file;
uint32_t recordsWritten = 0;
@@ -57,9 +51,7 @@ public:
recordSize(recordSize),
recordVersion(recordVersion),
append(append)
{
file_mutex_get(&mutex, this->filePath.c_str());
}
{}
~ObjectFileWriter() {