There's machinery in libflipper that relies on global state necessarily, e.g. all functions that need to construct an FMR packet share a single global buffer. We should do two things to deal with this:
Localize all the global state that doesn't actually need to be global.
Add locks to the remaining bits of global state to ensure that only one thread can mutate them. This part might suck, because we need to use pthreads mutexes in UNIX zone and God knows what on Windows.
It has been decided to push explicit thread safety back a bit. This confers the following responsibilities:
Language binding authors are responsible for employing whatever machinery the target language provides to ensure that only one OS thread may make calls to libflipper
Authors of C programs linking against libflipper will be responsible for ensuring that the same invariant is not violated, employing whatever explicit locking mechanism is appropriate.
There's machinery in libflipper that relies on global state necessarily, e.g. all functions that need to construct an FMR packet share a single global buffer. We should do two things to deal with this: