天天看点

linux 异步通知

在linux应用层没有中断概念,信号是进程间通信的一种。IO设备由于其访问速度问题,需要CPU等待,这样会消耗CPU时间。当需要把IO设备中断传递给应用程序,使用“异步通知I/O”。

一、发送信号(释放信号)

void kill_fasync(struct fasync_struct **fp, int sig, int band)

{

      /* First a quick test without locking: usually

       * the list is empty.

       */

      if (*fp) {

             rcu_read_lock();

             kill_fasync_rcu(rcu_dereference(*fp), sig, band);

             rcu_read_unlock();

      }

}

这里采用RCU(read-copy update)同步机制.读(更新)fasync_struct;

信号发送时通过send_sigio(fown, fa->fa_fd, band);将信号发送。

二、异步处理

int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fapp)

      ****

rcu_assign_pointer(*fapp, new);写fasync_struct

继续阅读