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
@@ -65,6 +65,19 @@ error_t spi_controller_try_lock(struct Device* device, TickType_t timeout);
*/
error_t spi_controller_unlock(struct Device* device);
/**
* @brief Locks device's parent bus when the parent is a SPI controller.
* @param[in] device the device whose parent may be a SPI controller
* @retval ERROR_NONE when the operation was successful, or the parent is not a SPI controller
*/
error_t spi_controller_lock_bus_of(struct Device* device);
/**
* @brief Unlocks a device's parent bus.
* @param[in] device the device whose parent may be a SPI controller
*/
void spi_controller_unlock_bus_of(struct Device* device);
extern const struct DeviceType SPI_CONTROLLER_TYPE;
#ifdef __cplusplus
@@ -1,63 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/freertos/freertos.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Set of lock/try_lock/unlock callbacks backing a filesystem mount's mutex.
* Any field left null is treated as a no-op by file_mutex_lock/try_lock/unlock.
*/
struct FileMutex {
void (*lock)();
bool (*try_lock)(uint32_t timeout);
void (*unlock)();
};
typedef uint32_t FileMutexId;
#define FILE_MUTEX_ID_INVALID ((FileMutexId)0)
/**
* @brief Registers a mutex for a mount path (e.g. "/sdcard") and its descendants.
* @param[in] mutex callbacks to associate with the path; a copy is stored
* @param[in] path mount path this mutex serializes access to
* @return the id of the new entry, or the id of the existing entry if path is already registered
* @note If a mutex is already registered for this exact path, no new entry is created and the
* existing entry's id is returned; the existing callbacks are left unchanged.
*/
FileMutexId file_mutex_add(const struct FileMutex* mutex, const char* path);
/**
* @brief Removes a previously added mutex registration.
* @param[in] id id returned by file_mutex_add(); a stale or unknown id is a no-op
*/
void file_mutex_remove(FileMutexId id);
/**
* @brief Looks up the mutex registered for path or one of its ancestor mount paths.
* @param[out] mutex receives the matching mutex, or an all-null (no-op) mutex if none matches
* @param[in] path file or directory path to look up
*/
void file_mutex_get(struct FileMutex* mutex, const char* path);
/** @brief Locks mutex. No-op if mutex->lock is null. */
void file_mutex_lock(const struct FileMutex* mutex);
/**
* @brief Attempts to lock mutex within timeout.
* @return true if locked (or mutex->try_lock is null), false on timeout
*/
bool file_mutex_try_lock(const struct FileMutex* mutex, TickType_t timeout);
/** @brief Unlocks mutex. No-op if mutex->unlock is null. */
void file_mutex_unlock(const struct FileMutex* mutex);
#ifdef __cplusplus
}
#endif
@@ -2,8 +2,6 @@
/**
* @brief Generic string key-value ".properties" file.
* @note Safely acquires/releases the filesystem mutex registered for the file's path (see
* tactility/filesystem/file_mutex.h) - manual locking isn't needed.
*/
#pragma once