mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-21 17:35:06 +00:00
init/deinit guard for drivers
This commit is contained in:
parent
74bcd979c5
commit
139c1c354c
@ -12,6 +12,7 @@ constexpr auto* TAG = "module";
|
|||||||
|
|
||||||
struct ModuleInternal {
|
struct ModuleInternal {
|
||||||
bool started = false;
|
bool started = false;
|
||||||
|
bool drivers_ready = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModuleLedger {
|
struct ModuleLedger {
|
||||||
@ -66,13 +67,14 @@ error_t module_start(Module* module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module->drivers != nullptr) {
|
if (module->drivers != nullptr && !internal->drivers_ready) {
|
||||||
auto* driver_location = module->drivers;
|
auto* driver_location = module->drivers;
|
||||||
while (*driver_location != nullptr) {
|
while (*driver_location != nullptr) {
|
||||||
auto driver = *driver_location;
|
auto driver = *driver_location;
|
||||||
check(driver_construct_add(driver) == ERROR_NONE);
|
check(driver_construct_add(driver) == ERROR_NONE);
|
||||||
driver_location++;
|
driver_location++;
|
||||||
}
|
}
|
||||||
|
internal->drivers_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal->started = true;
|
internal->started = true;
|
||||||
@ -91,7 +93,7 @@ error_t module_stop(Module* module) {
|
|||||||
if (internal == nullptr) return ERROR_INVALID_STATE;
|
if (internal == nullptr) return ERROR_INVALID_STATE;
|
||||||
if (!internal->started) return ERROR_NONE;
|
if (!internal->started) return ERROR_NONE;
|
||||||
|
|
||||||
if (module->drivers != nullptr) {
|
if (module->drivers != nullptr && internal->drivers_ready) {
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
while (module->drivers[count] != nullptr) {
|
while (module->drivers[count] != nullptr) {
|
||||||
count++;
|
count++;
|
||||||
@ -99,6 +101,7 @@ error_t module_stop(Module* module) {
|
|||||||
for (size_t i = count; i-- > 0;) {
|
for (size_t i = count; i-- > 0;) {
|
||||||
check(driver_remove_destruct(module->drivers[i]) == ERROR_NONE);
|
check(driver_remove_destruct(module->drivers[i]) == ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
internal->drivers_ready = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module->stop != nullptr) {
|
if (module->stop != nullptr) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user