diff --git a/src/platforms/esp32/components/avm_builtins/storage_nif.c b/src/platforms/esp32/components/avm_builtins/storage_nif.c index 682e9556b..bb8fdca9d 100644 --- a/src/platforms/esp32/components/avm_builtins/storage_nif.c +++ b/src/platforms/esp32/components/avm_builtins/storage_nif.c @@ -46,9 +46,11 @@ #define TAG "storage_nif" #ifndef AVM_NO_SMP -#define SMP_LOCK(mounted_fs) smp_spinlock_lock(mounted_fs->lock) -#define SMP_UNLOCK(mounted_fs) smp_spinlock_unlock(mounted_fs->lock) +#define SMP_LOCK_INIT(mounted_fs) smp_spinlock_init(&mounted_fs->lock) +#define SMP_LOCK(mounted_fs) smp_spinlock_lock(&mounted_fs->lock) +#define SMP_UNLOCK(mounted_fs) smp_spinlock_unlock(&mounted_fs->lock) #else +#define SMP_LOCK_INIT(mounted_fs) #define SMP_LOCK(mounted_fs) #define SMP_UNLOCK(mounted_fs) #endif @@ -65,7 +67,7 @@ enum mount_type struct MountedFS { #ifndef AVM_NO_SMP - SpinLock *lock; + SpinLock lock; #endif char *base_path; enum mount_type mount_type; @@ -160,6 +162,7 @@ static term nif_esp_mount(Context *ctx, int argc, term argv[]) free(target); RAISE_ERROR(OUT_OF_MEMORY_ATOM); } + SMP_LOCK_INIT(mount); mount->base_path = target; target = NULL; mount->mount_type = FATSPIFlash; @@ -184,6 +187,7 @@ static term nif_esp_mount(Context *ctx, int argc, term argv[]) if (IS_NULL_PTR(mount)) { RAISE_ERROR(OUT_OF_MEMORY_ATOM); } + SMP_LOCK_INIT(mount); mount->base_path = target; target = NULL; mount->mount_type = FATSDMMC; @@ -231,6 +235,7 @@ static term nif_esp_mount(Context *ctx, int argc, term argv[]) free(target); RAISE_ERROR(OUT_OF_MEMORY_ATOM); } + SMP_LOCK_INIT(mount); mount->base_path = target; target = NULL; mount->mount_type = FATSDSPI;