27 ASSERT_TRUE(fifo->isLockFree());
36 for(
int i=0; i<9; i++){
37 inbuff[i] = (char) i+97;
42 EXPECT_EQ((
size_t) 0, fifo->read(outbuff, (
size_t) 10));
45 bool write_success = fifo->write(inbuff, (
size_t) 21);
46 bool read_success = fifo->read(outbuff, (
size_t) 21);
47 EXPECT_STREQ(inbuff, outbuff);
48 EXPECT_EQ(write_success, read_success);
51 EXPECT_EQ((
size_t) 0, fifo->read(outbuff, (
size_t) 21));
54 for(
int i = 0; i < 10; i++){
55 write_success = fifo->write(inbuff, (
size_t) 11);
56 read_success = fifo->read(outbuff, (
size_t) 11);
57 EXPECT_STREQ(inbuff, outbuff);
58 EXPECT_EQ(write_success, read_success);
67 char buff[8] =
"message";
70 EXPECT_EQ(fifo->write(buff, (
size_t) 8), (
size_t) 0);
73 void send(std::mutex &m, std::condition_variable &cv, std::atomic<bool> &ready,
AtomicFifo *fifo,
char *message,
size_t size)
75 std::unique_lock<std::mutex> lk(m);
76 fifo->
write(message, size);
81 void receive(std::mutex &m, std::condition_variable &cv, std::atomic<bool> &ready,
AtomicFifo *fifo,
char *output,
size_t size)
83 std::unique_lock<std::mutex> lk(m);
85 cv.wait(lk, [&]{
return ready.load();});
87 fifo->
read(output, size);
93 std::condition_variable cv;
94 std::atomic<bool> ready;
97 char message[8] =
"message";
101 std::thread sender(&
send, std::ref(m), std::ref(cv), std::ref(ready), fifo, message, size);
102 std::thread receiver(&
receive, std::ref(m), std::ref(cv), std::ref(ready), fifo, output, size);
105 EXPECT_STREQ(message, output);