#pragma once
#include <stdatomic.h>
#include <stdint.h>

typedef struct {
    atomic_flag flag;
} spinlock_t;

#define SPINLOCK_INIT ((spinlock_t){ .flag = ATOMIC_FLAG_INIT })

void spinlock_init(spinlock_t *lock);
void spinlock_acquire_or_wait(spinlock_t *lock);
void spinlock_drop(spinlock_t *lock);

// Old IRQ-safe API still available for compatibility
void spinlock_acquire_irqsave(spinlock_t *lock, uint64_t *flags);
void spinlock_release_irqrestore(spinlock_t *lock, uint64_t flags);