diff options
author | Yabin Cui <yabinc@google.com> | 2015-03-06 17:23:53 -0800 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2015-03-12 21:39:49 -0700 |
commit | 58cf31b50699ed9f523de38c8e943f3bbd1ced9e (patch) | |
tree | 258ba808074bd047a94df452a4e465db66136797 /libc/bionic/pthread_join.cpp | |
parent | e86a86f9f24df7028d2596c69ff008cf88e039e4 (diff) | |
download | android_bionic-58cf31b50699ed9f523de38c8e943f3bbd1ced9e.tar.gz android_bionic-58cf31b50699ed9f523de38c8e943f3bbd1ced9e.tar.bz2 android_bionic-58cf31b50699ed9f523de38c8e943f3bbd1ced9e.zip |
Make pthread join_state not protected by g_thread_list_lock.
1. Move the representation of thread join_state from pthread.attr.flag
to pthread.join_state. This clarifies thread state change.
2. Use atomic operations for pthread.join_state. So we don't need to
protect it by g_thread_list_lock. g_thread_list_lock will be reduced
to only protect g_thread_list or even removed in further changes.
Bug: 19636317
Change-Id: I31fb143a7c69508c7287307dd3b0776993ec0f43
Diffstat (limited to 'libc/bionic/pthread_join.cpp')
-rw-r--r-- | libc/bionic/pthread_join.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/libc/bionic/pthread_join.cpp b/libc/bionic/pthread_join.cpp index e3350efd3..15543b48e 100644 --- a/libc/bionic/pthread_join.cpp +++ b/libc/bionic/pthread_join.cpp @@ -44,16 +44,15 @@ int pthread_join(pthread_t t, void** return_value) { return ESRCH; } - if ((thread->attr.flags & PTHREAD_ATTR_FLAG_DETACHED) != 0) { - return EINVAL; + ThreadJoinState old_state = THREAD_NOT_JOINED; + while ((old_state == THREAD_NOT_JOINED || old_state == THREAD_EXITED_NOT_JOINED) && + !atomic_compare_exchange_weak(&thread->join_state, &old_state, THREAD_JOINED)) { } - if ((thread->attr.flags & PTHREAD_ATTR_FLAG_JOINED) != 0) { + if (old_state == THREAD_DETACHED || old_state == THREAD_JOINED) { return EINVAL; } - // Okay, looks like we can signal our intention to join. - thread->attr.flags |= PTHREAD_ATTR_FLAG_JOINED; tid = thread->tid; tid_ptr = &thread->tid; } |