Skip to content

Commit

Permalink
Merge r222530 - Followup (r222427): SynchronizedFixedQueue should not…
Browse files Browse the repository at this point in the history
… have a public constructor

https://bugs.webkit.org/show_bug.cgi?id=177458

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2017-09-26
Reviewed by Tim Horton.

Source/WebCore:

ImageFrameCache::decodingQueue() and frameRequestQueue() should return
raw references instead of Ref objects.

* platform/graphics/ImageFrameCache.cpp:
(WebCore::ImageFrameCache::decodingQueue):
(WebCore::ImageFrameCache::frameRequestQueue):
(WebCore::ImageFrameCache::startAsyncDecodingQueue):
* platform/graphics/ImageFrameCache.h:

Source/WTF:

Since SynchronizedFixedQueue is now derived from ThreadSafeRefCounted<SynchronizedFixedQueue>,
the standard way to have an instance of it is to call SynchronizedFixedQueue::create()
which returns a Ref<SynchronizedFixedQueue>. Now it does not make sense to still
have the constructor public.

* wtf/SynchronizedFixedQueue.h:
(WTF::SynchronizedFixedQueue::SynchronizedFixedQueue):

Tools:

Fix the definition and the creation of SynchronizedFixedQueue.

* TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp:
(TestWebKitAPI::ToUpperConverter::ToUpperConverter):
(TestWebKitAPI::ToUpperConverter::startProducing):
(TestWebKitAPI::ToUpperConverter::startConsuming):
(TestWebKitAPI::ToUpperConverter::stopProducing):
(TestWebKitAPI::ToUpperConverter::stopConsuming):
(TestWebKitAPI::ToUpperConverter::enqueueLower):
  • Loading branch information
Said Abou-Hallawa authored and carlosgcampos committed Oct 16, 2017
1 parent ec125d1 commit 7874348
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 18 deletions.
15 changes: 15 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,18 @@
2017-09-26 Said Abou-Hallawa <sabouhallawa@apple.com>

Followup (r222427): SynchronizedFixedQueue should not have a public constructor
https://bugs.webkit.org/show_bug.cgi?id=177458

Reviewed by Tim Horton.

Since SynchronizedFixedQueue is now derived from ThreadSafeRefCounted<SynchronizedFixedQueue>,
the standard way to have an instance of it is to call SynchronizedFixedQueue::create()
which returns a Ref<SynchronizedFixedQueue>. Now it does not make sense to still
have the constructor public.

* wtf/SynchronizedFixedQueue.h:
(WTF::SynchronizedFixedQueue::SynchronizedFixedQueue):

2017-09-23 Said Abou-Hallawa <sabouhallawa@apple.com>

Images may render partial frames even after loading all the encoded data
Expand Down
10 changes: 5 additions & 5 deletions Source/WTF/wtf/SynchronizedFixedQueue.h
Expand Up @@ -40,11 +40,6 @@ class SynchronizedFixedQueue : public ThreadSafeRefCounted<SynchronizedFixedQueu
return adoptRef(*new SynchronizedFixedQueue());
}

SynchronizedFixedQueue()
{
static_assert(!((BufferSize - 1) & BufferSize), "BufferSize must be power of 2.");
}

void open()
{
LockHolder lockHolder(m_mutex);
Expand Down Expand Up @@ -113,6 +108,11 @@ class SynchronizedFixedQueue : public ThreadSafeRefCounted<SynchronizedFixedQueu
}

private:
SynchronizedFixedQueue()
{
static_assert(!((BufferSize - 1) & BufferSize), "BufferSize must be power of 2.");
}

Lock m_mutex;
Condition m_condition;

Expand Down
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
2017-09-26 Said Abou-Hallawa <sabouhallawa@apple.com>

Followup (r222427): SynchronizedFixedQueue should not have a public constructor
https://bugs.webkit.org/show_bug.cgi?id=177458

Reviewed by Tim Horton.

ImageFrameCache::decodingQueue() and frameRequestQueue() should return
raw references instead of Ref objects.

* platform/graphics/ImageFrameCache.cpp:
(WebCore::ImageFrameCache::decodingQueue):
(WebCore::ImageFrameCache::frameRequestQueue):
(WebCore::ImageFrameCache::startAsyncDecodingQueue):
* platform/graphics/ImageFrameCache.h:

2017-09-23 Said Abou-Hallawa <sabouhallawa@apple.com>

Images may render partial frames even after loading all the encoded data
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/ImageFrameCache.cpp
Expand Up @@ -262,15 +262,15 @@ void ImageFrameCache::cacheNativeImageAtIndexAsync(NativeImagePtr&& nativeImage,
m_image->imageFrameAvailableAtIndex(index);
}

Ref<WorkQueue> ImageFrameCache::decodingQueue()
WorkQueue& ImageFrameCache::decodingQueue()
{
if (!m_decodingQueue)
m_decodingQueue = WorkQueue::create("org.webkit.ImageDecoder", WorkQueue::Type::Serial, WorkQueue::QOS::Default);

return *m_decodingQueue;
}

Ref<ImageFrameCache::FrameRequestQueue> ImageFrameCache::frameRequestQueue()
ImageFrameCache::FrameRequestQueue& ImageFrameCache::frameRequestQueue()
{
if (!m_frameRequestQueue)
m_frameRequestQueue = FrameRequestQueue::create();
Expand All @@ -284,7 +284,7 @@ void ImageFrameCache::startAsyncDecodingQueue()
return;

// We need to protect this, m_decodingQueue and m_decoder from being deleted while we are in the decoding loop.
decodingQueue()->dispatch([protectedThis = makeRef(*this), protectedDecodingQueue = decodingQueue(), protectedFrameRequestQueue = frameRequestQueue(), protectedDecoder = makeRef(*m_decoder), sourceURL = sourceURL().string().isolatedCopy()] {
decodingQueue().dispatch([protectedThis = makeRef(*this), protectedDecodingQueue = makeRef(decodingQueue()), protectedFrameRequestQueue = makeRef(frameRequestQueue()), protectedDecoder = makeRef(*m_decoder), sourceURL = sourceURL().string().isolatedCopy()] {
ImageFrameRequest frameRequest;

while (protectedFrameRequestQueue->dequeue(frameRequest)) {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/ImageFrameCache.h
Expand Up @@ -137,8 +137,8 @@ class ImageFrameCache : public ThreadSafeRefCounted<ImageFrameCache> {

struct ImageFrameRequest;
static const int BufferSize = 8;
Ref<WorkQueue> decodingQueue();
Ref<SynchronizedFixedQueue<ImageFrameRequest, BufferSize>> frameRequestQueue();
WorkQueue& decodingQueue();
SynchronizedFixedQueue<ImageFrameRequest, BufferSize>& frameRequestQueue();

const ImageFrame& frameAtIndexCacheIfNeeded(size_t, ImageFrame::Caching, const std::optional<SubsamplingLevel>& = { });

Expand Down
17 changes: 17 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,20 @@
2017-09-26 Said Abou-Hallawa <sabouhallawa@apple.com>

Followup (r222427): SynchronizedFixedQueue should not have a public constructor
https://bugs.webkit.org/show_bug.cgi?id=177458

Reviewed by Tim Horton.

Fix the definition and the creation of SynchronizedFixedQueue.

* TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp:
(TestWebKitAPI::ToUpperConverter::ToUpperConverter):
(TestWebKitAPI::ToUpperConverter::startProducing):
(TestWebKitAPI::ToUpperConverter::startConsuming):
(TestWebKitAPI::ToUpperConverter::stopProducing):
(TestWebKitAPI::ToUpperConverter::stopConsuming):
(TestWebKitAPI::ToUpperConverter::enqueueLower):

2017-09-19 Wenson Hsieh <wenson_hsieh@apple.com>

REGRESSION (r215613): Incorrect corners clipping with border-radius
Expand Down
18 changes: 10 additions & 8 deletions Tools/TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp
Expand Up @@ -56,6 +56,8 @@ template <size_t BufferSize>
class ToUpperConverter {
public:
ToUpperConverter()
: m_lowerQueue(SynchronizedFixedQueue<CString, BufferSize>::create())
, m_upperQueue(SynchronizedFixedQueue<CString, BufferSize>::create())
{
}

Expand All @@ -80,8 +82,8 @@ class ToUpperConverter {

produceQueue()->dispatch([this] {
CString lower;
while (m_lowerQueue.dequeue(lower)) {
m_upperQueue.enqueue(toUpper(lower));
while (m_lowerQueue->dequeue(lower)) {
m_upperQueue->enqueue(toUpper(lower));
EXPECT_TRUE(lower == textItem(m_produceCount++));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
Expand All @@ -96,7 +98,7 @@ class ToUpperConverter {

consumeQueue()->dispatch([this] {
CString upper;
while (m_upperQueue.dequeue(upper)) {
while (m_upperQueue->dequeue(upper)) {
EXPECT_TRUE(upper == toUpper(textItem(m_consumeCount++)));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
Expand All @@ -115,7 +117,7 @@ class ToUpperConverter {
if (!isProducing())
return;

m_lowerQueue.close();
m_lowerQueue->close();
m_produceCloseSemaphore.wait(WallTime::infinity());
m_produceQueue = nullptr;
}
Expand All @@ -125,7 +127,7 @@ class ToUpperConverter {
if (!isConsuming())
return;

m_upperQueue.close();
m_upperQueue->close();
m_consumeCloseSemaphore.wait(WallTime::infinity());
m_consumeQueue = nullptr;
}
Expand All @@ -138,7 +140,7 @@ class ToUpperConverter {

void enqueueLower(const CString& lower)
{
m_lowerQueue.enqueue(lower);
m_lowerQueue->enqueue(lower);
}

bool isProducing() { return m_produceQueue; }
Expand All @@ -148,8 +150,8 @@ class ToUpperConverter {
size_t consumeCount() const { return m_consumeCount; }

private:
SynchronizedFixedQueue<CString, BufferSize> m_lowerQueue;
SynchronizedFixedQueue<CString, BufferSize> m_upperQueue;
Ref<SynchronizedFixedQueue<CString, BufferSize>> m_lowerQueue;
Ref<SynchronizedFixedQueue<CString, BufferSize>> m_upperQueue;
RefPtr<WorkQueue> m_produceQueue;
RefPtr<WorkQueue> m_consumeQueue;
BinarySemaphore m_produceCloseSemaphore;
Expand Down

0 comments on commit 7874348

Please sign in to comment.