Permalink
Browse files

Do proper locking on tb for threads.

  • Loading branch information...
1 parent e0d6035 commit 1879719cea4712c3ea233421fcaf2ddbabcf0795 @staceyson committed Apr 4, 2013
@@ -126,7 +126,7 @@ static int pending_cpus;
/* Make sure everything is in a consistent state for calling fork(). */
void fork_start(void)
{
- pthread_mutex_lock(&tb_lock);
+ spin_lock(&tb_lock);
pthread_mutex_lock(&exclusive_lock);
mmap_fork_start();
}
@@ -146,11 +146,11 @@ void fork_end(int child)
pthread_mutex_init(&cpu_list_mutex, NULL);
pthread_cond_init(&exclusive_cond, NULL);
pthread_cond_init(&exclusive_resume, NULL);
- pthread_mutex_init(&tb_lock, NULL);
+ spin_lock_init(&tb_lock);
gdbserver_fork(thread_env);
} else {
pthread_mutex_unlock(&exclusive_lock);
- pthread_mutex_unlock(&tb_lock);
+ spin_unlock(&tb_lock);
}
}
@@ -1012,10 +1012,7 @@ void cpu_loop(CPUMIPSState *env)
for(;;) {
cpu_exec_start(env);
- /* XXX there is a concurrency problem - giant lock for now */
- pthread_mutex_lock(&exclusive_lock); /* XXX */
trapnr = cpu_mips_exec(env);
- pthread_mutex_unlock(&exclusive_lock); /* XXX */
cpu_exec_end(env);
switch(trapnr) {
case EXCP_SYSCALL: /* syscall exception */
@@ -31,8 +31,8 @@
//#define DEBUG_MMAP
#if defined(CONFIG_USE_NPTL)
-pthread_mutex_t mmap_mutex;
-static int __thread mmap_lock_count;
+pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __thread int mmap_lock_count;
void mmap_lock(void)
{
@@ -2591,6 +2591,8 @@ new_thread_start(void *arg)
env = info->env;
thread_env = env;
+ fork_end(1);
+
ts = (TaskState *)thread_env->opaque;
(void)thr_self(&tid);
info->tid = tid;
@@ -2697,6 +2699,7 @@ do_thr_new(CPUArchState *env, abi_ulong target_param_addr, int32_t param_size)
}
/* Create a new CPU instance. */
+ fork_start();
ts = g_malloc0(sizeof(TaskState));
init_task_state(ts);
new_env = cpu_copy(env);
@@ -2743,6 +2746,8 @@ do_thr_new(CPUArchState *env, abi_ulong target_param_addr, int32_t param_size)
ret = pthread_create(&info.thread, &attr, new_thread_start, &info);
/* XXX Free new CPU state if thread creation fails. */
+ fork_end(0);
+
sigprocmask(SIG_SETMASK, &info.sigmask, NULL);
pthread_attr_destroy(&attr);
if (0 == ret) {
@@ -2809,6 +2814,9 @@ do_thr_exit(CPUArchState *cpu_env, abi_ulong tid_addr)
g_free(ts);
pthread_exit(NULL);
}
+
+ gdb_exit(cpu_env, 0); /* XXX need to put in the correct exit status here? */
+ _exit(0);
}
static int
@@ -4859,8 +4867,9 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
case TARGET_FREEBSD_NR_fstat:
{
struct stat st;
+
ret = get_errno(fstat(arg1, &st));
- if (! ret)
+ if (!is_error(ret))
ret = host_to_target_stat(arg2, &st);
}
break;
@@ -4869,10 +4878,12 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
{
struct timespec req, rem;
- target_to_host_timespec(&req, arg1);
- ret = get_errno(nanosleep(&req, &rem));
- if (is_error(ret) && arg2)
- host_to_target_timespec(arg2, &rem);
+ ret = target_to_host_timespec(&req, arg1);
+ if (!is_error(ret)) {
+ ret = get_errno(nanosleep(&req, &rem));
+ if (!is_error(ret) && arg2)
+ host_to_target_timespec(arg2, &rem);
+ }
}
break;
@@ -24,6 +24,7 @@
#include <pthread.h>
#define spin_lock pthread_mutex_lock
#define spin_unlock pthread_mutex_unlock
+#define spin_lock_init(mtx) pthread_mutex_init(mtx, NULL)
#define spinlock_t pthread_mutex_t
#define SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER

0 comments on commit 1879719

Please sign in to comment.