add multi-wait (not ready, TBD)

This commit is contained in:
mutouyun 2019-01-27 15:32:58 +08:00
parent c667f1513f
commit fc1c058d10
3 changed files with 7 additions and 7 deletions

View File

@ -252,7 +252,7 @@ public:
} }
// calc a new wait-id & construct event object // calc a new wait-id & construct event object
event evt { ipc::detail::calc_unique_id() }; event evt { ipc::detail::calc_unique_id() };
auto ids = static_cast<std::size_t*>(mem::alloc(sizeof(std::size_t[size]))); auto ids = static_cast<std::size_t*>(mem::alloc(sizeof(std::size_t) * size));
for (std::size_t i = 0; i < size; ++i) { for (std::size_t i = 0; i < size; ++i) {
ids[i] = std::get<0>(all[i])->push_event(evt); ids[i] = std::get<0>(all[i])->push_event(evt);
} }
@ -260,7 +260,7 @@ public:
for (std::size_t i = 0; i < size; ++i) { for (std::size_t i = 0; i < size; ++i) {
std::get<0>(all[i])->pop_event(ids[i]); std::get<0>(all[i])->pop_event(ids[i]);
} }
mem::free(ids, sizeof(std::size_t[size])); mem::free(ids, sizeof(std::size_t) * size);
}); });
// wait for event signal // wait for event signal
return evt.wait(); return evt.wait();

View File

@ -41,8 +41,8 @@ public:
if (all == nullptr || size == 0) { if (all == nullptr || size == 0) {
return false; return false;
} }
auto hs = static_cast<handle_t*>(mem::alloc(sizeof(handle_t[size]))); auto hs = static_cast<handle_t*>(mem::alloc(sizeof(handle_t) * size));
IPC_UNUSED_ auto guard = unique_ptr(hs, [size](void* p) { mem::free(p, sizeof(handle_t[size])); }); IPC_UNUSED_ auto guard = unique_ptr(hs, [size](void* p) { mem::free(p, sizeof(handle_t) * size); });
std::size_t i = 0; std::size_t i = 0;
for (; i < size; ++i) { for (; i < size; ++i) {
auto& info = all[i]; auto& info = all[i];
@ -52,7 +52,7 @@ public:
hs[i] = std::get<1>(all[i]); hs[i] = std::get<1>(all[i]);
} }
std::atomic_thread_fence(std::memory_order_release); std::atomic_thread_fence(std::memory_order_release);
return ::WaitForMultipleObjects(hs, i, FALSE, INFINITE) != WAIT_FAILED; return ::WaitForMultipleObjects(static_cast<DWORD>(i), hs, FALSE, INFINITE) != WAIT_FAILED;
} }
bool wait(handle_t h) { bool wait(handle_t h) {

View File

@ -67,8 +67,8 @@ public:
return false; return false;
} }
using tp_t = decltype(std::declval<waiter_wrapper>().to_w_info()); using tp_t = decltype(std::declval<waiter_wrapper>().to_w_info());
auto hs = static_cast<tp_t*>(mem::alloc(sizeof(tp_t[size]))); auto hs = static_cast<tp_t*>(mem::alloc(sizeof(tp_t) * size));
IPC_UNUSED_ auto guard = unique_ptr(hs, [size](void* p) { mem::free(p, sizeof(tp_t[size])); }); IPC_UNUSED_ auto guard = unique_ptr(hs, [size](void* p) { mem::free(p, sizeof(tp_t) * size); });
std::size_t i = 0; std::size_t i = 0;
for (; i < size; ++i) { for (; i < size; ++i) {
auto& w = all[i]; auto& w = all[i];