Skip to content

Commit

Permalink
Fix thread comparison by making sure we never pass our special 'not a…
Browse files Browse the repository at this point in the history
… thread' value to the underlying implementation. Fixes PR#42918.

llvm-svn: 368916
  • Loading branch information
mclow committed Aug 14, 2019
1 parent 376f642 commit 2e80d01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions libcxx/include/__threading_support
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,21 @@ public:

friend _LIBCPP_INLINE_VISIBILITY
bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT
{return __libcpp_thread_id_equal(__x.__id_, __y.__id_);}
{ // don't pass id==0 to underlying routines
if (__x.__id_ == 0) return __y.__id_ == 0;
if (__y.__id_ == 0) return false;
return __libcpp_thread_id_equal(__x.__id_, __y.__id_);
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT
{return !(__x == __y);}
friend _LIBCPP_INLINE_VISIBILITY
bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT
{return __libcpp_thread_id_less(__x.__id_, __y.__id_);}
{ // id==0 is always less than any other thread_id
if (__x.__id_ == 0) return __y.__id_ != 0;
if (__y.__id_ == 0) return false;
return __libcpp_thread_id_less(__x.__id_, __y.__id_);
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT
{return !(__y < __x);}
Expand All @@ -438,7 +446,7 @@ public:
{return !(__x < __y);}

_LIBCPP_INLINE_VISIBILITY
void reset() { __id_ = 0; }
void __reset() { __id_ = 0; }

template<class _CharT, class _Traits>
friend
Expand Down
2 changes: 1 addition & 1 deletion libcxx/src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ recursive_timed_mutex::unlock() _NOEXCEPT
unique_lock<mutex> lk(__m_);
if (--__count_ == 0)
{
__id_.reset();
__id_.__reset();
lk.unlock();
__cv_.notify_one();
}
Expand Down

0 comments on commit 2e80d01

Please sign in to comment.