Fix threading problem with LogcatOnlyMessageBuffer
LogcatOnlyMessageBuffer was originally intended to only use one message by having it be committed (and freed) immediately after it was obtained. This order was guarenteed by synchronizing them, however two potential issues are present with that approach. - A second thread could call obtain before the first thread called commit. This would cause the second thread to throw an exception. - The `messagePrinter` callback could throw an exception while creating the result string. This leaves the object in a unrecoverable state. This change solves both by creating a small circular list of messages to use, which has a number of benefits. - Messages can be seamlessly lost or fail and will be recreated without impacting long-term object state. - A small max queue size can be enforced to limit baseline memory use - Additional temporary messages can be easily created when needed - Most log calls will be able to reuse an existing object from the pool instead of incurring an allocation. - Only operations on the message queue need to be synchronized as all other operations are executed on distinct objects. Bug: 414815071 Test: Checked logging functions Flag: NONE Bugfix Change-Id: I12445ed27f0336b14608f3f46b6e11077f87b1a6
Loading
Please register or sign in to comment