Android培訓班(18)

來源:互聯網
上載者:User

通上面的函數就可以把服務和事件觸發的命令添加隊列裡。其實是在檔案parser.c頭部,就聲明了下面三個鏈表,如下:

 

static list_declare(service_list);

static list_declare(action_list);

static list_declare(action_queue);

 

service_list是定義添加分析所有資源檔裡的服務,action_list是定義添加分析所有資源檔裡的事件觸發的命令列表,action_queue是定義添加當前需要執行操作的命令動作或者服務等。

那麼又有下面一個問題了,init進程是在那裡添加這些服務或命令到運行隊列呢?在init.c檔案看到下面的代碼:

    action_for_each_trigger("early-init", action_add_queue_tail);

    drain_action_queue();

 

原來是通過函數action_for_each_trigger來把所有需要按事件觸發啟動並執行命令添加到隊列裡,函數action_add_queue_tail把需要執行命令放到隊列,函數drain_action_queue把添加到隊列裡的命令進行運行。

 

#001  void action_for_each_trigger(const char *trigger,

#002                               void (*func)(struct action *act))

#003  {

#004      struct listnode *node;

#005      struct action *act;

#006      list_for_each(node, &action_list) {

這行代碼是遍曆鏈表所有項。

 

#007          act = node_to_item(node, struct action, alist);

這行代碼是把動作節點轉換為動作項。

 

#008          if (!strcmp(act->name, trigger)) {

#009              func(act);

這段代碼是當找到與使用者輸入相同事件觸發的動作,比如上面是尋找“early-init”事件。這時就把動作項添加到將要啟動並執行隊列裡。

 

#010          }

#011      }

#012  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.