summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Nosach <ANosach@luxoft.com>2016-04-05 17:02:07 +0300
committerArtem Nosach <ANosach@luxoft.com>2016-04-05 17:08:40 +0300
commit0d69009cc43596e0e23daf1bdcb60f2d7c6e61f6 (patch)
treeac294d85604a5076631e83ddd6651d616bfdcf0b
parentfb0df050932298eaa3da44abda1aa7202e95e313 (diff)
downloadsdl_core-0d69009cc43596e0e23daf1bdcb60f2d7c6e61f6.tar.gz
Add possibility to check current thread in thread class
Implements: APPLINK-22281
-rw-r--r--src/components/include/utils/threads/thread.h6
-rw-r--r--src/components/utils/src/threads/posix_thread.cc6
-rw-r--r--src/components/utils/src/threads/thread_delegate.cc2
3 files changed, 12 insertions, 2 deletions
diff --git a/src/components/include/utils/threads/thread.h b/src/components/include/utils/threads/thread.h
index 7791a4f754..98e0f51f87 100644
--- a/src/components/include/utils/threads/thread.h
+++ b/src/components/include/utils/threads/thread.h
@@ -198,6 +198,12 @@ class Thread {
}
/**
+ * @brief Checks if invoked in this Thread context
+ * @return True if called from this Thread class, false otherwise
+ */
+ bool IsCurrentThread() const;
+
+ /**
* @brief Thread options.
* @return thread options.
*/
diff --git a/src/components/utils/src/threads/posix_thread.cc b/src/components/utils/src/threads/posix_thread.cc
index 5e8d609b67..7b76299475 100644
--- a/src/components/utils/src/threads/posix_thread.cc
+++ b/src/components/utils/src/threads/posix_thread.cc
@@ -151,6 +151,10 @@ PlatformThreadHandle Thread::CurrentId() {
return pthread_self();
}
+bool Thread::IsCurrentThread() const {
+ return pthread_equal(CurrentId(), thread_handle());
+}
+
bool Thread::start(const ThreadOptions& options) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -258,7 +262,7 @@ void Thread::stop() {
void Thread::join() {
LOG4CXX_AUTO_TRACE(logger_);
- DCHECK(!pthread_equal(pthread_self(), handle_));
+ DCHECK_OR_RETURN_VOID(!IsCurrentThread());
stop();
diff --git a/src/components/utils/src/threads/thread_delegate.cc b/src/components/utils/src/threads/thread_delegate.cc
index 0e71ca3f59..417bae5753 100644
--- a/src/components/utils/src/threads/thread_delegate.cc
+++ b/src/components/utils/src/threads/thread_delegate.cc
@@ -47,7 +47,7 @@ ThreadDelegate::~ThreadDelegate() {
void ThreadDelegate::exitThreadMain() {
if (thread_) {
- if (thread_->thread_handle() == pthread_self()) {
+ if (thread_->IsCurrentThread()) {
pthread_exit(NULL);
} else {
pthread_cancel(thread_->thread_handle());