Fixup futex emulation
std::unordered_multimap::find may return any matching element.. unlike equal_range. (code relied on matching the first) There was also UB there of reference to an element after it has deleted.
This commit is contained in:
+5
-5
@@ -81,9 +81,9 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t
|
|||||||
{
|
{
|
||||||
struct waiter
|
struct waiter
|
||||||
{
|
{
|
||||||
uint val;
|
uint val;
|
||||||
uint mask;
|
uint mask;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
@@ -111,7 +111,7 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t
|
|||||||
waiter rec;
|
waiter rec;
|
||||||
rec.val = val;
|
rec.val = val;
|
||||||
rec.mask = mask;
|
rec.mask = mask;
|
||||||
const auto& ref = *map.emplace(uaddr, &rec);
|
const auto itr = map.emplace(uaddr, &rec);
|
||||||
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t
|
|||||||
// TODO: absolute timeout
|
// TODO: absolute timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
map.erase(std::find(map.find(uaddr), map.end(), ref));
|
map.erase(itr);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2228,11 +2228,8 @@ void lv2_obj::notify_all() noexcept
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpu != &g_to_notify)
|
// Note: by the time of notification the thread could have been deallocated which is why the direct function is used
|
||||||
{
|
atomic_wait_engine::notify_all(cpu);
|
||||||
// Note: by the time of notification the thread could have been deallocated which is why the direct function is used
|
|
||||||
atomic_wait_engine::notify_all(cpu);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_to_notify[0] = nullptr;
|
g_to_notify[0] = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user