Skip to content

Commit

Permalink
fix locks
Browse files Browse the repository at this point in the history
  • Loading branch information
bettio committed Oct 3, 2024
1 parent 70686fe commit 70b3d45
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/platforms/esp32/components/avm_builtins/storage_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 70b3d45

Please sign in to comment.