Page MenuHome

Fix T91212: BLI_mmap not thread-safe on Linux/macOS
Needs ReviewPublic

Authored by Lukas Stockner (lukasstockner97) on Oct 4 2021, 1:40 AM.

Details

Summary

Since we can't lock in signal handlers, the next-best approach is to use thread-local storage to track open files.
Luckily, SIGBUS is guaranteed to be handled by the same thread that caused it, so as long as mmapped files are only accessed from the thread that opened them, this works fine.

Diff Detail

Repository
rB Blender

Event Timeline

Minor change suggested, otherwise this works well & LGTM.

source/blender/blenlib/intern/BLI_mmap.c
85–89

While I don't have a strong opinion on this, a BLI_mmap_init_once() function would avoid the lock & configured check, I have a slight preference for this over locking for a one-off call.

This revision is now accepted and ready to land.Oct 17 2021, 7:47 AM

Good point, I added BLI_mmap_init_once.

Lukas Stockner (lukasstockner97) requested review of this revision.Dec 11 2021, 1:03 AM