标题: USB中这段代码会不会有原子操作问题? [打印本页] 作者: newbieforever 时间: 2011-11-15 15:32 标题: USB中这段代码会不会有原子操作问题? /*
* Process events in the schedule, but only in one thread at a time
*/
static void uhci_scan_schedule(struct uhci_hcd *uhci)
{
int i;
struct uhci_qh *qh;
/* Go through all the QH queues and process the URBs in each one */
for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) {
uhci->next_qh = list_entry(uhci->skelqh[i]->node.next,
struct uhci_qh, node);
while ((qh = uhci->next_qh) != uhci->skelqh[i]) {
uhci->next_qh = list_entry(qh->node.next,
struct uhci_qh, node);
if (uhci_advance_check(uhci, qh)) {
uhci_scan_qh(uhci, qh);
if (qh->state == QH_STATE_ACTIVE) {
uhci_urbp_wants_fsbr(uhci,
list_entry(qh->queue.next, struct urb_priv, node));
}
}
}
}
uhci->last_iso_frame = uhci->cur_iso_frame;
if (uhci->need_rescan)
goto rescan;
uhci->scan_in_progress = 0;
if (list_empty(&uhci->skel_unlink_qh->node))
uhci_clear_next_interrupt(uhci);
else
uhci_set_next_interrupt(uhci);
}
Process events in the schedule, but only in one thread at a time,这句话说这函数一次只能在一个线程中运行,是由下面这段代码实现的:
/* Don't allow re-entrant calls */
if (uhci->scan_in_progress) {
uhci->need_rescan = 1;
return;
}
uhci->scan_in_progress = 1;
unsigned int scan_in_progress:1; /* Schedule scan is running */ 在结构体里是这样定义的,问题是不需要考虑原子操作问题吗? 多个线程同时调用这个函数的时候如何保证 if (uhci->scan_in_progress) 是原子的?作者: newbieforever 时间: 2011-11-19 12:58
顶上去