Revision 83f64091 vl.c

b/vl.c
4772 4772
}
4773 4773

  
4774 4774
/***********************************************************/
4775
/* bottom halves (can be seen as timers which expire ASAP) */
4776

  
4777
struct QEMUBH {
4778
    QEMUBHFunc *cb;
4779
    void *opaque;
4780
    int scheduled;
4781
    QEMUBH *next;
4782
};
4783

  
4784
static QEMUBH *first_bh = NULL;
4785

  
4786
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
4787
{
4788
    QEMUBH *bh;
4789
    bh = qemu_mallocz(sizeof(QEMUBH));
4790
    if (!bh)
4791
        return NULL;
4792
    bh->cb = cb;
4793
    bh->opaque = opaque;
4794
    return bh;
4795
}
4796

  
4797
void qemu_bh_poll(void)
4798
{
4799
    QEMUBH *bh, **pbh;
4800

  
4801
    for(;;) {
4802
        pbh = &first_bh;
4803
        bh = *pbh;
4804
        if (!bh)
4805
            break;
4806
        *pbh = bh->next;
4807
        bh->scheduled = 0;
4808
        bh->cb(bh->opaque);
4809
    }
4810
}
4811

  
4812
void qemu_bh_schedule(QEMUBH *bh)
4813
{
4814
    CPUState *env = cpu_single_env;
4815
    if (bh->scheduled)
4816
        return;
4817
    bh->scheduled = 1;
4818
    bh->next = first_bh;
4819
    first_bh = bh;
4820

  
4821
    /* stop the currently executing CPU to execute the BH ASAP */
4822
    if (env) {
4823
        cpu_interrupt(env, CPU_INTERRUPT_EXIT);
4824
    }
4825
}
4826

  
4827
void qemu_bh_cancel(QEMUBH *bh)
4828
{
4829
    QEMUBH **pbh;
4830
    if (bh->scheduled) {
4831
        pbh = &first_bh;
4832
        while (*pbh != bh)
4833
            pbh = &(*pbh)->next;
4834
        *pbh = bh->next;
4835
        bh->scheduled = 0;
4836
    }
4837
}
4838

  
4839
void qemu_bh_delete(QEMUBH *bh)
4840
{
4841
    qemu_bh_cancel(bh);
4842
    qemu_free(bh);
4843
}
4844

  
4845
/***********************************************************/
4775 4846
/* machine registration */
4776 4847

  
4777 4848
QEMUMachine *first_machine = NULL;
......
5030 5101
#ifdef _WIN32
5031 5102
    tap_win32_poll();
5032 5103
#endif
5104
    qemu_aio_poll();
5105
    qemu_bh_poll();
5033 5106

  
5034 5107
    if (vm_running) {
5035 5108
        qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], 
......
6049 6122
    
6050 6123
    init_timers();
6051 6124
    init_timer_alarm();
6125
    qemu_aio_init();
6052 6126

  
6053 6127
#ifdef _WIN32
6054 6128
    socket_init();
......
6093 6167
                snprintf(buf, sizeof(buf), "hd%c", i + 'a');
6094 6168
                bs_table[i] = bdrv_new(buf);
6095 6169
            }
6096
            if (bdrv_open(bs_table[i], hd_filename[i], snapshot) < 0) {
6170
            if (bdrv_open(bs_table[i], hd_filename[i], snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
6097 6171
                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
6098 6172
                        hd_filename[i]);
6099 6173
                exit(1);
......
6118 6192
                bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY);
6119 6193
            }
6120 6194
            if (fd_filename[i] != '\0') {
6121
                if (bdrv_open(fd_table[i], fd_filename[i], snapshot) < 0) {
6195
                if (bdrv_open(fd_table[i], fd_filename[i],
6196
                              snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
6122 6197
                    fprintf(stderr, "qemu: could not open floppy disk image '%s'\n",
6123 6198
                            fd_filename[i]);
6124 6199
                    exit(1);

Also available in: Unified diff