std::try_lock problems
Jonathan Wakely
jwakely.gcc@gmail.com
Sat Dec 4 02:40:00 GMT 2010
This fixes the problems described on the libstdc++ list, tested
x86_64-linux and committed to trunk
-------------- next part --------------
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;
}
};
-------------- next part --------------
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.
More information about the Libstdc++
mailing list