From: Sungyeon Woo Date: Thu, 30 May 2013 12:08:21 +0000 (+0900) Subject: applied MutexGuard in FontImpl X-Git-Tag: submit/tizen_2.2/20130714.153149~277^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45b446979b4d032c5c3e7f45f05ad884d4ff1c73;p=framework%2Fosp%2Fuifw.git applied MutexGuard in FontImpl Change-Id: I5ec190496007b021abf71d9b5025b55ed61ea43e Signed-off-by: Sungyeon Woo --- diff --git a/src/graphics/FGrp_FontImpl.cpp b/src/graphics/FGrp_FontImpl.cpp old mode 100755 new mode 100644 index fcdaacb..c2e5c32 --- a/src/graphics/FGrp_FontImpl.cpp +++ b/src/graphics/FGrp_FontImpl.cpp @@ -23,16 +23,19 @@ #include #include +#include #include - #include +#include #include "FGrp_FontImpl.h" #include "FGrp_Font.h" #include "FGrp_ResUtil.h" +using namespace Tizen::Base::Runtime; + #define IF_NOT_INITIALIZED(code) if (this->_pNativeFont == null || this->_pCoordHolder == null) \ { \ code; \ @@ -43,9 +46,59 @@ } #define IsSucceeded(X) (!IsFailed(X)) + +#if 1 +#define CRITICAL_SECTION _MutexGuard __mutexGuard__ +#else +#define CRITICAL_SECTION +#endif + + namespace Tizen { namespace Graphics { +class _MutexGuard +{ +public: + _MutexGuard() + { + Mutex* pMutex = GetMutexInstance(); + pMutex->Acquire(); + } + + ~_MutexGuard() + { + Mutex* pMutex = GetMutexInstance(); + pMutex->Release(); + } + +private: + static void __InitCreateMutex(void) + { + static Mutex mutex; + mutex.Create(); + _MutexGuard::pMutexInstance = &mutex; + } + + static Mutex* GetMutexInstance(void) + { + static pthread_once_t once_block = PTHREAD_ONCE_INIT; + + if (_MutexGuard::pMutexInstance == null) + { + pthread_once(&once_block, __InitCreateMutex); + } + + return _MutexGuard::pMutexInstance; + } + +public: + static Mutex* pMutexInstance; +}; + +Mutex* _MutexGuard::pMutexInstance = null; + + struct _FontCoordHolder { _ResUtil::CoordHolder size; @@ -130,6 +183,7 @@ _FontImpl::~_FontImpl() result _FontImpl::Construct(int style, int vcSize) { + CRITICAL_SECTION; IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY); // convert VC -> PC @@ -151,6 +205,7 @@ _FontImpl::Construct(int style, int vcSize) result _FontImpl::Construct(const Tizen::Base::String& fontName, int style, int vcSize, bool isPathEnabled) { + CRITICAL_SECTION; IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY); // convert VC -> PC @@ -172,6 +227,7 @@ _FontImpl::Construct(const Tizen::Base::String& fontName, int style, int vcSize, result _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, int vcSize) { + CRITICAL_SECTION; IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY); // convert VC -> PC @@ -193,6 +249,7 @@ _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, int vcS result _FontImpl::Construct(int style, float vcSize) { + CRITICAL_SECTION; IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY); // convert VC -> PC @@ -214,6 +271,7 @@ _FontImpl::Construct(int style, float vcSize) result _FontImpl::Construct(const Tizen::Base::String& fontName, int style, float vcSize, bool isPathEnabled) { + CRITICAL_SECTION; IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY); // convert VC -> PC @@ -235,6 +293,7 @@ _FontImpl::Construct(const Tizen::Base::String& fontName, int style, float vcSiz result _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, float vcSize) { + CRITICAL_SECTION; IF_NOT_INITIALIZED(return E_OUT_OF_MEMORY); // convert VC -> PC @@ -256,6 +315,7 @@ _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, float v bool _FontImpl::IsConstructed(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return false); return true; @@ -264,6 +324,7 @@ _FontImpl::IsConstructed(void) const int _FontImpl::GetMaxHeight(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1); int pcMaxHeight = _DoubleToIntForPos(ceil(_pNativeFont->GetMaxHeight().ToDouble())); @@ -285,6 +346,7 @@ _FontImpl::GetMaxHeight(void) const float _FontImpl::GetMaxHeightF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1.0f); float pcMaxHeight = float(ceil(_pNativeFont->GetMaxHeight().ToDouble())); @@ -296,6 +358,7 @@ _FontImpl::GetMaxHeightF(void) const int _FontImpl::GetMaxWidth(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1); int pcMaxWidth = _pNativeFont->GetMaxWidth().ToInt(); @@ -307,6 +370,7 @@ _FontImpl::GetMaxWidth(void) const float _FontImpl::GetMaxWidthF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1.0f); float pcMaxWidth = _pNativeFont->GetMaxWidth().ToFloat(); @@ -318,6 +382,7 @@ _FontImpl::GetMaxWidthF(void) const int _FontImpl::GetAscender(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1); int pcAscender = _pNativeFont->GetAscender().ToInt(); @@ -329,6 +394,7 @@ _FontImpl::GetAscender(void) const float _FontImpl::GetAscenderF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1.0f); float pcAscender = _pNativeFont->GetAscender().ToFloat(); @@ -340,6 +406,7 @@ _FontImpl::GetAscenderF(void) const int _FontImpl::GetDescender(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1); int pcDescender = _pNativeFont->GetDescender().ToInt(); @@ -356,6 +423,7 @@ _FontImpl::GetDescender(void) const float _FontImpl::GetDescenderF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1.0f); float pcDescender = _pNativeFont->GetDescender().ToFloat(); @@ -372,6 +440,7 @@ _FontImpl::GetDescenderF(void) const result _FontImpl::GetLeftBear(wchar_t character, int& vcLeftBear) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); _Util::FixedPoint22_10 pcLeftBear(0); @@ -389,6 +458,7 @@ _FontImpl::GetLeftBear(wchar_t character, int& vcLeftBear) const result _FontImpl::GetLeftBear(wchar_t character, float& vcLeftBear) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); _Util::FixedPoint22_10 pcLeftBear(0); @@ -405,6 +475,7 @@ _FontImpl::GetLeftBear(wchar_t character, float& vcLeftBear) const result _FontImpl::GetRightBear(wchar_t character, int& vcRightBear) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); _Util::FixedPoint22_10 pcRightBear(0); @@ -422,6 +493,7 @@ _FontImpl::GetRightBear(wchar_t character, int& vcRightBear) const result _FontImpl::GetRightBear(wchar_t character, float& vcRightBear) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); _Util::FixedPoint22_10 pcRightBear(0); @@ -438,6 +510,7 @@ _FontImpl::GetRightBear(wchar_t character, float& vcRightBear) const result _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& vcDim, bool outline) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); int dummyCount = 0 ; @@ -463,6 +536,7 @@ _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, Dimension& result _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, FloatDimension& vcDim, bool outline) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); int dummyCount = 0; @@ -482,6 +556,7 @@ _FontImpl::GetTextExtent(const Tizen::Base::String& text, int length, FloatDimen bool _FontImpl::IsBold(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return false); return _pNativeFont->IsBold(); @@ -490,6 +565,7 @@ _FontImpl::IsBold(void) const bool _FontImpl::IsItalic(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return false); return _pNativeFont->IsItalic(); @@ -498,6 +574,7 @@ _FontImpl::IsItalic(void) const bool _FontImpl::IsPlain(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return false); return _pNativeFont->IsPlain(); @@ -506,6 +583,7 @@ _FontImpl::IsPlain(void) const bool _FontImpl::IsStrikeOut(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return false); return _pNativeFont->IsStrikeOut(); @@ -514,6 +592,7 @@ _FontImpl::IsStrikeOut(void) const bool _FontImpl::IsUnderlined(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return false); return _pNativeFont->IsUnderlined(); @@ -522,6 +601,7 @@ _FontImpl::IsUnderlined(void) const int _FontImpl::GetSize(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1); return _pCoordHolder->size.required; @@ -530,6 +610,7 @@ _FontImpl::GetSize(void) const float _FontImpl::GetSizeF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1.0f); return _pCoordHolder->sizeF.required; @@ -538,6 +619,7 @@ _FontImpl::GetSizeF(void) const void _FontImpl::SetStrikeOut(bool strikeOut) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return); _pNativeFont->SetStrikeOut(strikeOut); @@ -548,6 +630,7 @@ _FontImpl::SetStrikeOut(bool strikeOut) void _FontImpl::SetUnderline(bool underline) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return); _pNativeFont->SetUnderline(underline); @@ -558,6 +641,7 @@ _FontImpl::SetUnderline(bool underline) void _FontImpl::SetCharSpace(int vcSpace) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return); // save it @@ -574,6 +658,7 @@ _FontImpl::SetCharSpace(int vcSpace) void _FontImpl::SetCharSpace(float vcSpace) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return); // save it @@ -590,6 +675,7 @@ _FontImpl::SetCharSpace(float vcSpace) int _FontImpl::GetCharSpace(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return 0); return _pCoordHolder->charSpace.required; @@ -598,6 +684,7 @@ _FontImpl::GetCharSpace(void) const float _FontImpl::GetCharSpaceF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return 0.0f); return _pCoordHolder->charSpaceF.required; @@ -606,6 +693,7 @@ _FontImpl::GetCharSpaceF(void) const Tizen::Base::String _FontImpl::GetFaceName(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return ""); return _pNativeFont->GetFaceName(); @@ -614,18 +702,21 @@ _FontImpl::GetFaceName(void) const Tizen::Base::Collection::IList* _FontImpl::GetSystemFontListN(void) { + CRITICAL_SECTION; return _Font::GetSystemFontListN(); } Tizen::Base::String _FontImpl::GetFaceName(const Tizen::Base::String& filePath) { + CRITICAL_SECTION; return _Font::GetFaceName(filePath); } _FontImpl* _FontImpl::CloneN(void) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return null); std::auto_ptr<_FontImpl> pFontImpl(new (std::nothrow) _FontImpl(*this)); @@ -639,6 +730,8 @@ _FontImpl::CloneN(void) Font* _FontImpl::CloneN(const Font& font) { + CRITICAL_SECTION; + // check the validation of input param SysTryReturn(NID_GRP, font.__pImpl && font.__pImpl->IsConstructed(), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid input param given"); @@ -653,6 +746,7 @@ _FontImpl::CloneN(const Font& font) result _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, Dimension& vcDim) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, @@ -680,6 +774,7 @@ _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int start result _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, const Tizen::Base::String& delimiter, int& count, Dimension& vcDim) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, @@ -707,6 +802,7 @@ _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int start result _FontImpl::GetTextExtent(float vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, FloatDimension& vcDim) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, @@ -728,6 +824,7 @@ _FontImpl::GetTextExtent(float vcWidth, const Tizen::Base::String& text, int sta result _FontImpl::GetTextExtent(float vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, const Tizen::Base::String& delimiter, int& count, FloatDimension& vcDim) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, @@ -749,6 +846,7 @@ _FontImpl::GetTextExtent(float vcWidth, const Tizen::Base::String& text, int sta result _FontImpl::SetSize(int vcSize) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, vcSize > 0, E_INVALID_ARG, "Font size should be greater than 0"); @@ -774,6 +872,7 @@ _FontImpl::SetSize(int vcSize) result _FontImpl::SetSize(float vcSize) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, vcSize > 0.0f, E_INVALID_ARG, "Font size should be greater than 0"); @@ -799,6 +898,7 @@ _FontImpl::SetSize(float vcSize) result _FontImpl::SetStyle(int style) { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, style > FONT_STYLE_MIN && style <= (FONT_STYLE_PLAIN | FONT_STYLE_BOLD | FONT_STYLE_ITALIC), E_INVALID_ARG, "Style(%d) is invalid", style); @@ -812,6 +912,7 @@ _FontImpl::SetStyle(int style) int _FontImpl::GetStyle(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return FONT_STYLE_PLAIN); return _pNativeFont->GetStyle(); @@ -820,6 +921,7 @@ _FontImpl::GetStyle(void) const int _FontImpl::GetLeading(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1); int pcLeading = _DoubleToIntForPos(ceil(_pNativeFont->GetLeading().ToDouble())); @@ -841,6 +943,7 @@ _FontImpl::GetLeading(void) const float _FontImpl::GetLeadingF(void) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return -1.0f); float pcLeading = float(ceil(_pNativeFont->GetLeading().ToDouble())); @@ -852,24 +955,28 @@ _FontImpl::GetLeadingF(void) const _FontImpl* _FontImpl::GetInstance(Font& font) { + CRITICAL_SECTION; return (&font != null) ? font.__pImpl : null; } const _FontImpl* _FontImpl::GetInstance(const Font& font) { + CRITICAL_SECTION; return (&font != null) ? font.__pImpl : null; } bool _FontImpl::UpdateDefaultFont(const Tizen::Base::String& key) { + CRITICAL_SECTION; return _Font::UpdateDefaultFont(key); } result _FontImpl::GetTextExtentList(const Tizen::Base::String& string, int startIndex, int length, Tizen::Base::Collection::ArrayListT<_FloatPair>& outList) const { + CRITICAL_SECTION; IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED); SysTryReturnResult(NID_GRP, startIndex >= 0 && length >= 0 && startIndex < string.GetLength(), E_OUT_OF_RANGE,