mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
revert some changes
This commit is contained in:
parent
68590dd2f3
commit
be6f16f87f
@ -34,7 +34,6 @@ struct waiter_helper {
|
||||
counter.waiting_.fetch_add(1, std::memory_order_release);
|
||||
flags.is_waiting_.store(true, std::memory_order_relaxed);
|
||||
auto finally = ipc::guard([&ctrl, &counter, &flags] {
|
||||
ctrl.get_lock(); // barrier
|
||||
for (auto curr_wait = counter.waiting_.load(std::memory_order_relaxed); curr_wait > 0;) {
|
||||
if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_acq_rel)) {
|
||||
break;
|
||||
|
||||
@ -18,8 +18,9 @@ using namespace ipc;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int LoopCount = 10000;
|
||||
constexpr int MultiMax = 8;
|
||||
constexpr int LoopCount = 10000;
|
||||
constexpr int MultiMax = 8;
|
||||
constexpr int TestBuffMax = 65536;
|
||||
|
||||
struct msg_head {
|
||||
int id_;
|
||||
@ -28,7 +29,7 @@ struct msg_head {
|
||||
class rand_buf : public buffer {
|
||||
public:
|
||||
rand_buf() {
|
||||
int size = capo::random<>{sizeof(msg_head), 65536}();
|
||||
int size = capo::random<>{sizeof(msg_head), TestBuffMax}();
|
||||
*this = buffer(new char[size], size, [](void * p, std::size_t) {
|
||||
delete [] static_cast<char *>(p);
|
||||
});
|
||||
@ -98,6 +99,22 @@ public:
|
||||
}
|
||||
} const data_set__;
|
||||
|
||||
#define IPC_ASSERT_TRUE(condition) \
|
||||
do { \
|
||||
bool check = !!(condition); \
|
||||
GTEST_TEST_BOOLEAN_(check, #condition, false, true, \
|
||||
GTEST_NONFATAL_FAILURE_); \
|
||||
if (!check) return; \
|
||||
} while (0)
|
||||
|
||||
#define IPC_ASSERT_FALSE(condition) \
|
||||
do { \
|
||||
bool check = !!(condition); \
|
||||
GTEST_TEST_BOOLEAN_(!check, #condition, true, false, \
|
||||
GTEST_NONFATAL_FAILURE_); \
|
||||
if (check) return; \
|
||||
} while (0)
|
||||
|
||||
template <relat Rp, relat Rc, trans Ts, typename Que = chan<Rp, Rc, Ts>>
|
||||
void test_sr(char const * name, int s_cnt, int r_cnt) {
|
||||
ipc_ut::sender().start(static_cast<std::size_t>(s_cnt));
|
||||
@ -109,10 +126,10 @@ void test_sr(char const * name, int s_cnt, int r_cnt) {
|
||||
for (int k = 0; k < s_cnt; ++k) {
|
||||
ipc_ut::sender() << [name, &sw, r_cnt, k] {
|
||||
Que que { name, ipc::sender };
|
||||
ASSERT_TRUE(que.wait_for_recv(r_cnt));
|
||||
IPC_ASSERT_TRUE(que.wait_for_recv(r_cnt));
|
||||
sw.start();
|
||||
for (int i = 0; i < (int)data_set__.get().size(); ++i) {
|
||||
ASSERT_TRUE(que.send(data_set__.get()[i]));
|
||||
IPC_ASSERT_TRUE(que.send(data_set__.get()[i]));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -122,17 +139,17 @@ void test_sr(char const * name, int s_cnt, int r_cnt) {
|
||||
Que que { name, ipc::receiver };
|
||||
for (;;) {
|
||||
rand_buf got { que.recv() };
|
||||
ASSERT_FALSE(got.empty());
|
||||
IPC_ASSERT_FALSE(got.empty());
|
||||
int i = got.get_id();
|
||||
if (i == -1) {
|
||||
return;
|
||||
}
|
||||
ASSERT_TRUE((i >= 0) && (i < (int)data_set__.get().size()));
|
||||
IPC_ASSERT_TRUE((i >= 0) && (i < (int)data_set__.get().size()));
|
||||
auto const &data_set = data_set__.get()[i];
|
||||
if (data_set != got) {
|
||||
printf("data_set__.get()[%d] != got, size = %zd/%zd\n",
|
||||
i, data_set.size(), got.size());
|
||||
ASSERT_TRUE(false);
|
||||
IPC_ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -140,7 +157,7 @@ void test_sr(char const * name, int s_cnt, int r_cnt) {
|
||||
|
||||
ipc_ut::sender().wait_for_done();
|
||||
Que que { name };
|
||||
ASSERT_TRUE(que.wait_for_recv(r_cnt));
|
||||
IPC_ASSERT_TRUE(que.wait_for_recv(r_cnt));
|
||||
for (int k = 0; k < r_cnt; ++k) {
|
||||
que.send(rand_buf{msg_head{-1}});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user