I would create two separate ring buffers for incoming data on the USB and DIN port and assign timestamps to the messages.
On the receive routine (there's one for each input)
1. get byte
2. track running status
3. when a message is complete, insert it into the ring buffer
Then on the send-routine
1. look at the two messages on the tail of both buffers, and determine which of the two messages has the lower timestamp
2. send that message
Whenever one of the two messages is a sysex-start message: Go into sysex mode, where only messages from one buffer are sent until the sysex string is over.
Yes, there is a chance for buffer overflow, but that's there with usb midi to din midi converters anyway.
Doesn't look too difficult at the first glance. Am I missing something?