ohmtech-rdi / eurorack-blocks

Software to Hardware Prototyping for Eurorack using C++, Max/Gen~ or Faust
Other
309 stars 21 forks source link

Simulator memory pool per instance #570

Closed ohmtech-rdi closed 1 year ago

ohmtech-rdi commented 1 year ago

This PR fixes a flaw where the SRAM and SDRAM simulation was entire to the full process, including in the simulator.

This was mainly motivated because operator new is a global function, and passing a memory pool around makes a plug-in porting effort way harder.

This was not an issue in the firmware, as anyway "there is only one module running at a time", but that's not the case for the simulator. Because the memory pool is static, it is shared between multiple instances of the same module, for example on macOS (this depends on the way dynamic libraries are handled).

This PR makes it so that there is one memory pool per instance of module in the simulator. The implementation keeps a pointer to know which instance is the "current one". Because there can be multiple instances running in different threads, a thread local storage is used for that. This is ugly, but seems to work.

Todo:

ohmtech-rdi commented 1 year ago

We found out that it is not possible to debug on macOS with VS Code, but the problem was at least not introduced in this branch.

ohmtech-rdi commented 1 year ago

First time we executed erbb install for the firmware, there was no sound output, but turning off and on the module solved it.