[libcxx-commits] [libcxx] r368916 - Fix thread comparison by making sure we never pass our special 'not a thread' value to the underlying implementation. Fixes PR#42918.
Hans Wennborg via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 20 04:30:29 PDT 2019
Merged together with r368867 to release_90 in r369369.
On Wed, Aug 14, 2019 at 10:53 PM Marshall Clow via libcxx-commits
<libcxx-commits at lists.llvm.org> wrote:
>
> Author: marshall
> Date: Wed Aug 14 13:54:56 2019
> New Revision: 368916
>
> URL: http://llvm.org/viewvc/llvm-project?rev=368916&view=rev
> Log:
> Fix thread comparison by making sure we never pass our special 'not a thread' value to the underlying implementation. Fixes PR#42918.
>
> Modified:
> libcxx/trunk/include/__threading_support
> libcxx/trunk/src/mutex.cpp
>
> Modified: libcxx/trunk/include/__threading_support
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=368916&r1=368915&r2=368916&view=diff
> ==============================================================================
> --- libcxx/trunk/include/__threading_support (original)
> +++ libcxx/trunk/include/__threading_support Wed Aug 14 13:54:56 2019
> @@ -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);}
> @@ -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
>
> Modified: libcxx/trunk/src/mutex.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/mutex.cpp?rev=368916&r1=368915&r2=368916&view=diff
> ==============================================================================
> --- libcxx/trunk/src/mutex.cpp (original)
> +++ libcxx/trunk/src/mutex.cpp Wed Aug 14 13:54:56 2019
> @@ -181,7 +181,7 @@ recursive_timed_mutex::unlock() _NOEXCEP
> unique_lock<mutex> lk(__m_);
> if (--__count_ == 0)
> {
> - __id_.reset();
> + __id_.__reset();
> lk.unlock();
> __cv_.notify_one();
> }
>
>
> _______________________________________________
> libcxx-commits mailing list
> libcxx-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits
More information about the libcxx-commits
mailing list