#include <cassert>
#include <cinttypes>
#include <cstring>
#include <memory>
#include <thread>
#include <pthread.h>
private:
return rb;
}
return rb;
}
std::vector<TrivialType> array(capacity);
}
return array;
}
}
(void)msg;
}
std::vector<TrivialType> array(len);
REQUIRE_MSG(
"get-range of "+
std::to_string(array.size())+
" elem in "+rb->toString(), len==rb->getBlocking( &(*array.begin()), len, len, 0_s) );
}
(void)msg;
}
REQUIRE( true == rb->putBlocking( vI, 0_s ) );
}
(void)msg;
}
std::vector<TrivialType> data = createIntArray(len, startValue);
REQUIRE_MSG(
"put-range of "+
std::to_string(data.size())+
" elem in "+rb->toString(), rb->put( &(*data.begin()), &(*data.end()) ) );
(void)msg;
}
public:
fprintf(stderr, "test01a_Read1Write1: %s\n", rb.get_info().c_str());
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
std::thread getThread01(&TestRingbuffer11::getThreadType01, this, "test01a.get01", &rb, capacity);
std::thread putThread01(&TestRingbuffer11::putThreadType01, this, "test01a.put01", &rb, capacity, 0);
putThread01.join();
getThread01.join();
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
}
INFO_STR(
"\n\ntest01b_Read1Write1_Range\n");
fprintf(stderr, "test01b_Read1Write1_Range: %s\n", rb.get_info().c_str());
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
std::thread getThread01(&TestRingbuffer11::getRangeThreadType02, this, "test01b.getR01", &rb, capacity);
std::thread putThread01(&TestRingbuffer11::putRangeThreadType02, this, "test01b.putR01", &rb, capacity, 0);
putThread01.join();
getThread01.join();
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
}
rb.setMultiPCEnabled(true);
fprintf(stderr, "test02a_Read4Write1: %s\n", rb.get_info().c_str());
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
std::thread getThread01(&TestRingbuffer11::getThreadType01, this, "test02a.get01", &rb, capacity/4);
std::thread getThread02(&TestRingbuffer11::getThreadType01, this, "test02a.get02", &rb, capacity/4);
std::thread putThread01(&TestRingbuffer11::putThreadType01, this, "test02a.put01", &rb, capacity, 0);
std::thread getThread03(&TestRingbuffer11::getThreadType01, this, "test02a.get03", &rb, capacity/4);
std::thread getThread04(&TestRingbuffer11::getThreadType01, this, "test02a.get04", &rb, capacity/4);
putThread01.join();
getThread01.join();
getThread02.join();
getThread03.join();
getThread04.join();
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
}
INFO_STR(
"\n\ntest02b_Read4Write1_Range\n");
rb.setMultiPCEnabled(true);
fprintf(stderr, "test02b_Read4Write1_Range: %s\n", rb.get_info().c_str());
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
std::thread getThread01(&TestRingbuffer11::getRangeThreadType02, this, "test02b.getR01", &rb, capacity/4);
std::thread getThread02(&TestRingbuffer11::getRangeThreadType02, this, "test02b.getR02", &rb, capacity/4);
std::thread putThread01(&TestRingbuffer11::putRangeThreadType02, this, "test02b.putR01", &rb, capacity, 0);
std::thread getThread03(&TestRingbuffer11::getRangeThreadType02, this, "test02b.getR03", &rb, capacity/4);
std::thread getThread04(&TestRingbuffer11::getRangeThreadType02, this, "test02b.getR04", &rb, capacity/4);
putThread01.join();
getThread01.join();
getThread02.join();
getThread03.join();
getThread04.join();
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
}
rb.setMultiPCEnabled(true);
fprintf(stderr, "test03a_Read8Write2: %s\n", rb.get_info().c_str());
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
std::thread getThread01(&TestRingbuffer11::getThreadType01, this, "test03a.get01", &rb, capacity/8);
std::thread getThread02(&TestRingbuffer11::getThreadType01, this, "test03a.get02", &rb, capacity/8);
std::thread putThread01(&TestRingbuffer11::putThreadType01, this, "test03a.put01", &rb, capacity/2, 0);
std::thread getThread03(&TestRingbuffer11::getThreadType01, this, "test03a.get03", &rb, capacity/8);
std::thread getThread04(&TestRingbuffer11::getThreadType01, this, "test03a.get04", &rb, capacity/8);
std::thread getThread05(&TestRingbuffer11::getThreadType01, this, "test03a.get05", &rb, capacity/8);
std::thread getThread06(&TestRingbuffer11::getThreadType01, this, "test03a.get06", &rb, capacity/8);
std::thread putThread02(&TestRingbuffer11::putThreadType01, this, "test03a.put02", &rb, capacity/2, 400);
std::thread getThread07(&TestRingbuffer11::getThreadType01, this, "test03a.get07", &rb, capacity/8);
std::thread getThread08(&TestRingbuffer11::getThreadType01, this, "test03a.get08", &rb, capacity/8);
putThread01.join();
putThread02.join();
getThread01.join();
getThread02.join();
getThread03.join();
getThread04.join();
getThread05.join();
getThread06.join();
getThread07.join();
getThread08.join();
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
}
INFO_STR(
"\n\ntest03b_Read8Write2_Range\n");
rb.setMultiPCEnabled(true);
fprintf(stderr, "test03b_Read8Write2_Range: %s\n", rb.get_info().c_str());
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
std::thread getThread01(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR01", &rb, capacity/8);
std::thread getThread02(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR02", &rb, capacity/8);
std::thread putThread01(&TestRingbuffer11::putRangeThreadType02, this, "test03b.putR01", &rb, capacity/2, 0);
std::thread getThread03(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR03", &rb, capacity/8);
std::thread getThread04(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR04", &rb, capacity/8);
std::thread getThread05(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR05", &rb, capacity/8);
std::thread getThread06(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR06", &rb, capacity/8);
std::thread putThread02(&TestRingbuffer11::putRangeThreadType02, this, "test03b.putR02", &rb, capacity/2, 400);
std::thread getThread07(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR07", &rb, capacity/8);
std::thread getThread08(&TestRingbuffer11::getRangeThreadType02, this, "test03b.getR08", &rb, capacity/8);
putThread01.join();
putThread02.join();
getThread01.join();
getThread02.join();
getThread03.join();
getThread04.join();
getThread05.join();
getThread06.join();
getThread07.join();
getThread08.join();
REQUIRE_MSG(
"empty size "+rb.toString(), 0 == rb.size());
}
}
}
};
#define REQUIRE_MSG(MSG,...)
void test01b_Read1Write1_Range()
void test02a_Read4Write1()
void test03b_Read8Write2_Range()
void test01a_Read1Write1()
void test02b_Read4Write1_Range()
void test03a_Read8Write2()
Ring buffer implementation, a.k.a circular buffer, exposing lock-free get*(..) and put*(....
std::string to_string(const alphabet &v) noexcept
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
constexpr const jau::fraction_i64 zero(0l, 1lu)
zero is 0/1
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
static constexpr const IntegralType integral_modulus
constexpr const TrivialType TrivialTypeNullElem(0xff)
ringbuffer< TrivialType, jau::nsize_t > TrivialTypeRingbuffer
METHOD_AS_TEST_CASE(TestRingbuffer11::test_sequential, "Test TestRingbuffer 11- test_sequential")