aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-10-08 17:12:35 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-10-08 19:22:31 +0000
commit8f22e808650a0d599913f608441515f9d985cced (patch)
treefe06cbe53aeff5ccdf016915c724768c19047ce3
parentMerge pull request #4036 (diff)
downloadmonero-8f22e808650a0d599913f608441515f9d985cced.tar.xz
device: destroy device objects on exit
-rw-r--r--src/device/device.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/device/device.cpp b/src/device/device.cpp
index 50041baef..d5e3031ff 100644
--- a/src/device/device.cpp
+++ b/src/device/device.cpp
@@ -41,13 +41,26 @@ namespace hw {
/* 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(){
hw::core::register_all(registry);
#ifdef WITH_DEVICE_LEDGER
hw::ledger::register_all(registry);
#endif
+ atexit(clear_device_registry);
}
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) {
- if (!registry){
- registry.reset(new device_registry());
- }
-
+ device_registry *registry = get_device_registry();
return registry->get_device(device_descriptor);
}
bool register_device(const std::string & device_name, device * hw_device){
- if (!registry){
- registry.reset(new device_registry());
- }
-
+ device_registry *registry = get_device_registry();
return registry->register_device(device_name, hw_device);
}