binder_loop函数

来源:互联网 发布:笑郭网络验证通杀 编辑:程序博客网 时间:2024/06/03 05:27
  1. void binder_loop(struct binder_state *bs, binder_handler func)  
  2. {  
  3.     int res;  
  4.     struct binder_write_read bwr;  
  5.     unsigned readbuf[32];  
  6.   
  7.     bwr.write_size = 0;  
  8.     bwr.write_consumed = 0;  
  9.     bwr.write_buffer = 0;  
  10.       
  11.     readbuf[0] = BC_ENTER_LOOPER;  
  12. /*
  13. *下面这个函数只是设置了binder驱动中thread的loop状态为循环态BINDER_LOOPER_STATE_ENTERED
  14. */
  15.     binder_write(bs, readbuf, sizeof(unsigned));  
  16.   
  17.     for (;;) {  
  18.         bwr.read_size = sizeof(readbuf);  
  19.         bwr.read_consumed = 0;  
  20.         bwr.read_buffer = (unsigned) readbuf;  
  21. /*
  22. *下面这个函数让程序进入睡眠,等待唤醒
  23. */  
  24.         res = ioctl(bs->fd, BINDER_WRITE_READ, &bwr);  
  25.   
  26.         if (res < 0) {  
  27.             LOGE("binder_loop: ioctl failed (%s)\n", strerror(errno));  
  28.             break;  
  29.         }  
  30.   /*
  31. *等待下一步的分析
  32. */
  33.         res = binder_parse(bs, 0, readbuf, bwr.read_consumed, func);  
  34.         if (res == 0) {  
  35.             LOGE("binder_loop: unexpected reply?!\n");  
  36.             break;  
  37.         }  
  38.         if (res < 0) {  
  39.             LOGE("binder_loop: io error %d %s\n", res, strerror(errno));  
  40.             break;  
  41.         }  
  42.     }  
  43. }  
原创粉丝点击