全部博文(51)
分类: LINUX
2015-09-01 13:50:55
static void __pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p) { struct poll_wqueues *pwq = container_of(p, struct poll_wqueues, pt); //poll_wqueues 管理结构 struct poll_table_entry *entry = poll_get_entry(pwq); //在管理结构上申请一个表项 if (!entry) return; get_file(filp); entry->filp = filp; entry->wait_address = wait_address; //等待队列 entry->key = p->_key; init_waitqueue_func_entry(&entry->wait, pollwake); //唤醒后执行函数pollwake entry->wait.private = pwq; //私有数据指向管理结构 add_wait_queue(wait_address, &entry->wait); //添加entry->wait到wait_address等待队列 } |
signal(SIGIO, &input_handler); /* dummy sample; sigaction() is better */ fcntl(STDIN_FILENO, F_SETOWN, getpid()); oflags = fcntl(STDIN_FILENO, F_GETFL); fcntl(STDIN_FILENO, F_SETFL, oflags | FASYNC); |
struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); ...... int (*fasync) (int, struct file *, int); ...... } |
struct fasync_struct { spinlock_t fa_lock; int magic; int fa_fd; struct fasync_struct *fa_next; /* singly linked list */ struct file *fa_file; struct rcu_head fa_rcu; }; |
/* * fasync_helper() is used by almost all character device drivers * to set up the fasync queue, and for regular files by the file * lease code. It returns negative on error, 0 if it did no changes * and positive if it added/deleted the entry. */ int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fapp) { if (!on) //on为0时,表示删除异步对象 return fasync_remove_entry(filp, fapp); return fasync_add_entry(fd, filp, fapp); //on为1时,表示添加异步对象 } |