Latency functions in Android

Source: Internet
Author: User
Tags usleep

In Android, latency functions are divided into user space and kernel space:


Kernel space

# Include <Linux/delay. h>

Udelay (int n );

Mdelay (INT n ));

Ndelay (INT n ));

These functions will lead to an endless cycle of CPU and lead to a busy wait of CPU.

Usleep (int n );

Msleep (INT n ));

Nsleep (INT n ));

The difference between the first group and the second group of latency functions is that the first group of latency is a busy wait, and the process cannot be scheduled. The first group of functions can be used to implement short-time and precise waiting in the driver. The second group of functions allows the called process to enter sleep. At this time, the CPU can instead execute the tasks of other processes. The actual latency value of the second group of delay functions will be greater than the set delay time.


User space
# Include <unistd. h>
Unsigned int sleep (unsigned int seconds );
Int usleep (useconds_t USEC );

Latency in milliseconds can be achieved through macro definition:

# Define xxx_msleep (MS) usleep (MS) * 1000)

This article from: http://blog.csdn.net/hp0773/article/details/8257183

In Android, latency functions are divided into user space and kernel space:


Kernel space

# Include <Linux/delay. h>

Udelay (int n );

Mdelay (INT n ));

Ndelay (INT n ));

These functions will lead to an endless cycle of CPU and lead to a busy wait of CPU.

Usleep (int n );

Msleep (INT n ));

Nsleep (INT n ));

The difference between the first group and the second group of latency functions is that the first group of latency is a busy wait, and the process cannot be scheduled. The first group of functions can be used to implement short-time and precise waiting in the driver. The second group of functions allows the called process to enter sleep. At this time, the CPU can instead execute the tasks of other processes. The actual latency value of the second group of delay functions will be greater than the set delay time.


User space
# Include <unistd. h>
Unsigned int sleep (unsigned int seconds );
Int usleep (useconds_t USEC );

Latency in milliseconds can be achieved through macro definition:

# Define xxx_msleep (MS) usleep (MS) * 1000)

Related Article

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.