[libcxx] r292011 - Fix Windows try_lock implementation

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 14 02:27:13 PST 2017


Author: ericwf
Date: Sat Jan 14 04:27:12 2017
New Revision: 292011

URL: http://llvm.org/viewvc/llvm-project?rev=292011&view=rev
Log:
Fix Windows try_lock implementation

Modified:
    libcxx/trunk/include/__threading_support
    libcxx/trunk/src/mutex.cpp
    libcxx/trunk/test/libcxx/test/config.py

Modified: libcxx/trunk/include/__threading_support
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=292011&r1=292010&r2=292011&view=diff
==============================================================================
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Sat Jan 14 04:27:12 2017
@@ -102,7 +102,7 @@ _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
-int __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
+bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
@@ -114,7 +114,7 @@ _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
-int __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
+bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
@@ -221,9 +221,9 @@ int __libcpp_recursive_mutex_lock(__libc
   return pthread_mutex_lock(__m);
 }
 
-int __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
+bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
 {
-  return pthread_mutex_trylock(__m);
+  return pthread_mutex_trylock(__m) == 0;
 }
 
 int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t *__m)
@@ -241,9 +241,9 @@ int __libcpp_mutex_lock(__libcpp_mutex_t
   return pthread_mutex_lock(__m);
 }
 
-int __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
+bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
 {
-  return pthread_mutex_trylock(__m);
+  return pthread_mutex_trylock(__m) == 0;
 }
 
 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
@@ -371,10 +371,9 @@ int __libcpp_recursive_mutex_lock(__libc
   return 0;
 }
 
-int __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
+bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
 {
-  TryEnterCriticalSection(__m);
-  return 0;
+  return TryEnterCriticalSection(__m) != 0;
 }
 
 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
@@ -395,10 +394,9 @@ int __libcpp_mutex_lock(__libcpp_mutex_t
   return 0;
 }
 
-int __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
+bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
 {
-  TryAcquireSRWLockExclusive(__m);
-  return 0;
+  return TryAcquireSRWLockExclusive(__m) != 0;
 }
 
 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)

Modified: libcxx/trunk/src/mutex.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/mutex.cpp?rev=292011&r1=292010&r2=292011&view=diff
==============================================================================
--- libcxx/trunk/src/mutex.cpp (original)
+++ libcxx/trunk/src/mutex.cpp Sat Jan 14 04:27:12 2017
@@ -37,7 +37,7 @@ mutex::lock()
 bool
 mutex::try_lock() _NOEXCEPT
 {
-    return __libcpp_mutex_trylock(&__m_) == 0;
+    return __libcpp_mutex_trylock(&__m_);
 }
 
 void
@@ -83,7 +83,7 @@ recursive_mutex::unlock() _NOEXCEPT
 bool
 recursive_mutex::try_lock() _NOEXCEPT
 {
-    return __libcpp_recursive_mutex_trylock(&__m_) == 0;
+    return __libcpp_recursive_mutex_trylock(&__m_);
 }
 
 // timed_mutex

Modified: libcxx/trunk/test/libcxx/test/config.py
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=292011&r1=292010&r2=292011&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/test/config.py (original)
+++ libcxx/trunk/test/libcxx/test/config.py Sat Jan 14 04:27:12 2017
@@ -382,6 +382,9 @@ class Configuration(object):
         if '__cpp_structured_bindings' not in macros:
             self.config.available_features.add('libcpp-no-structured-bindings')
 
+        if self.is_windows:
+            self.config.available_features.add('windows')
+
     def configure_compile_flags(self):
         no_default_flags = self.get_lit_bool('no_default_flags', False)
         if not no_default_flags:




More information about the cfe-commits mailing list