I have an FFI function that pushes messages to a callback function in my application. This callback can potentially be called multiple times from any thread. The documentation notes that this callback must also be reentrant safe.
The API gives me one pointer-sized value that can be passed straight through to the callback function. This should hopefully allow my callback function to pass the message back to the part of my program that is expecting this particular message without blocking the callback more than absolutely necessary.
However, I'm not certain how to do this safely. A crossbeam channel would be the ideal choice but I need a way to get the right channel to use for a particular message. Simply using a pointer to the channel would work but I would need to ensure that the channel never moves.
What's the best way to approach this?