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)