mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
ReleaseSemaphore mayn't wake WaitForSingleObject up soon
This commit is contained in:
parent
4262f7bd34
commit
a6d88a1208
@ -8,6 +8,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#include "def.h"
|
||||
#include "export.h"
|
||||
|
||||
// pre-defined
|
||||
|
||||
@ -82,7 +83,7 @@ constexpr auto shared_lock(T&& lc) {
|
||||
|
||||
#endif/*__cplusplus < 201703L*/
|
||||
|
||||
std::size_t calc_unique_id();
|
||||
IPC_EXPORT std::size_t calc_unique_id();
|
||||
|
||||
template <typename F, typename D>
|
||||
constexpr decltype(auto) static_switch(std::size_t /*i*/, std::index_sequence<>, F&& /*f*/, D&& def) {
|
||||
|
||||
@ -2,11 +2,7 @@
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
|
||||
#include "rw_lock.h"
|
||||
#include "pool_alloc.h"
|
||||
@ -51,20 +47,26 @@ public:
|
||||
|
||||
void notify(handle_t h) {
|
||||
if (h == invalid()) return;
|
||||
{
|
||||
IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lock_);
|
||||
if (counter_ == 0) return;
|
||||
-- counter_;
|
||||
::ReleaseSemaphore(h, 1, NULL);
|
||||
}
|
||||
::Sleep(1);
|
||||
}
|
||||
|
||||
void broadcast(handle_t h) {
|
||||
if (h == invalid()) return;
|
||||
{
|
||||
IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lock_);
|
||||
if (counter_ == 0) return;
|
||||
long all_count = counter_;
|
||||
counter_ = 0;
|
||||
::ReleaseSemaphore(h, all_count, NULL);
|
||||
}
|
||||
::Sleep(1);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@ -368,7 +368,7 @@ void Unit::test_route_rtt() {
|
||||
for (std::size_t i = 0;; ++i) {
|
||||
auto dd = cc.recv();
|
||||
if (dd.size() < 2) return;
|
||||
// std::cout << "recving: " << i << "-[" << dd.size() << "]" << std::endl;
|
||||
//std::cout << "recv: " << i << "-[" << dd.size() << "]" << std::endl;
|
||||
while (!cr.send(ipc::buff_t('a'))) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
@ -383,8 +383,8 @@ void Unit::test_route_rtt() {
|
||||
}
|
||||
sw.start();
|
||||
for (std::size_t i = 0; i < LoopCount; ++i) {
|
||||
// std::cout << "sending: " << i << "-[" << datas__[i].size() << "]" << std::endl;
|
||||
cc.send(datas__[i]);
|
||||
//std::cout << "sent: " << i << "-[" << datas__[i].size() << "]" << std::endl;
|
||||
/*auto dd = */cr.recv();
|
||||
// if (dd.size() != 1 || dd[0] != 'a') {
|
||||
// QVERIFY(false);
|
||||
@ -434,14 +434,17 @@ void Unit::test_channel_rtt() {
|
||||
|
||||
std::thread t1 {[&] {
|
||||
ipc::channel cc { "my-ipc-channel" };
|
||||
bool recv_2 = false;
|
||||
for (std::size_t i = 0;; ++i) {
|
||||
auto dd = cc.recv();
|
||||
if (dd.size() < 2) return;
|
||||
//std::cout << "recving: " << i << "-[" << dd.size() << "]" << std::endl;
|
||||
while (!cc.send(ipc::buff_t('a'))) {
|
||||
cc.wait_for_recv(1);
|
||||
//if (i % 1000 == 0) {
|
||||
// std::cout << "recv: " << i << "-[" << dd.size() << "]" << std::endl;
|
||||
//}
|
||||
while (!recv_2) {
|
||||
recv_2 = cc.wait_for_recv(2);
|
||||
}
|
||||
//std::cout << "sent ack." << std::endl;
|
||||
cc.send(ipc::buff_t('a'));
|
||||
}
|
||||
}};
|
||||
|
||||
@ -450,7 +453,9 @@ void Unit::test_channel_rtt() {
|
||||
cc.wait_for_recv(1);
|
||||
sw.start();
|
||||
for (std::size_t i = 0; i < LoopCount; ++i) {
|
||||
//std::cout << "sending: " << i << "-[" << datas__[i].size() << "]" << std::endl;
|
||||
//if (i % 1000 == 0) {
|
||||
// std::cout << "send: " << i << "-[" << datas__[i].size() << "]" << std::endl;
|
||||
//}
|
||||
cc.send(datas__[i]);
|
||||
/*auto dd = */cc.recv();
|
||||
//if (dd.size() != 1 || dd.data<char>()[0] != 'a') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user