Android Training Course (19)

Source: Internet
Author: User

In the init initialization process, how does one initialize the device? To understand this, you need to carefully analyze the following code:

#001 int device_init (void)

#002 {

#003 suseconds_t t0, t1;

#004 int fd;

#005

#006 fd = open_uevent_socket ();

#007 if (fd <0)

#008 return-1;

This Code calls the open_uevent_socket function to create a socket for the user's event space.

 

#009

#010 fcntl (fd, F_SETFD, FD_CLOEXEC );

#011 fcntl (fd, F_SETFL, O_NONBLOCK );

This Code sets the socket attribute. FD_CLOEXEC is used to set the close-on-exec Status standard of the file. When the close-on-exec flag is 0 after exec () is called, this file is not closed. If it is not zero, it is disabled after exec. The default close-on-exec Status is 0 and needs to be set through FD_CLOEXEC. O_NONBLOCK sets this socket as an asynchronous communication method.

 

#012

#013 t0 = get_usecs ();

This line of code is used to obtain the time of the current user.

 

#014 coldboot (fd, "/sys/class ");

#015 coldboot (fd, "/sys/block ");

#016 coldboot (fd, "/sys/devices ");

This code is used to traverse all the devices that have been created before the init process and find the device Event file to send event notifications.

 

#017 t1 = get_usecs ();

This line of code is used to obtain the time of the current user.

 

#018

#019 log_event_print ("coldboot % ld uS", (long) (t1-t0 )));

This line of code is used to print the number of seconds of the output cold start.

 

#020

#021 return fd;

#022}

#023

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.