Skip to content

Commit f7ad229

Browse files
Update README.md
1 parent 66dfae7 commit f7ad229

File tree

1 file changed

+30
-110
lines changed

1 file changed

+30
-110
lines changed

README.md

Lines changed: 30 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -588,116 +588,36 @@ static int binder_thread_release(struct binder_proc *proc, struct binder_thread
588588

589589
These lines have been added to source code:
590590

591-
592-
<table>
593-
<tr>
594-
<td><code>static int binder_thread_release(struct binder_proc *proc,</code>
595-
<p>
596-
<code> struct<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread"> binder_thread</a> *thread)</code>
597-
<code>{</code>
598-
<p>
599-
<code> .</code>
600-
<p>
601-
<code> .</code>
602-
<p>
603-
<code> .</code>
604-
<p>
605-
<code> /* </code>
606-
<p>
607-
<code> * If this thread used poll, make sure we remove the waitqueue</code>
608-
</td>
609-
</tr>
610-
<tr>
611-
<td><code> * from any epoll data structures holding it with POLLFREE.</code>
612-
</td>
613-
</tr>
614-
<tr>
615-
<td><code> * waitqueue_active() is safe to use here because we're holding</code>
616-
</td>
617-
</tr>
618-
<tr>
619-
<td><code> * the inner lock.</code>
620-
</td>
621-
</tr>
622-
<tr>
623-
<td><code> */</code>
624-
</td>
625-
</tr>
626-
<tr>
627-
<td><code> if ((<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#1042thread">thread</a>-><a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread::looper">looper</a> &<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#BINDER_LOOPER_STATE_POLL"> BINDER_LOOPER_STATE_POLL</a>) &&</code>
628-
</td>
629-
</tr>
630-
<tr>
631-
<td><code> <a href="https://code.woboq.org/linux/linux/include/linux/wait.h.html#waitqueue_active"> waitqueue_active</a>(&<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#1042thread">thread</a>-><a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread::wait">wait</a>)) {</code>
632-
</td>
633-
</tr>
634-
<tr>
635-
<td><code><b> <a href="https://code.woboq.org/linux/linux/include/linux/wait.h.html#211">wake_up_poll</a>(&<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#1042thread">thread</a>-><a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread::wait">wait</a>,<a href="https://code.woboq.org/linux/linux/include/uapi/linux/eventpoll.h.html#35"> EPOLLHUP</a> |<a href="https://code.woboq.org/linux/linux/include/uapi/asm-generic/poll.h.html#32"> POLLFREE</a>);</b></code>
636-
</td>
637-
</tr>
638-
<tr>
639-
<td><code> }</code>
640-
</td>
641-
</tr>
642-
<tr>
643-
<td>
644-
</td>
645-
</tr>
646-
<tr>
647-
<td><code> <a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#706">binder_inner_proc_unlock</a>(<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#1042thread">thread</a>-><a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread::proc">proc</a>);</code>
648-
</td>
649-
</tr>
650-
<tr>
651-
<td>
652-
</td>
653-
</tr>
654-
<tr>
655-
<td><code> /*</code>
656-
</td>
657-
</tr>
658-
<tr>
659-
<td><code> * This is needed to avoid races between wake_up_poll() above and</code>
660-
</td>
661-
</tr>
662-
<tr>
663-
<td><code> * and ep_remove_waitqueue() called for other reasons (eg the epoll file</code>
664-
</td>
665-
</tr>
666-
<tr>
667-
<td><code> * descriptor being closed); ep_remove_waitqueue() holds an RCU read</code>
668-
</td>
669-
</tr>
670-
<tr>
671-
<td><code> * lock, so we can be sure it's done after calling synchronize_rcu().</code>
672-
</td>
673-
</tr>
674-
<tr>
675-
<td><code> */</code>
676-
</td>
677-
</tr>
678-
<tr>
679-
<td><code> if (<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#1042thread">thread</a>-><a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread::looper">looper</a> &<a href="https://code.woboq.org/linux/linux/drivers/android/binder.c.html#BINDER_LOOPER_STATE_POLL"> BINDER_LOOPER_STATE_POLL</a>)</code>
680-
</td>
681-
</tr>
682-
<tr>
683-
<td>
684-
<code> <a href="https://code.woboq.org/linux/linux/kernel/rcu/tree.c.html#synchronize_rcu">synchronize_rcu</a>();</code>
685-
686-
<code> .</code>
687-
<p>
688-
689-
<code> .</code>
690-
<p>
691-
692-
<code> .</code>
693-
<p>
694-
695-
<code>}</code>
696-
</td>
697-
</tr>
698-
</table>
699-
700-
591+
<pre>
592+
static int binder_thread_release(struct binder_proc *proc,
593+
binder_thread *thread)
594+
{
595+
.
596+
.
597+
.
598+
/*
599+
* If this thread used poll, make sure we remove the waitqueue
600+
* from any epoll data structures holding it with POLLFREE.
601+
* waitqueue_active() is safe to use here because we're holding
602+
* the inner lock.
603+
*/
604+
if ((thread->looper & BINDER_LOOPER_STATE_POLL) && waitqueue_active(&thread->wait)) {
605+
wake_up_poll(&thread->wait, EPOLLHUP | POLLFREE);
606+
}
607+
binder_inner_proc_unlock(thread->proc);
608+
/*
609+
* This is needed to avoid races between wake_up_poll() above and
610+
* and ep_remove_waitqueue() called for other reasons (eg the epoll file
611+
* descriptor being closed); ep_remove_waitqueue() holds an RCU read
612+
* lock, so we can be sure it's done after calling synchronize_rcu().
613+
*/
614+
if (thread->looper & BINDER_LOOPER_STATE_POLL)
615+
synchronize_rcu();
616+
.
617+
.
618+
.
619+
}
620+
701621
see full code [here](https://code.woboq.org/linux/linux/drivers/android/binder.c.html#binder_thread_release)
702622

703623

0 commit comments

Comments
 (0)