免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2041 | 回复: 1
打印 上一主题 下一主题

USB中这段代码会不会有原子操作问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-15 15:32 |只看该作者 |倒序浏览
/*
* 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;

        /* Don't allow re-entrant calls */
        if (uhci->scan_in_progress) {
                uhci->need_rescan = 1;
                return;
        }
        uhci->scan_in_progress = 1;
rescan:
        uhci->need_rescan = 0;
        uhci->fsbr_is_wanted = 0;

        uhci_clear_next_interrupt(uhci);
        uhci_get_current_frame_number(uhci);
        uhci->cur_iso_frame = uhci->frame_number;

        /* 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 (uhci->fsbr_is_on && !uhci->fsbr_is_wanted &&
                        !uhci->fsbr_expiring) {
                uhci->fsbr_expiring = 1;
                mod_timer(&uhci->fsbr_timer, jiffies + FSBR_OFF_DELAY);
        }

        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) 是原子的?

论坛徽章:
0
2 [报告]
发表于 2011-11-19 12:58 |只看该作者
顶上去
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP