do proper cpu_self check

Currently, our check for qemu_cpu_self only checks if there is a cpu
currently in execution (represented by cpu_single_env being set). While
this might be okay for tcg, it is certainly not okay for kvm, since multiple
cpus might be executing.

Instead, I propose we use pthread primitives to test if the caller thread is
the same as env->thread.

For tcg, it will have the same semantics as before, since all CPUStates will
point to the same thread, and we'll only have one in execution at a time.

Signed-off-by: Glauber Costa <glommer@mothafucka.localdomain>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
