Enabling/disabling audio context interrupts (locking)

I am writing a 100% custom audio handler which is using its own data structs and parameters to play audio from within an SDK audio source callback (no other SDK constructs used here). When modifying those variables from within the main context there is the risk that the audio callback may interrupt that setting routine midway, and the audio then continues to play back from corrupted and incompletely set parameters, leading to massive audio glitches and crashes if that happens.

My workaround has been a command queue protected by a special dmb instruction to prevent incomplete writing/reading... But it would be nice if the SDK provided the native functionality to disable and enable audio interrupting, very similar to locking and unlocking mutexes when working with threads.

Example of what I mean:

struct { // custom playback from file
    SDFile *file;
    i32     num_samples;
    i32     pos;
    // ...
} audiodata;

// AUDIO CONTEXT, playback custom data from audiodata.file
void audio_callback(i16 *lbuf, i16 *rbuf, i32 len)
{
    // ...
}

// MAIN CONTEXT, modify file playback
void play_from_file(const char *fname)
{
    if (audiodata.file) {
        PD->file->close(audiodata.file);
    }
    audiodata.file = PD->file->open(fname, ...);

    // <<<--- interrupt here = corrupted playback data!

    audiodata.pos  = 0;
    PD->file->read(audiodata.file, &audiodata.num_samples, sizeof(i32));
    // ...
}

I could imagine something like this as a solution for folks who want to do custom audio programming and protect themselves from interrupts while modifying shared data. Of course time spent inside such a locking scope has to be very short to not starve the audio:

// MAIN CONTEXT
void play_from_file(const char *fname)
{
    // prevent audio context from running after this
    if (PD->sound->lock()) { 
        if (audiodata.file) {
            PD->file->close(audiodata.file);
        }
        audiodata.file = PD->file->open(fname, ...);
        audiodata.pos  = 0;
        PD->file->read(audiodata.file, &audiodata.num_samples, sizeof(i32));
        PD->sound->unlock(); // enable audio context again!
    }
}