[libcxx] Fix thread join.pass.cpp segfault after r271475

Some pthread implementations do not like being called pthead_join()
with the pthread_t argument set to 0, and causes a segfault. This
patch fixes this issue by validating the pthread_t argument before
invoking pthread_join().

NFC.

Differential revision: http://reviews.llvm.org/D20929

Change-Id: Ief817c57bd0e1f43cbaa03061e02417d6a180c38
Reviewers: EricWF
llvm-svn: 271634
This commit is contained in:
Asiri Rathnayake 2016-06-03 08:45:26 +00:00
parent e85506b6e0
commit 1f077f6b2b
1 changed files with 7 additions and 4 deletions

View File

@ -46,14 +46,17 @@ thread::~thread()
void
thread::join()
{
int ec = __libcpp_thread_join(&__t_);
int ec = EINVAL;
if (__t_ != 0)
{
ec = __libcpp_thread_join(&__t_);
if (ec == 0)
__t_ = 0;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
if (ec)
throw system_error(error_code(ec, system_category()), "thread::join failed");
#else
(void)ec;
#endif // _LIBCPP_NO_EXCEPTIONS
__t_ = 0;
}
void