diff --git a/src/AlarmHandler.cpp b/src/AlarmHandler.cpp index 59f9cd58a260da1d29237de9575516ffe68e9fce..47e4ddf2516d4535f5422ad81b31b3ed3e671576 100644 --- a/src/AlarmHandler.cpp +++ b/src/AlarmHandler.cpp @@ -192,6 +192,7 @@ void AlarmHandler::delete_device() DEBUG_STREAM << __func__ << " starting="<<(int)starting << " shutting_down="<<(int)shutting_down<<" restarting="<<(int)restarting; abortflag = true; + updateloop->signal(); DEBUG_STREAM << "AlarmHandler::delete_device(): after abortflag=true..." << endl; try { events->unsubscribe_events(); @@ -210,10 +211,11 @@ void AlarmHandler::delete_device() if(!shutting_down && !restarting) alarms.del_rwlock(); //otherwise moved in alarm_table destructor alarms.stop_cmdthread(); - sleep(1); //wait for alarm_thread and log_thread to exit + delete events; + sleep(1); //wait for alarm_thread, update_thread and log_thread to exit //delete almloop; DEBUG_STREAM << "AlarmHandler::delete_device(): stopped alarm and log threads!" << endl; - + //delete proxy for actions for(alarm_container_t::iterator i = alarms.v_alarm.begin(); i!=alarms.v_alarm.end(); i++) @@ -314,7 +316,6 @@ void AlarmHandler::delete_device() delete alarmedlock; delete internallock; delete dslock; - delete events; instanceCounter--; //Tango::leavefunc(); diff --git a/src/update-thread.cpp b/src/update-thread.cpp index 6064f4f327a196607e5dbe37eead7425dd9e1b3e..1249e5f427e1434a9dfdfb319707d5cd3dcaa556 100644 --- a/src/update-thread.cpp +++ b/src/update-thread.cpp @@ -26,7 +26,7 @@ static const char __FILE__rev[] = __FILE__ " $Revision: 1.2 $"; /* * alarm_thread::alarm_thread() */ -update_thread::update_thread(AlarmHandler_ns::AlarmHandler *p) : p_Alarm(p) +update_thread::update_thread(AlarmHandler_ns::AlarmHandler *p) : p_Alarm(p),Tango::LogAdapter(p) { //cout << __FILE__rev << endl; } @@ -36,6 +36,7 @@ update_thread::update_thread(AlarmHandler_ns::AlarmHandler *p) : p_Alarm(p) */ update_thread::~update_thread() { + DEBUG_STREAM << __func__ << "update_thread::run(): exiting!" << endl; p_Alarm = NULL; } @@ -52,14 +53,23 @@ void update_thread::run(void *) while (!p_Alarm->abortflag) { try { - omni_thread::sleep(pausasec,pausanano); - p_Alarm->timer_update(); + //omni_thread::sleep(pausasec,pausanano); + abort_sleep(pausasec+(double)pausanano/1000000000); + if(!p_Alarm->abortflag) + p_Alarm->timer_update(); //printf("update_thread::run(): TIMER!!\n"); } catch(...) { - printf("update_thread::run(): catched unknown exception!!\n"); + INFO_STREAM << "update_thread::run(): catched unknown exception!!"; } } - //cout << "update_thread::run(): exiting!" << endl; + DEBUG_STREAM << "update_thread::run(): exiting!" << endl; } /* update_thread::run() */ + +void update_thread::abort_sleep(double time) +{ + omni_mutex_lock sync(*this); + long time_millis = (long)(time*1000); + int res = wait(time_millis); +} diff --git a/src/update-thread.h b/src/update-thread.h index ef97c4fdfa20b958d849bc92596d07a54477296c..1d299a1575b359f3dc0e426eace1975081509242 100644 --- a/src/update-thread.h +++ b/src/update-thread.h @@ -24,13 +24,14 @@ #include <tango.h> #include <AlarmHandler.h> -class update_thread : public omni_thread { +class update_thread : public omni_thread, public Tango::TangoMonitor, public Tango::LogAdapter { public: update_thread(AlarmHandler_ns::AlarmHandler *p); ~update_thread(); protected: void run(void *); private: + void abort_sleep(double time); AlarmHandler_ns::AlarmHandler *p_Alarm; };