Changeset 207156 in webkit


Ignore:
Timestamp:
Oct 11, 2016 12:35:36 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Add SynchronizedFixedQueue class
https://bugs.webkit.org/show_bug.cgi?id=162478

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2016-10-11
Reviewed by Geoffrey Garen.

Source/WTF:

This class represents a simple producer/consumer worker. It facilitates
synchronizing enqueuing to and dequeuing from a fixed size-queue. It uses
a single lock and a single condition to synchronize all its members among
the working threads. This means a single thread is active at any time and
and the other threads are blocked waiting for the lock to be released. Or
they are sleeping waiting for the condition to be satisfied.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/SynchronizedFixedQueue.h: Added.

(WTF::SynchronizedFixedQueue::SynchronizedFixedQueue):
(WTF::SynchronizedFixedQueue::open): Restore the queue to its original state.
(WTF::SynchronizedFixedQueue::close): Wake all the sleeping threads with a closing state.
(WTF::SynchronizedFixedQueue::isOpen): Does the queue accept new items?
(WTF::SynchronizedFixedQueue::enqueue): Enqueue an item into the queue.
(WTF::SynchronizedFixedQueue::dequeue): Dequeue an item form the queue.

Tools:

Add a new test for SynchronizedFixedQueue. The test defines a new class
called ToUpperConverter which converts strings from lower case to upper
case. It creates two threads : (1) produce thread and (2) consume thread.
Here is what each thread does:

  1. Main threads: Enqueues lower case strings into m_lowerQueue.
  2. Produce thread: Dequeues lower case strings from m_lowerQueue and enqueue their upper case strings in the m_upperQueue.
  3. Consume thread: Dequeues upper case strings from m_upperQueue.
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp: Added.

(TestWebKitAPI::textItem): A helper function which returns a lower case string given an index.
(TestWebKitAPI::toUpper): A helper function which Returns the upper case of a string.
(TestWebKitAPI::ToUpperConverter::ToUpperConverter):
(TestWebKitAPI::ToUpperConverter::produceQueue): Returns a workQueue for the produce thread.
(TestWebKitAPI::ToUpperConverter::consumeQueue): Returns a workQueue for the consume thread.
(TestWebKitAPI::ToUpperConverter::startProducing): Creates a thread for the producer.
(TestWebKitAPI::ToUpperConverter::startConsuming): Creates a thread for the consumer.
(TestWebKitAPI::ToUpperConverter::start): Starts both the producer and the consumer threads.
(TestWebKitAPI::ToUpperConverter::stopProducing): Terminates the producer thread.
(TestWebKitAPI::ToUpperConverter::stopConsuming): Terminates the consumer thread.
(TestWebKitAPI::ToUpperConverter::stop): Terminates both the producer and the consumer threads.
(TestWebKitAPI::ToUpperConverter::enqueueLower): Adds a lower case string to the m_lowerQueue on the main thread.
(TestWebKitAPI::ToUpperConverter::isProducing): Returns whether the producing thread is active.
(TestWebKitAPI::ToUpperConverter::isConsuming): Returns whether the consuming thread is active.
(TestWebKitAPI::ToUpperConverter::produceCount): Returns the number of produced elements.
(TestWebKitAPI::ToUpperConverter::consumeCount): Returns the number of consumed elements.
(TestWebKitAPI::TEST):

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r207151 r207156  
     12016-10-11  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Add SynchronizedFixedQueue class
     4        https://bugs.webkit.org/show_bug.cgi?id=162478
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        This class represents a simple producer/consumer worker. It facilitates
     9        synchronizing enqueuing to and dequeuing from a fixed size-queue. It uses
     10        a single lock and a single condition to synchronize all its members among
     11        the working threads. This means a single thread is active at any time and
     12        and the other threads are blocked waiting for the lock to be released. Or
     13        they are sleeping waiting for the condition to be satisfied.
     14
     15        * WTF.xcodeproj/project.pbxproj:
     16        * wtf/SynchronizedFixedQueue.h: Added.
     17        (WTF::SynchronizedFixedQueue::SynchronizedFixedQueue):
     18        (WTF::SynchronizedFixedQueue::open): Restore the queue to its original state.
     19        (WTF::SynchronizedFixedQueue::close): Wake all the sleeping threads with a closing state.
     20        (WTF::SynchronizedFixedQueue::isOpen): Does the queue accept new items?
     21        (WTF::SynchronizedFixedQueue::enqueue): Enqueue an item into the queue.
     22        (WTF::SynchronizedFixedQueue::dequeue): Dequeue an item form the queue.
     23
    1242016-10-11  Alex Christensen  <achristensen@webkit.org>
    225
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r206691 r207156  
    120120                539EB0631D55284200C82EF7 /* LEBDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 539EB0621D55284200C82EF7 /* LEBDecoder.h */; };
    121121                553071CA1C40427200384898 /* TinyLRUCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 553071C91C40427200384898 /* TinyLRUCache.h */; };
     122                5597F82F1D94B9970066BC21 /* SynchronizedFixedQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */; };
    122123                5C7C88D41D0A3A0A009D2F6D /* UniqueRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C7C88D31D0A3A0A009D2F6D /* UniqueRef.h */; };
    123124                70A993FE1AD7151300FA615B /* SymbolRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 70A993FC1AD7151300FA615B /* SymbolRegistry.cpp */; };
     
    464465                539EB0621D55284200C82EF7 /* LEBDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LEBDecoder.h; sourceTree = "<group>"; };
    465466                553071C91C40427200384898 /* TinyLRUCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyLRUCache.h; sourceTree = "<group>"; };
     467                5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SynchronizedFixedQueue.h; sourceTree = "<group>"; };
    466468                5B43383A5D0B463C9433D933 /* IndexMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexMap.h; sourceTree = "<group>"; };
    467469                5C7C88D31D0A3A0A009D2F6D /* UniqueRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniqueRef.h; sourceTree = "<group>"; };
     
    10241026                                0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */,
    10251027                                0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */,
     1028                                5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */,
    10261029                                0FB317C31C488001007E395A /* SystemTracing.h */,
    10271030                                A8A4731A151A825B004123FF /* TemporaryChange.h */,
     
    14081411                                1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */,
    14091412                                A8A4743B151A825B004123FF /* StringBuffer.h in Headers */,
     1413                                5597F82F1D94B9970066BC21 /* SynchronizedFixedQueue.h in Headers */,
    14101414                                A8A4743D151A825B004123FF /* StringBuilder.h in Headers */,
    14111415                                430B47891AAAAC1A001223DA /* StringCommon.h in Headers */,
  • trunk/Tools/ChangeLog

    r207153 r207156  
     12016-10-11  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Add SynchronizedFixedQueue class
     4        https://bugs.webkit.org/show_bug.cgi?id=162478
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add a new test for SynchronizedFixedQueue. The test defines a new class
     9        called ToUpperConverter which converts strings from lower case to upper
     10        case. It creates two threads : (1) produce thread and (2) consume thread.
     11        Here is what each thread does:
     12
     13        1. Main threads: Enqueues lower case strings into m_lowerQueue.
     14        2. Produce thread: Dequeues lower case strings from m_lowerQueue and
     15           enqueue their upper case strings in the m_upperQueue.
     16        3. Consume thread: Dequeues upper case strings from m_upperQueue.
     17
     18        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     19        * TestWebKitAPI/Tests/WTF/SynchronizedFixedQueue.cpp: Added.
     20        (TestWebKitAPI::textItem): A helper function which returns a lower case string given an index.
     21        (TestWebKitAPI::toUpper): A helper function which Returns the upper case of a string.
     22        (TestWebKitAPI::ToUpperConverter::ToUpperConverter):
     23        (TestWebKitAPI::ToUpperConverter::produceQueue): Returns a workQueue for the produce thread.
     24        (TestWebKitAPI::ToUpperConverter::consumeQueue): Returns a workQueue for the consume thread.
     25        (TestWebKitAPI::ToUpperConverter::startProducing): Creates a thread for the producer.
     26        (TestWebKitAPI::ToUpperConverter::startConsuming): Creates a thread for the consumer.
     27        (TestWebKitAPI::ToUpperConverter::start): Starts both the producer and the consumer threads.
     28        (TestWebKitAPI::ToUpperConverter::stopProducing): Terminates the producer thread.
     29        (TestWebKitAPI::ToUpperConverter::stopConsuming): Terminates the consumer thread.
     30        (TestWebKitAPI::ToUpperConverter::stop): Terminates both the producer and the consumer threads.
     31        (TestWebKitAPI::ToUpperConverter::enqueueLower): Adds a lower case string to the m_lowerQueue on the main thread.
     32        (TestWebKitAPI::ToUpperConverter::isProducing): Returns whether the producing thread is active.
     33        (TestWebKitAPI::ToUpperConverter::isConsuming): Returns whether the consuming thread is active.
     34        (TestWebKitAPI::ToUpperConverter::produceCount): Returns the number of produced elements.
     35        (TestWebKitAPI::ToUpperConverter::consumeCount): Returns the number of consumed elements.
     36        (TestWebKitAPI::TEST):
     37
    1382016-10-11  Megan Gardner  <megan_gardner@apple.com>
    239
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r206922 r207156  
    141141                536770341CC8022800D425B1 /* WebScriptObjectDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */; };
    142142                536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 536770351CC812F900D425B1 /* WebScriptObjectDescription.html */; };
     143                5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */; };
    143144                5714ECB91CA8B5B000051AC8 /* DownloadRequestOriginalURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */; };
    144145                5714ECBB1CA8BFE400051AC8 /* DownloadRequestOriginalURLFrame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */; };
     
    917918                536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptObjectDescription.mm; sourceTree = "<group>"; };
    918919                536770351CC812F900D425B1 /* WebScriptObjectDescription.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WebScriptObjectDescription.html; sourceTree = "<group>"; };
     920                5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SynchronizedFixedQueue.cpp; sourceTree = "<group>"; };
    919921                5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURL.html; sourceTree = "<group>"; };
    920922                5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURLFrame.html; sourceTree = "<group>"; };
     
    17961798                                C01363C713C3997300EF3964 /* StringOperators.cpp */,
    17971799                                7C74D42D188228F300E5ED57 /* StringView.cpp */,
     1800                                5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */,
    17981801                                0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */,
    17991802                                5C5E633D1D0B67940085A025 /* UniqueRef.cpp */,
     
    22902293                                7C83DF371D0A590C00FEBCF3 /* StringImpl.cpp in Sources */,
    22912294                                7C83DF381D0A590C00FEBCF3 /* StringOperators.cpp in Sources */,
     2295                                5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */,
    22922296                                7C83DF3A1D0A590C00FEBCF3 /* StringView.cpp in Sources */,
    22932297                                7C83DF3D1D0A590C00FEBCF3 /* TemporaryChange.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.