@@ -68,22 +68,24 @@ struct result {
6868template <class Timepoint , class Locks , class ... Seqs>
6969int try_lock_until_impl (const Timepoint& end_time, Locks locks, type_pack<Seqs...>) {
7070 // an array with one function per lockable/sequence to try:
71- std::array<result (*)(const Timepoint&, Locks&), sizeof ...(Seqs)> seqs{{+[](const Timepoint& tp, Locks& lks) {
72- return []<class Tp , std::size_t I0, std::size_t ... Is>(
73- const Tp& itp, Locks& lcks, std::index_sequence<I0, Is...>) -> result {
74- if (std::unique_lock first{std::get<I0>(lcks), itp}) {
75- int res = friendly_try_lock (std::get<Is>(lcks)...);
76- if (res == -1 ) {
77- first.release ();
78- return {-1 , false }; // success
71+ constexpr std::array<result (*)(const Timepoint&, Locks&), sizeof ...(Seqs)> seqs{
72+ {+[](const Timepoint& tp, Locks& lks) {
73+ return []<class Tp , std::size_t I0, std::size_t ... Is>(
74+ const Tp& itp, Locks& lcks, std::index_sequence<I0, Is...>) -> result {
75+ if (std::unique_lock first{std::get<I0>(lcks), itp}) {
76+ int res = friendly_try_lock (std::get<Is>(lcks)...);
77+ if (res == -1 ) {
78+ first.release ();
79+ return {-1 , false }; // success
80+ }
81+ // return the index to try_lock_until next round
82+ constexpr std::array idxs{static_cast <int >(Is)...};
83+ return {idxs[static_cast <std::size_t >(res)], true };
7984 }
80- // return the index to try_lock_until next round
81- return {static_cast <int >(std::array{Is...}[static_cast <std::size_t >(res)]), true };
82- }
83- // timeout
84- return {static_cast <int >(I0), false };
85- }(tp, lks, Seqs{});
86- }...}};
85+ // timeout
86+ return {static_cast <int >(I0), false };
87+ }(tp, lks, Seqs{});
88+ }...}};
8789
8890 // try rotations in seqs while there is time to retry
8991 result ret{};
0 commit comments