exec.c: Use a QTAILQ to list CPUs.

This introduces CPUState, a mere typedef to CPUOldState for now,
and changes the way CPUs are listed in QEMU. The goal is to get
closer to upstream, while also allowing really separating CPUState
from CPUArmState in future patches.

+ Move "current_cpu" to a thread-local variable on Linux, just like
  upstream. Testing shows this doesn't affect performance.

Change-Id: Id07bbef4ba1584e607bec647d5117ac755c48ce6
diff --git a/cpus.c b/cpus.c
index 53ccd8a..38ecaf3 100644
--- a/cpus.c
+++ b/cpus.c
@@ -43,13 +43,13 @@
 void hw_error(const char *fmt, ...)
 {
     va_list ap;
-    CPUOldState *env;
+    CPUState *env;
 
     va_start(ap, fmt);
     fprintf(stderr, "qemu: hardware error: ");
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
-    for(env = first_cpu; env != NULL; env = env->next_cpu) {
+    CPU_FOREACH(env) {
         fprintf(stderr, "CPU #%d:\n", env->cpu_index);
 #ifdef TARGET_I386
         cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU);
@@ -80,26 +80,21 @@
     return 1;
 }
 
-static int internal_cpu_has_work(CPUOldState *env)
-{
-    if (env->stop)
-        return 1;
-    if (env->stopped)
-        return 0;
-    if (!env->halted)
-        return 1;
-    if (cpu_has_work(env))
-        return 1;
-    return 0;
-}
-
 int tcg_has_work(void)
 {
     CPUOldState *env;
 
-    for (env = first_cpu; env != NULL; env = env->next_cpu)
-        if (internal_cpu_has_work(env))
+    CPU_FOREACH(env) {
+        if (env->stop)
             return 1;
+        if (env->stopped)
+            return 0;
+        if (!env->halted)
+            return 1;
+        if (cpu_has_work(env))
+            return 1;
+        return 0;
+    }
     return 0;
 }
 
@@ -227,8 +222,8 @@
     int ret = 0;
 
     if (next_cpu == NULL)
-        next_cpu = first_cpu;
-    for (; next_cpu != NULL; next_cpu = next_cpu->next_cpu) {
+        next_cpu = QTAILQ_FIRST(&cpus);
+    for (; next_cpu != NULL; next_cpu = QTAILQ_NEXT(next_cpu, node)) {
         CPUOldState *env = cur_cpu = next_cpu;
 
         if (!vm_running)