From 27181a9a38d62a84c89f4a34abae2a1d9d49000d Mon Sep 17 00:00:00 2001 From: Rithesh Gowda Date: Thu, 17 Oct 2013 17:16:09 +0530 Subject: [PATCH] Added support for Event creation in worker thread Change-Id: Ie30c7def97a25711d8d18cf0521a7c5a49dfd666 Signed-off-by: Rithesh Gowda --- inc/FBaseRtEvent.h | 1 - src/base/inc/FBaseRt_Event.h | 1 - src/base/runtime/FBaseRt_Event.cpp | 16 ++++++++++++++-- src/base/runtime/FBaseRt_EventManager.cpp | 7 +++++-- src/base/runtime/FBaseRt_MainThreadImpl.cpp | 1 + src/base/runtime/FBaseRt_ThreadImpl.cpp | 17 +++++++++++++++++ src/base/runtime/FBaseRt_ThreadImpl.h | 3 +++ 7 files changed, 40 insertions(+), 6 deletions(-) mode change 100755 => 100644 src/base/inc/FBaseRt_Event.h mode change 100755 => 100644 src/base/runtime/FBaseRt_Event.cpp diff --git a/inc/FBaseRtEvent.h b/inc/FBaseRtEvent.h index 2f4501b..b7ba556 100644 --- a/inc/FBaseRtEvent.h +++ b/inc/FBaseRtEvent.h @@ -37,7 +37,6 @@ class IEventListener; * @since 2.0 * * The %Event class provides methods for notifying events with argument to its listeners. -* Because bounded to either default thread or event-driven thread, it cannot be created on worker thread. * It supports two types of listeners; one is called on the thread where the event is fired, and another is called on the thread where the listener was registered. * * @code diff --git a/src/base/inc/FBaseRt_Event.h b/src/base/inc/FBaseRt_Event.h old mode 100755 new mode 100644 index 884968b..312e37e --- a/src/base/inc/FBaseRt_Event.h +++ b/src/base/inc/FBaseRt_Event.h @@ -174,7 +174,6 @@ protected: * @return An error code * @exception E_SUCCESS This method was successful. * @exception E_INVALID_STATE The event was already initialized. - * @exception E_INVALID_OPERATION This was called by a worker thread. * * @remark A derived class from _Event should call this method */ diff --git a/src/base/runtime/FBaseRt_Event.cpp b/src/base/runtime/FBaseRt_Event.cpp old mode 100755 new mode 100644 index 5d6c58c..4b1fbde --- a/src/base/runtime/FBaseRt_Event.cpp +++ b/src/base/runtime/FBaseRt_Event.cpp @@ -27,6 +27,7 @@ #include #include "FBaseRt_Event.h" #include "FBaseRt_EventManager.h" +#include "FBaseRt_ThreadImpl.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -130,9 +131,20 @@ _Event::AddListener(const IEventListener& listener, bool calledByCallerThread) if (calledByCallerThread) { + _ThreadImpl* pThreadImpl = _ThreadImpl::GetCurrentThreadImpl(); + SysTryReturnResult(NID_BASE_RT, pThreadImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] This is not OSP thread."); + + ThreadType threadType = pThreadImpl->GetThreadType(); + SysTryReturnResult(NID_BASE_RT, threadType != THREAD_TYPE_WORKER, E_INVALID_OPERATION, "The caller thread is not an event driven thread."); + + ClearLastResult(); _EventManager* pEventManager = _EventManager::GetCurrentEventManager(); - SysTryReturnResult(NID_BASE_RT, pEventManager != null, E_INVALID_OPERATION - , "The caller thread is not an event driven thread."); + r = GetLastResult(); + if (IsFailed(r)) + { + SysPropagate(NID_BASE_RT, r); + return r; + } eventManager = pEventManager->GetHandle(); } diff --git a/src/base/runtime/FBaseRt_EventManager.cpp b/src/base/runtime/FBaseRt_EventManager.cpp index 4713ce3..834066c 100644 --- a/src/base/runtime/FBaseRt_EventManager.cpp +++ b/src/base/runtime/FBaseRt_EventManager.cpp @@ -292,8 +292,11 @@ _EventManager::GetCurrentEventManager(void) SysTryReturn(NID_BASE_RT, pThreadImpl != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] This is not OSP thread."); ThreadType threadType = pThreadImpl->GetThreadType(); - SysTryReturn(NID_BASE_RT, threadType != THREAD_TYPE_WORKER, null, E_INVALID_OPERATION, - "[E_INVALID_OPERATION] This is a worker thread."); + if (threadType == THREAD_TYPE_WORKER) + { + pThreadImpl = _ThreadImpl::GetMainThreadImpl(); + SysTryReturn(NID_BASE_RT, pThreadImpl != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] This is not OSP thread."); + } _EventManager* pEventManager = pThreadImpl->GetEventManager(); SysTryReturn(NID_BASE_RT, pEventManager != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Event manager is not initialized."); diff --git a/src/base/runtime/FBaseRt_MainThreadImpl.cpp b/src/base/runtime/FBaseRt_MainThreadImpl.cpp index d7b64e8..e0f61af 100644 --- a/src/base/runtime/FBaseRt_MainThreadImpl.cpp +++ b/src/base/runtime/FBaseRt_MainThreadImpl.cpp @@ -93,6 +93,7 @@ _MainThreadImpl::Initialize(void) _ThreadImpl::Initialize(); + SetMainThread(); __pEventDispatcher = pEventDispatcher; return E_SUCCESS; diff --git a/src/base/runtime/FBaseRt_ThreadImpl.cpp b/src/base/runtime/FBaseRt_ThreadImpl.cpp index 9a15e06..ef7b50d 100644 --- a/src/base/runtime/FBaseRt_ThreadImpl.cpp +++ b/src/base/runtime/FBaseRt_ThreadImpl.cpp @@ -37,6 +37,7 @@ namespace Tizen { namespace Base { namespace Runtime { __thread Thread* pCurrentThread = null; +Thread* _ThreadImpl::__pDefaultThread = null; _ThreadImpl* _ThreadImpl::GetCurrentThreadImpl(void) @@ -290,4 +291,20 @@ _ThreadImpl::GetEventManager(void) } +void +_ThreadImpl::SetMainThread(void) +{ + __pDefaultThread = _pThread; +} + +_ThreadImpl* +_ThreadImpl::GetMainThreadImpl(void) +{ + if (__pDefaultThread != null) + { + return __pDefaultThread->__pThreadImpl; + } + + return null; +} } } } // Tizen::Base::Runtime diff --git a/src/base/runtime/FBaseRt_ThreadImpl.h b/src/base/runtime/FBaseRt_ThreadImpl.h index 6667f76..999fd4a 100644 --- a/src/base/runtime/FBaseRt_ThreadImpl.h +++ b/src/base/runtime/FBaseRt_ThreadImpl.h @@ -72,6 +72,7 @@ public: static _ThreadImpl* GetCurrentThreadImpl(void); + static _ThreadImpl* GetMainThreadImpl(void); protected: virtual result Initialize(void); @@ -84,6 +85,7 @@ protected: void SetThread(Thread* pThread); void SetNativeThread(pthread_t nativeThread); + void SetMainThread(void); private: static void* ThreadProc(void* pParam); @@ -99,6 +101,7 @@ private: pthread_t __nativeThread; int __exitCode; _EventManager* __pEventManager; + static Thread* __pDefaultThread; }; // _ThreadImpl } } } // Tizen::Base::Runtime -- 2.7.4