diff options
author | Seigo Nonaka <nona@google.com> | 2018-02-06 20:56:38 -0800 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2018-02-08 11:50:53 -0800 |
commit | 49292611f286fc8cea34c1739933455222960954 (patch) | |
tree | 2e9c152eb26da9fcad08e39788563d8a65aad2c7 | |
parent | 4de86391218f9fa2d1ba15d78cd80514fb5ce43d (diff) | |
download | minikin-49292611f286fc8cea34c1739933455222960954.tar.gz |
Use own private mutex for guarding pool in BreakerPool
To be independent from gMinikinLock, introduce own private mutex for
guarding mPool in ICULineBreakerPoolImpl.
Here is a raw performance score:
StaticLayout creation time:
MeasuredText Balanced Hyphenation : 704,994 -> 702,566: (-0.3%)
MeasuredText Balanced NoHyphenation: 539,847 -> 545,703: (+1.1%)
MeasuredText Greedy Hyphenation : 494,681 -> 494,209: (-0.1%)
MeasuredText Greedy NoHyphenation : 488,553 -> 492,238: (+0.8%)
RandomText Balanced Hyphenation : 18,148,346 -> 18,186,174: (+0.2%)
RandomText Balanced NoHyphenation : 7,631,448 -> 7,650,471: (+0.2%)
RandomText Greedy Hyphenation : 7,515,126 -> 7,580,007: (+0.9%)
RandomText Greedy NoHyphenation : 7,575,344 -> 7,594,000: (+0.2%)
MeasuredText creation time:
NoStyled Hyphenation : 18,004,921 -> 18,084,752: (+0.4%)
NoStyled Hyphenation WidthOnly : 17,459,350 -> 17,583,465: (+0.7%)
NoStyled NoHyphenation : 7,601,492 -> 7,617,908: (+0.2%)
NoStyled NoHyphenation WidthOnly : 7,122,189 -> 7,151,384: (+0.4%)
Styled Hyphenation : 14,961,242 -> 14,842,647: (-0.8%)
Styled Hyphenation WidthOnly : 14,067,121 -> 13,925,084: (-1.0%)
Styled NoHyphenation : 14,470,800 -> 14,378,989: (-0.6%)
Styled NoHyphenation WidthOnly : 13,568,743 -> 13,587,057: (+0.1%)
StaticLayout draw time:
MeasuredText NoStyled : 658,118 -> 667,373: (+1.4%)
MeasuredText NoStyled WithoutCache : 654,450 -> 651,152: (-0.5%)
MeasuredText Styled : 897,991 -> 856,718: (-4.6%)
MeasuredText Styled WithoutCache : 911,318 -> 909,806: (-0.2%)
RandomText NoStyled : 574,551 -> 585,543: (+1.9%)
RandomText NoStyled WithoutCache : 6,918,073 -> 6,904,898: (-0.2%)
RandomText Styled : 2,978,776 -> 2,964,139: (-0.5%)
RandomText Styled WithoutCache : 3,402,067 -> 3,411,934: (+0.3%)
Bug: 37567215
Test: minikin tests
Change-Id: I062b44ea87f3b0abaf859c738605b67d2ba0fbf2
-rw-r--r-- | libs/minikin/WordBreaker.cpp | 4 | ||||
-rw-r--r-- | libs/minikin/WordBreaker.h | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/libs/minikin/WordBreaker.cpp b/libs/minikin/WordBreaker.cpp index 12d64f8..dae5cab 100644 --- a/libs/minikin/WordBreaker.cpp +++ b/libs/minikin/WordBreaker.cpp @@ -43,7 +43,7 @@ static icu::BreakIterator* createNewIterator(const Locale& locale) { ICULineBreakerPool::Slot ICULineBreakerPoolImpl::acquire(const Locale& locale) { const uint64_t id = locale.getIdentifier(); - android::AutoMutex _l(gMinikinLock); + std::lock_guard<std::mutex> lock(mMutex); for (auto i = mPool.begin(); i != mPool.end(); i++) { if (i->localeId == id) { Slot slot = std::move(*i); @@ -60,7 +60,7 @@ void ICULineBreakerPoolImpl::release(ICULineBreakerPool::Slot&& slot) { if (slot.breaker.get() == nullptr) { return; // Already released slot. Do nothing. } - android::AutoMutex _l(gMinikinLock); + std::lock_guard<std::mutex> lock(mMutex); if (mPool.size() >= MAX_POOL_SIZE) { // Pool is full. Move to local variable, so that the given slot will be released when the // variable leaves the scope. diff --git a/libs/minikin/WordBreaker.h b/libs/minikin/WordBreaker.h index 84d1d62..ca4648e 100644 --- a/libs/minikin/WordBreaker.h +++ b/libs/minikin/WordBreaker.h @@ -24,6 +24,7 @@ #define MINIKIN_WORD_BREAKER_H #include <list> +#include <mutex> #include <unicode/brkiter.h> @@ -76,7 +77,8 @@ protected: size_t getPoolSize() const { return mPool.size(); } private: - std::list<Slot> mPool; // Guarded by gMinikinLock + std::list<Slot> mPool; // Guarded by mMutex + std::mutex mMutex; }; class WordBreaker { |