分类: LINUX
2008-08-03 16:52:46
二.代码详解 定义在:linux/kernel/rcupdate.c 606/** 607 * synchronize_rcu - wait until a grace period has elapsed. 608 * 609 * Control will return to the caller some time after a full grace 610 * period has elapsed, in other words after all currently executing RCU 611 * read-side critical sections have completed. RCU read-side critical 612 * sections are delimited by rcu_read_lock() and rcu_read_unlock(), 613 * and may be nested. 614 * 615 * If your read-side code is not protected by rcu_read_lock(), do -not- 616 * use synchronize_rcu(). 617 */ 618void synchronize_rcu(void) 619{ 620 struct rcu_synchronize rcu; 621 622 init_completion(&rcu.completion); 623 /* Will wake me after RCU finished */ 624 call_rcu(&rcu.head, wakeme_after_rcu); 625 626 /* Wait for it */ 627 wait_for_completion(&rcu.completion); 628} 其中 struct rcu_synchronize为: 592struct rcu_synchronize { 593 struct rcu_head head; 594 struct completion completion; 595}; rcu_head结构定义了 struct rcu_head *next; //指向rcu_head的指针 void (*func)(struct rcu_head *head); //回调函数 回调函数完成写执行单元最后的数据释放或修改操作。 completion结构的定义: 13struct completion { 14 unsigned int done; 15 wait_queue_head_t wait; 16}; unsigned int done; 指示等待的事件是否完成。初始化时为0。如果为0,则表示等待的事件未完成。大于0表示等待的事件已经完成。 wait_queue_head_t wait; 存放等待该事件完成的进程队列。 |
627> wait_for_completion(&rcu.completion); 作用:具体进程调用过程。 定义在:linux/kernel/sched.c 3731void fastcall __sched wait_for_completion(struct completion *x) 3732{ 3733 might_sleep(); 3734 3735 spin_lock_irq(&x->wait.lock); 3736 if (!x->done) { 3737 DECLARE_WAITQUEUE(wait, current); 3738 3739 wait.flags |= WQ_FLAG_EXCLUSIVE; 3740 __add_wait_queue_tail(&x->wait, &wait); 3741 do { 3742 __set_current_state(TASK_UNINTERRUPTIBLE); 3743 spin_unlock_irq(&x->wait.lock); 3744 schedule(); 3745 spin_lock_irq(&x->wait.lock); 3746 } while (!x->done); 3747 __remove_wait_queue(&x->wait, &wait); 3748 } 3749 x->done--; 3750 spin_unlock_irq(&x->wait.lock); 3751} |