accel: Remove _WIN32 ifdef from qtest-cpus.c
[qemu.git] / accel / qtest / qtest-cpus.c
1 /*
2 * QTest accelerator code
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 *
12 */
13
14 #include "qemu/osdep.h"
15 #include "qemu/rcu.h"
16 #include "qapi/error.h"
17 #include "qemu/module.h"
18 #include "qemu/option.h"
19 #include "qemu/config-file.h"
20 #include "sysemu/accel.h"
21 #include "sysemu/qtest.h"
22 #include "sysemu/cpus.h"
23 #include "sysemu/cpu-timers.h"
24 #include "qemu/guest-random.h"
25 #include "qemu/main-loop.h"
26 #include "hw/core/cpu.h"
27
28 #include "qtest-cpus.h"
29
30 static void *qtest_cpu_thread_fn(void *arg)
31 {
32 CPUState *cpu = arg;
33 sigset_t waitset;
34 int r;
35
36 rcu_register_thread();
37
38 qemu_mutex_lock_iothread();
39 qemu_thread_get_self(cpu->thread);
40 cpu->thread_id = qemu_get_thread_id();
41 cpu->can_do_io = 1;
42 current_cpu = cpu;
43
44 sigemptyset(&waitset);
45 sigaddset(&waitset, SIG_IPI);
46
47 /* signal CPU creation */
48 cpu_thread_signal_created(cpu);
49 qemu_guest_random_seed_thread_part2(cpu->random_seed);
50
51 do {
52 qemu_mutex_unlock_iothread();
53 do {
54 int sig;
55 r = sigwait(&waitset, &sig);
56 } while (r == -1 && (errno == EAGAIN || errno == EINTR));
57 if (r == -1) {
58 perror("sigwait");
59 exit(1);
60 }
61 qemu_mutex_lock_iothread();
62 qemu_wait_io_event(cpu);
63 } while (!cpu->unplug);
64
65 qemu_mutex_unlock_iothread();
66 rcu_unregister_thread();
67 return NULL;
68 }
69
70 static void qtest_start_vcpu_thread(CPUState *cpu)
71 {
72 char thread_name[VCPU_THREAD_NAME_SIZE];
73
74 cpu->thread = g_malloc0(sizeof(QemuThread));
75 cpu->halt_cond = g_malloc0(sizeof(QemuCond));
76 qemu_cond_init(cpu->halt_cond);
77 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
78 cpu->cpu_index);
79 qemu_thread_create(cpu->thread, thread_name, qtest_cpu_thread_fn, cpu,
80 QEMU_THREAD_JOINABLE);
81 }
82
83 const CpusAccel qtest_cpus = {
84 .create_vcpu_thread = qtest_start_vcpu_thread,
85 .get_virtual_clock = qtest_get_virtual_clock,
86 };