frameworks: Add highly concurrent MessageQueue implementations
Move MessageQueue.java to LegacyMessageQueue.java and add two variants on an optional implemenation which we can switch on via build flag. The 'legacy' MessageQueue class stays the default. ConcurrentMessageQueue and SemiConcurrentMessageQueue keeps the same API from MessageQueue. We enqueue new messages onto a lockless (treiber) stack. Next() walks the stack and enqueues items into a priority queue which is then used to determine the next messages to deliver. This gives us amortized constant time insertions - next() pays the price of O(Log n) inserts. Remove is still a liner time operation as the API around it makes it impossible to remove items without doing a full scan. For ConcurrentMessageQueue, remove() runs in parallel to insert and next(). For SemiConcurrentMessageQueue, remove() and next() are mutually excluded. The difference between ConcurrentMessageQueue and SemiConcurrentMessageQueue is in priority queue implementations. One uses the lockless ConcurrentSkipListSet while the other uses PriorityQueue with a lock around priority queue operations. We are not sure about the average case performance of ConcurrentSkipListSet, hence the 'SemiConcurrent' implementation. Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION Test: atest MessageQueueTest Test: boot phone and use it Bug: 336880969 Change-Id: I69108655dfcde6e54c5bb5d00f3b3b47967d814f
Loading
Please register or sign in to comment