summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kutsan <AKutsan@luxoft.com>2014-10-06 19:49:14 +0300
committerAlexander Kutsan <AKutsan@luxoft.com>2014-10-07 10:03:22 +0300
commit916ef5559e32f553ecfa8429786bed9889d73efd (patch)
tree579a595cfedb8eb79f1ce460dd410c870c8f1b94
parentc06a89e44df0daee954953ae933be7dce2297c79 (diff)
downloadsmartdevicelink-916ef5559e32f553ecfa8429786bed9889d73efd.tar.gz
APPLINK-9586 APPLINK-8760 Fix core crash in Timer and PH singletone
-rw-r--r--customer-specific/pasa/src/appMain/SmartDeviceLinkMainApp.cpp2
-rw-r--r--src/appMain/life_cycle.cc3
-rw-r--r--src/appMain/signal_handlers.cc5
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc3
-rw-r--r--src/components/application_manager/src/request_controller.cc8
-rw-r--r--src/components/include/utils/timer_thread.h52
-rw-r--r--src/components/utils/src/conditional_variable_posix.cc2
-rw-r--r--src/components/utils/src/threads/posix_thread.cc2
8 files changed, 46 insertions, 31 deletions
diff --git a/customer-specific/pasa/src/appMain/SmartDeviceLinkMainApp.cpp b/customer-specific/pasa/src/appMain/SmartDeviceLinkMainApp.cpp
index 869a4ab2a..8c926c67e 100644
--- a/customer-specific/pasa/src/appMain/SmartDeviceLinkMainApp.cpp
+++ b/customer-specific/pasa/src/appMain/SmartDeviceLinkMainApp.cpp
@@ -278,7 +278,7 @@ int main(int argc, char** argv) {
new threads::Thread("ApplinkNotify", new ApplinkNotificationThreadDelegate());
applink_notification_thread->start();
- utils::SubscribeToTerminateSignal(main_namespace::dummy_signal_handler);
+ utils::SubscribeToTerminateSignal(main_namespace::legacy_signal_handler);
threads::Thread::UnmaskSignals();
pause();
diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc
index 8ae94ac50..30783a52a 100644
--- a/src/appMain/life_cycle.cc
+++ b/src/appMain/life_cycle.cc
@@ -373,7 +373,9 @@ bool LifeCycle::InitMessageSystem() {
#endif // CUSTOMER_PASA
void LifeCycle::StopComponents() {
+ LOG4CXX_TRACE(logger_, "enter");
if (components_started == false) {
+ LOG4CXX_TRACE(logger_, "exit");
LOG4CXX_ERROR(logger_, "Components wasn't started");
return;
}
@@ -490,6 +492,7 @@ void LifeCycle::StopComponents() {
}
#endif // TIME_TESTER
components_started =false;
+ LOG4CXX_TRACE(logger_, "exit");
}
} // namespace main_namespace
diff --git a/src/appMain/signal_handlers.cc b/src/appMain/signal_handlers.cc
index 06684a860..51757358e 100644
--- a/src/appMain/signal_handlers.cc
+++ b/src/appMain/signal_handlers.cc
@@ -32,14 +32,17 @@
#include "signal_handlers.h"
#include "life_cycle.h"
+#include "utils/logger.h"
namespace main_namespace {
+CREATE_LOGGERPTR_GLOBAL(logger_, "SmartDeviceLinkMainApp")
void dummy_signal_handler(int32_t signal) {
}
void legacy_signal_handler(int32_t signal) {
+ LOG4CXX_TRACE(logger_, "legacy_signal_handler get signal " << signal);
LifeCycle::instance()->StopComponents();
}
-} // namespace main_namespace
+} // namespace main_namespace
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index 611d76f74..775eef0bc 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -117,12 +117,13 @@ ApplicationManagerImpl::~ApplicationManagerImpl() {
mobile_so_factory_ = NULL;
protocol_handler_ = NULL;
media_manager_ = NULL;
+ LOG4CXX_INFO(logger_, "Destroying Policy Handler");
+ policy::PolicyHandler::destroy();
}
bool ApplicationManagerImpl::Stop() {
LOG4CXX_INFO(logger_, "Stop ApplicationManager.");
application_list_update_timer_->stop();
-
try {
UnregisterAllApplications();
} catch (...) {
diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc
index a9f5db075..4421ea8b3 100644
--- a/src/components/application_manager/src/request_controller.cc
+++ b/src/components/application_manager/src/request_controller.cc
@@ -145,9 +145,9 @@ RequestController::TResult RequestController::addMobileRequest(
AutoLock auto_lock(mobile_request_list_lock_);
mobile_request_list_.push_back(request);
- LOG4CXX_INFO(logger_, "RequestController size is "
+ LOG4CXX_INFO(logger_, "mobile_request_list_ size is "
<< mobile_request_list_.size()
- << " Pending request size is "
+ << " pending_request_set_ size is "
<< pending_request_set_.size()
);
}
@@ -171,8 +171,8 @@ RequestController::TResult RequestController::addHMIRequest(
if (0 != raw_ptr->default_timeout()) {
pending_request_set_lock_.Acquire();
pending_request_set_.insert(request_info_ptr);
- LOG4CXX_INFO(logger_, "Pending request size is "
- << pending_request_set_.size() );
+ LOG4CXX_INFO(logger_, "pending_request_set_ size is "
+ << pending_request_set_.size());
UpdateTimer();
pending_request_set_lock_.Release();
} else {
diff --git a/src/components/include/utils/timer_thread.h b/src/components/include/utils/timer_thread.h
index d9041f9c8..3c36786a2 100644
--- a/src/components/include/utils/timer_thread.h
+++ b/src/components/include/utils/timer_thread.h
@@ -172,7 +172,7 @@ class TimerThread {
sync_primitives::Lock state_lock_;
sync_primitives::ConditionalVariable termination_condition_;
volatile bool stop_flag_;
-
+ int32_t calculateMillisecondsLeft();
private:
DISALLOW_COPY_AND_ASSIGN(TimerDelegate);
};
@@ -206,6 +206,8 @@ class TimerThread {
TimerDelegate* delegate_;
//threads::Thread* thread_;
mutable bool is_running_;
+ mutable bool is_looper_;
+
DISALLOW_COPY_AND_ASSIGN(TimerThread);
};
@@ -216,7 +218,8 @@ TimerThread<T>::TimerThread(const char* name, T* callee, void (T::*f)(), bool is
callback_(f),
callee_(callee),
delegate_(NULL),
- is_running_(false) {
+ is_running_(false),
+ is_looper_(is_looper) {
if (is_looper) {
delegate_ = new TimerLooperDelegate(this);
} else {
@@ -273,7 +276,9 @@ template <class T>
void TimerThread<T>::onTimeOut() const {
if (callee_ && callback_) {
(callee_->*callback_)();
- is_running_ = false;
+ if (!is_looper_) {
+ is_running_ = false;
+ }
}
}
@@ -300,16 +305,14 @@ template <class T>
void TimerThread<T>::TimerDelegate::threadMain() {
using sync_primitives::ConditionalVariable;
sync_primitives::AutoLock auto_lock(state_lock_);
- const time_t end_time = time(NULL) + timeout_seconds_;
- int32_t wait_seconds_left = int32_t(difftime(end_time, time(NULL)));
while (!stop_flag_) {
// Sleep
+ int32_t wait_milliseconds_left = TimerDelegate::calculateMillisecondsLeft();
ConditionalVariable::WaitStatus wait_status =
- termination_condition_.WaitFor(auto_lock, wait_seconds_left * 1000);
- wait_seconds_left = int32_t(difftime(end_time, time(NULL)));
+ termination_condition_.WaitFor(auto_lock, wait_milliseconds_left);
// Quit sleeping or continue sleeping in case of spurious wake up
if (ConditionalVariable::kTimeout == wait_status ||
- wait_seconds_left <= 0) {
+ wait_milliseconds_left <= 0) {
break;
}
}
@@ -324,19 +327,7 @@ void TimerThread<T>::TimerLooperDelegate::threadMain() {
using sync_primitives::ConditionalVariable;
sync_primitives::AutoLock auto_lock(TimerDelegate::state_lock_);
while (!TimerDelegate::stop_flag_) {
- time_t cur_time = time(NULL);
- time_t end_time = std::numeric_limits<time_t>::max();
- if (TimerDelegate::timeout_seconds_ + cur_time > TimerDelegate::timeout_seconds_) { // no overflow occurred
- end_time = cur_time + TimerDelegate::timeout_seconds_;
- }
-
- int64_t wait_seconds_left = static_cast<int64_t>(difftime(end_time, cur_time));
- int32_t wait_milliseconds_left = std::numeric_limits<int32_t>::max();
- const int32_t millisecconds_in_second = 1000;
- if (wait_seconds_left < std::numeric_limits<int32_t>::max() / millisecconds_in_second) {
- wait_milliseconds_left = millisecconds_in_second * wait_seconds_left;
- }
-
+ int32_t wait_milliseconds_left = TimerDelegate::calculateMillisecondsLeft();
ConditionalVariable::WaitStatus wait_status =
TimerDelegate::termination_condition_.WaitFor(auto_lock, wait_milliseconds_left);
// Quit sleeping or continue sleeping in case of spurious wake up
@@ -348,7 +339,6 @@ void TimerThread<T>::TimerLooperDelegate::threadMain() {
LOG4CXX_DEBUG(logger_, "Timeout reset force: " << TimerDelegate::timeout_seconds_);
}
}
- TimerDelegate::stop_flag_ = false;
}
@@ -359,6 +349,8 @@ bool TimerThread<T>::TimerDelegate::exitThreadMain() {
stop_flag_ = true;
}
termination_condition_.NotifyOne();
+ // FIXME(AKutsan)
+ {sync_primitives::AutoLock wait_for_thread_main(state_lock_);}
return true;
}
@@ -368,6 +360,22 @@ void TimerThread<T>::TimerDelegate::setTimeOut(const uint32_t timeout_seconds) {
termination_condition_.NotifyOne();
}
+template <class T>
+int32_t TimerThread<T>::TimerThread::TimerDelegate::calculateMillisecondsLeft() {
+ time_t cur_time = time(NULL);
+ time_t end_time = std::numeric_limits<time_t>::max();
+ if (TimerDelegate::timeout_seconds_ + cur_time > TimerDelegate::timeout_seconds_) { // no overflow occurred
+ end_time = cur_time + TimerDelegate::timeout_seconds_;
+ }
+
+ int64_t wait_seconds_left = static_cast<int64_t>(difftime(end_time, cur_time));
+ int32_t wait_milliseconds_left = std::numeric_limits<int32_t>::max();
+ const int32_t millisecconds_in_second = 1000;
+ if (wait_seconds_left < std::numeric_limits<int32_t>::max() / millisecconds_in_second) {
+ wait_milliseconds_left = millisecconds_in_second * wait_seconds_left;
+ }
+ return wait_milliseconds_left;
+}
} // namespace timer
diff --git a/src/components/utils/src/conditional_variable_posix.cc b/src/components/utils/src/conditional_variable_posix.cc
index 37751b097..a89f8cab6 100644
--- a/src/components/utils/src/conditional_variable_posix.cc
+++ b/src/components/utils/src/conditional_variable_posix.cc
@@ -126,7 +126,7 @@ ConditionalVariable::WaitStatus ConditionalVariable::WaitFor(
break;
}
default: {
- LOG4CXX_ERROR(logger_, "Failed to timewait for conditional variable");
+ LOG4CXX_ERROR(logger_, "Failed to timewait for conditional variable timedwait_status: " << timedwait_status);
}
}
diff --git a/src/components/utils/src/threads/posix_thread.cc b/src/components/utils/src/threads/posix_thread.cc
index d52ad9467..faaadd673 100644
--- a/src/components/utils/src/threads/posix_thread.cc
+++ b/src/components/utils/src/threads/posix_thread.cc
@@ -187,7 +187,7 @@ bool Thread::startWithOptions(const ThreadOptions& options) {
pthread_result = pthread_create(&thread_handle_, &attributes, threadFunc, delegate_);
isThreadRunning_ = (pthread_result == EOK);
if (!isThreadRunning_) {
- LOG4CXX_WARN(logger_, "Couldn't cancel thread. Error code = "
+ LOG4CXX_WARN(logger_, "Couldn't create thread. Error code = "
<< pthread_result << "(\"" << strerror(pthread_result) << "\")");
} else {
LOG4CXX_INFO(logger_,"Created thread: " << name_);