Application of Android 4.4 fence in Surfaceflinger

Source: Internet
Author: User

on-line information about android,fence little Ah, almost no, but this mechanism in the GUI system plays an important role, so I read through the source and comments, and share with you the next fence what is going on?

          Fence is the fence, the role of the fence is very similar to its name A group of threads can use fences to collectively synchronize each other Essentially each thread calls the fence's wait () when it reaches a known state. method blocks up waits for all other participating threads to call The wait () method indicates that they have also reached this state Once all the threads have reached the fence they will collectively unblock and continue to execute The wait () method that causes the program to call the fence is called the fence State

This article is mainly about the theoretical basis of the application of fence in Surfaceflinger , and the exact fence in producer and Consumer The process of buffer processing is how to coordinate their work synchronously, so as to ensure the accuracy of the buffer content, without being tampered with.

First we know that a buffer has the following states:

Free->dequeued->queued->acquired->free

    Free producer Can I apply for him? The answer is wrong, he needs to wait for a signal , which is no_fence this signal because it is possible that the last request for buffer is being job, so wait for consumer to issue , at which time free State >buffer The is like being stopped by a fence, here is the fence wait () or waitforever () method, and so on, a no_ Fencce the signal, the fence will open. Go to the next process.

   DEQUEUED means producer has applied for a has come out of the queue, has not yet entered the queue or canceled buffer , this state of buffer , producer want to modify it is to fill in the Span style= "Font-family:calibri" >ui data, you must wait for a no_fence signal, as there may be other Span style= "Font-family:calibri" >owner is working on it. When the signal is reached, poducer can operate on it, send a no_ FENCE signal.

   QUEUED State, that is, the buffer into the queue, but before this operation needs to wait for a no_fence signal, like the previous step dequeuebuffer no_fence after completion. The signal is received before the queue operation or the buffer operation is canceled. This time its owner becomes bufferqueue .

acquired state that is producer has filled the buffer , as before it will wait until a no_fence signal, and then Consumer to operate on it. When the operation is complete, bufferis released and a no_fence signal is emitted.

You probably know fence's work flow.

When the previous owner issued a job that was completed,fencewill send a signal. When aBufferIs Free, the consumer has completed theBufferRead something or if it's inQueuebufferSome operations have been called after theCancelbufferWhen the producer has completed theBufferThe write operation. If whenBufferInQUEUEDState, this indicates that the producer has completed theBufferThe fill. WhenBufferInDEQUEUEOracquiredState,Fencehas been passed on to consumers or producers, together withBufferOf the owner, this timeFencebe set tono_fence.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.