Patchwork std::try_lock problems

login
register
mail settings
Submitter Jonathan Wakely
Date Dec. 4, 2010, 2:40 a.m.
Message ID <AANLkTi=_th+Ga0_WorcF9fAuHMctKQsxNEkML00HiN_t@mail.gmail.com>
Download mbox | patch
Permalink /patch/74234/
State New
Headers show

Comments

Jonathan Wakely - Dec. 4, 2010, 2:40 a.m.
This fixes the problems described on the libstdc++ list, tested
x86_64-linux and committed to trunk

2010-12-04  Jonathan Wakely  <jwakely.gcc@gmail.com>

	* include/std/mutex (try_lock, __try_lock_impl): Fix.
	(lock): Implement using __try_lock_impl.
	* testsuite/30_threads/try_lock/2.cc: Fix logic.
	* testsuite/30_threads/try_lock/4.cc: New.
	* testsuite/30_threads/lock/1.cc: New.
	* testsuite/30_threads/lock/2.cc: New.
	* testsuite/30_threads/lock/3.cc: New.
	* testsuite/30_threads/lock/4.cc: New.
Jonathan Wakely - Dec. 6, 2010, 12:32 p.m.
On 4 December 2010 02:40, Jonathan Wakely wrote:
> This fixes the problems described on the libstdc++ list, tested
> x86_64-linux and committed to trunk
>

I've just noticed I attached the wrong file to that email. I included
an earlier version of the patch, not the one I checked in, the right
diffs are visible at
http://gcc.gnu.org/viewcvs?view=revision&revision=167452

Sorry,

Jonathan

Patch

Index: include/std/mutex
===================================================================
--- include/std/mutex	(revision 167396)
+++ include/std/mutex	(working copy)
@@ -663,16 +663,19 @@  _GLIBCXX_BEGIN_NAMESPACE(std)
 	static int
 	__do_try_lock(tuple<_Lock&...>& __locks)
 	{
-	  if(std::get<_Idx>(__locks).try_lock())
-	    {
-	      return __try_lock_impl<_Idx + 1,
-		_Idx + 2 < sizeof...(_Lock)>::__do_try_lock(__locks);
-	    }
-	  else
-	    {
-	      __unlock_impl<_Idx>::__do_unlock(__locks);
-	      return _Idx;
-	    }
+          __try
+            {
+              if(std::get<_Idx>(__locks).try_lock())
+                {
+                  return __try_lock_impl<_Idx + 1,
+                    _Idx + 2 < sizeof...(_Lock)>::__do_try_lock(__locks);
+                }
+            }
+          __catch(...)
+            {
+            }
+          __unlock_impl<_Idx - 1>::__do_unlock(__locks);
+          return _Idx;
 	}
     };
 
@@ -683,13 +686,16 @@  _GLIBCXX_BEGIN_NAMESPACE(std)
 	static int
 	__do_try_lock(tuple<_Lock&...>& __locks)
 	{
-	  if(std::get<_Idx>(__locks).try_lock())
-	    return -1;
-	  else
+          __try
+            {
+	      if(std::get<_Idx>(__locks).try_lock())
+	        return -1;
+	    }
+          __catch(...)
 	    {
-	      __unlock_impl<_Idx>::__do_unlock(__locks);
-	      return _Idx;
 	    }
+	  __unlock_impl<_Idx - 1>::__do_unlock(__locks);
+	  return _Idx;
 	}
     };