base-foc: avoid global ctor in Irq_session_component

Issue #4784
Issue #3509
This commit is contained in:
Christian Helmuth 2023-06-29 15:53:49 +02:00 committed by Norman Feske
parent f6dcc3ca74
commit c84bbea1ca

View File

@ -61,7 +61,7 @@ class Core::Interrupt_handler : public Thread
enum { MAX_MSIS = 256 }; enum { MAX_MSIS = 256 };
static struct Msi_allocator : Bit_array<MAX_MSIS> struct Msi_allocator : Bit_array<MAX_MSIS>
{ {
Msi_allocator() Msi_allocator()
{ {
@ -78,7 +78,14 @@ static struct Msi_allocator : Bit_array<MAX_MSIS>
set(info.nr_msis, MAX_MSIS - info.nr_msis); set(info.nr_msis, MAX_MSIS - info.nr_msis);
} }
} msi_alloc; };
static Msi_allocator & msi_alloc()
{
static Msi_allocator instance;
return instance;
}
bool Irq_object::associate(unsigned irq, bool msi, bool Irq_object::associate(unsigned irq, bool msi,
@ -189,11 +196,11 @@ Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
long const msi = Arg_string::find_arg(args, "device_config_phys").long_value(0); long const msi = Arg_string::find_arg(args, "device_config_phys").long_value(0);
if (msi) { if (msi) {
if (msi_alloc.get(_irq_number, 1)) { if (msi_alloc().get(_irq_number, 1)) {
error("unavailable MSI ", _irq_number, " requested"); error("unavailable MSI ", _irq_number, " requested");
throw Service_denied(); throw Service_denied();
} }
msi_alloc.set(_irq_number, 1); msi_alloc().set(_irq_number, 1);
} else { } else {
if (irq_alloc.alloc_addr(1, _irq_number).failed()) { if (irq_alloc.alloc_addr(1, _irq_number).failed()) {
error("unavailable IRQ ", _irq_number, " requested"); error("unavailable IRQ ", _irq_number, " requested");
@ -209,7 +216,7 @@ Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
/* cleanup */ /* cleanup */
if (msi) if (msi)
msi_alloc.clear(_irq_number, 1); msi_alloc().clear(_irq_number, 1);
else { else {
addr_t const free_irq = _irq_number; addr_t const free_irq = _irq_number;
_irq_alloc.free((void *)free_irq); _irq_alloc.free((void *)free_irq);
@ -224,7 +231,7 @@ Irq_session_component::~Irq_session_component()
return; return;
if (_irq_object.msi_address()) { if (_irq_object.msi_address()) {
msi_alloc.clear(_irq_number, 1); msi_alloc().clear(_irq_number, 1);
} else { } else {
addr_t const free_irq = _irq_number; addr_t const free_irq = _irq_number;
_irq_alloc.free((void *)free_irq); _irq_alloc.free((void *)free_irq);