diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2015-11-19 11:50:04 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2015-11-19 11:50:04 +0100 |
| commit | 93f8cc38aa01d8ebfbfed4f111e7a0a48dc89cac (patch) | |
| tree | 1f38f449421bc76b85a42556d5d5c2af39b91807 /executor/executor.cc | |
| parent | 6a76998e5e88331ce4f5ced88298a0a253be8c76 (diff) | |
executor: don't wait for pending calls if there are none
Diffstat (limited to 'executor/executor.cc')
| -rw-r--r-- | executor/executor.cc | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/executor/executor.cc b/executor/executor.cc index effe3c3af..c0cdf72f1 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -64,6 +64,7 @@ __attribute__((aligned(64 << 10))) char input_data[kMaxInput]; __attribute__((aligned(64 << 10))) char output_data[kMaxOutput]; uint32_t* output_pos; int completed; +int running; bool collide; struct res_t { @@ -302,12 +303,16 @@ retry: // Check if any of previous calls have completed. // Give them some additional time, because they could have been // just unblocked by the current call. - bool last = read_input(&input_pos, true) == instr_eof; - usleep(last ? 1000 : 100); - for (int i = 0; i < kMaxThreads; i++) { - th = &threads[i]; - if (__atomic_load_n(&th->done, __ATOMIC_ACQUIRE) && !th->handled) - handle_completion(th); + if (running < 0) + fail("running = %d", running); + if (running > 0) { + bool last = read_input(&input_pos, true) == instr_eof; + usleep(last ? 1000 : 100); + for (int i = 0; i < kMaxThreads; i++) { + th = &threads[i]; + if (__atomic_load_n(&th->done, __ATOMIC_ACQUIRE) && !th->handled) + handle_completion(th); + } } } else { @@ -365,6 +370,7 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, th->args[i] = args[i]; __atomic_store_n(&th->ready, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->ready, FUTEX_WAKE); + running++; return th; } @@ -400,6 +406,7 @@ void handle_completion(thread_t* th) __atomic_store_n((uint32_t*)&output_data[0], completed, __ATOMIC_RELEASE); } th->handled = true; + running--; } void thread_create(thread_t* th, int id, bool root) |
