diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-06-30 13:32:05 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-06-30 13:32:05 +0200 |
| commit | 65c456e595c099c7ea55c4ab2b04efcb75dfe857 (patch) | |
| tree | 955fb8efebf5f9ee91617e0a6d4409530478cb02 /pkg/csource/fuchsia_common.go | |
| parent | b1f623c85339555c67393824a08b1bc5a36af499 (diff) | |
pkg/csource: don't use pthread_cond_timedwait for fuchsia
We removed it in executor, do the same in csource.
Diffstat (limited to 'pkg/csource/fuchsia_common.go')
| -rw-r--r-- | pkg/csource/fuchsia_common.go | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/pkg/csource/fuchsia_common.go b/pkg/csource/fuchsia_common.go index 9d14c5e8d..8c780a19f 100644 --- a/pkg/csource/fuchsia_common.go +++ b/pkg/csource/fuchsia_common.go @@ -580,8 +580,6 @@ void loop() struct thread_t { int created, running, call; pthread_t th; - pthread_mutex_t mu; - pthread_cond_t cv; }; static struct thread_t threads[16]; @@ -595,23 +593,18 @@ static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { - pthread_mutex_lock(&th->mu); - while (!th->running) - pthread_cond_wait(&th->cv, &th->mu); - pthread_mutex_unlock(&th->mu); + while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) + usleep(200); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); - pthread_mutex_lock(&th->mu); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); - pthread_mutex_unlock(&th->mu); - pthread_cond_signal(&th->cv); } return 0; } static void execute(int num_calls) { - int call, thread; + int i, call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { @@ -622,30 +615,20 @@ static void execute(int num_calls) pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); - pthread_mutex_init(&th->mu, 0); - pthread_cond_init(&th->cv, 0); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); - - pthread_mutex_lock(&th->mu); - th->running = 1; - pthread_mutex_unlock(&th->mu); - pthread_cond_signal(&th->cv); + __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); #if defined(SYZ_COLLIDE) if (collide && call % 2) break; #endif - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = 20 * 1000 * 1000; - pthread_mutex_lock(&th->mu); - while (th->running && ts.tv_nsec >= 5 * 1000 * 1000) { - pthread_cond_timedwait(&th->cv, &th->mu, &ts); - ts.tv_nsec /= 2; + for (i = 0; i < 100; i++) { + if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) + break; + usleep(200); } - pthread_mutex_unlock(&th->mu); if (__atomic_load_n(&running, __ATOMIC_RELAXED)) usleep((call == num_calls - 1) ? 10000 : 1000); break; |
