From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932341AbbE1XLI (ORCPT ); Thu, 28 May 2015 19:11:08 -0400 Received: from mail-ig0-f179.google.com ([209.85.213.179]:35179 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755208AbbE1XKB (ORCPT ); Thu, 28 May 2015 19:10:01 -0400 From: Riley Andrews To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Riley Andrews , devel@driverdev.osuosl.org Subject: [PATCH 11/13] android: binder: add function to handle waiting for binder_thread_read Date: Thu, 28 May 2015 16:08:29 -0700 Message-Id: <1432854511-33320-12-git-send-email-riandrews@android.com> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1432854511-33320-1-git-send-email-riandrews@android.com> References: <1432854511-33320-1-git-send-email-riandrews@android.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add another helper function for binder_thread_read. All of the logic for waiting for work to do has been pulled into this function. Signed-off-by: Riley Andrews --- drivers/android/binder.c | 104 ++++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 38 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index b69ca0a..c98436c 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2528,6 +2528,71 @@ static int binder_work_tr_complete(struct binder_thread *thread, return 0; } +static int binder_wait_for_thread_work(struct binder_thread *thread, + bool non_block) +{ + if (binder_has_thread_work(thread)) + return 0; + + if (non_block) + return -EAGAIN; + + return wait_event_freezable(thread->wait, + binder_has_thread_work(thread)); +} + +static int binder_wait_for_proc_work(struct binder_thread *thread, + bool non_block) +{ + struct binder_proc *proc = thread->proc; + + if (!(thread->looper & (BINDER_LOOPER_STATE_REGISTERED | + BINDER_LOOPER_STATE_ENTERED))) { + binder_user_error("%d:%d ERROR: Thread waiting for process work before calling BC_REGISTER_LOOPER or BC_ENTER_LOOPER (state %x)\n", + proc->pid, thread->pid, + thread->looper); + wait_event_interruptible(binder_user_error_wait, + binder_stop_on_user_error < 2); + } + binder_set_nice(proc->default_priority); + + if (binder_has_proc_work(proc, thread)) + return 0; + + if (non_block) + return -EAGAIN; + + return wait_event_freezable_exclusive(proc->wait, + binder_has_proc_work(proc, thread)); +} + +static int binder_wait_for_work(struct binder_thread *thread, int non_block, + int wait_for_proc_work) +{ + int ret; + struct binder_proc *proc = thread->proc; + + trace_binder_wait_for_work(wait_for_proc_work, + !!thread->transaction_stack, + !list_empty(&thread->todo)); + thread->looper |= BINDER_LOOPER_STATE_WAITING; + if (wait_for_proc_work) + proc->ready_threads++; + + binder_unlock(__func__); + if (wait_for_proc_work) + ret = binder_wait_for_proc_work(thread, non_block); + else + ret = binder_wait_for_thread_work(thread, non_block); + binder_lock(__func__); + + if (wait_for_proc_work) + proc->ready_threads--; + thread->looper &= ~BINDER_LOOPER_STATE_WAITING; + + return ret; +} + static int binder_thread_read(struct binder_proc *proc, struct binder_thread *thread, binder_uintptr_t binder_buffer, size_t size, @@ -2568,44 +2633,7 @@ retry: goto done; } - - thread->looper |= BINDER_LOOPER_STATE_WAITING; - if (wait_for_proc_work) - proc->ready_threads++; - - binder_unlock(__func__); - - trace_binder_wait_for_work(wait_for_proc_work, - !!thread->transaction_stack, - !list_empty(&thread->todo)); - if (wait_for_proc_work) { - if (!(thread->looper & (BINDER_LOOPER_STATE_REGISTERED | - BINDER_LOOPER_STATE_ENTERED))) { - binder_user_error("%d:%d ERROR: Thread waiting for process work before calling BC_REGISTER_LOOPER or BC_ENTER_LOOPER (state %x)\n", - proc->pid, thread->pid, thread->looper); - wait_event_interruptible(binder_user_error_wait, - binder_stop_on_user_error < 2); - } - binder_set_nice(proc->default_priority); - if (non_block) { - if (!binder_has_proc_work(proc, thread)) - ret = -EAGAIN; - } else - ret = wait_event_freezable_exclusive(proc->wait, binder_has_proc_work(proc, thread)); - } else { - if (non_block) { - if (!binder_has_thread_work(thread)) - ret = -EAGAIN; - } else - ret = wait_event_freezable(thread->wait, binder_has_thread_work(thread)); - } - - binder_lock(__func__); - - if (wait_for_proc_work) - proc->ready_threads--; - thread->looper &= ~BINDER_LOOPER_STATE_WAITING; - + ret = binder_wait_for_work(thread, non_block, wait_for_proc_work); if (ret) return ret; -- 2.2.0.rc0.207.ga3a616c