mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 20:19:34 +00:00
Merge pull request #4532
8f22e808
device: destroy device objects on exit (moneromooo-monero)
This commit is contained in:
parent
4b609dede3
commit
eca27122df
1 changed files with 16 additions and 9 deletions
|
@ -41,13 +41,26 @@ namespace hw {
|
||||||
/* SETUP */
|
/* SETUP */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
static std::unique_ptr<device_registry> registry;
|
static device_registry *get_device_registry(bool clear = false){
|
||||||
|
static device_registry *registry = new device_registry();
|
||||||
|
if (clear)
|
||||||
|
{
|
||||||
|
delete registry;
|
||||||
|
registry = NULL;
|
||||||
|
}
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clear_device_registry(){
|
||||||
|
get_device_registry(true);
|
||||||
|
}
|
||||||
|
|
||||||
device_registry::device_registry(){
|
device_registry::device_registry(){
|
||||||
hw::core::register_all(registry);
|
hw::core::register_all(registry);
|
||||||
#ifdef WITH_DEVICE_LEDGER
|
#ifdef WITH_DEVICE_LEDGER
|
||||||
hw::ledger::register_all(registry);
|
hw::ledger::register_all(registry);
|
||||||
#endif
|
#endif
|
||||||
|
atexit(clear_device_registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool device_registry::register_device(const std::string & device_name, device * hw_device){
|
bool device_registry::register_device(const std::string & device_name, device * hw_device){
|
||||||
|
@ -80,18 +93,12 @@ namespace hw {
|
||||||
}
|
}
|
||||||
|
|
||||||
device& get_device(const std::string & device_descriptor) {
|
device& get_device(const std::string & device_descriptor) {
|
||||||
if (!registry){
|
device_registry *registry = get_device_registry();
|
||||||
registry.reset(new device_registry());
|
|
||||||
}
|
|
||||||
|
|
||||||
return registry->get_device(device_descriptor);
|
return registry->get_device(device_descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool register_device(const std::string & device_name, device * hw_device){
|
bool register_device(const std::string & device_name, device * hw_device){
|
||||||
if (!registry){
|
device_registry *registry = get_device_registry();
|
||||||
registry.reset(new device_registry());
|
|
||||||
}
|
|
||||||
|
|
||||||
return registry->register_device(device_name, hw_device);
|
return registry->register_device(device_name, hw_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue