66 std::shared_ptr<SharedTypeRingbuffer> createEmpty(
jau::nsize_t initialCapacity) {
67 return std::make_shared<SharedTypeRingbuffer>(initialCapacity);
69 std::shared_ptr<SharedTypeRingbuffer> createFull(
const std::vector<std::shared_ptr<Integer>> & source) {
70 return std::make_shared<SharedTypeRingbuffer>(source);
74 std::vector<SharedType> array(capacity);
76 array[i] = std::make_shared<Integer>(startValue+i);
81 void getThreadType01(
const std::string& msg,
const std::shared_ptr<SharedTypeRingbuffer>& rb,
jau::nsize_t len) {
96 void getRangeThreadType02(
const std::string& msg,
const std::shared_ptr<SharedTypeRingbuffer>& rb,
jau::nsize_t len) {
102 std::vector<SharedType> array(len);
103 REQUIRE_MSG(
"get-range of "+
std::to_string(array.size())+
" elem in "+rb->toString(), len==rb->getBlocking( &(*array.begin()), len, len, 0_s) );
114 void putThreadType01(
const std::string& msg,
const std::shared_ptr<SharedTypeRingbuffer>& rb,
jau::nsize_t len,
IntegralType startValue) {
122 REQUIRE(
true == rb->putBlocking(
SharedType( vI ), 0_s ) );
128 void putRangeThreadType02(
const std::string& msg,
const std::shared_ptr<SharedTypeRingbuffer>& rb,
jau::nsize_t len,
IntegralType startValue) {
133 std::vector<SharedType> data = createIntArray(len, startValue);
134 REQUIRE_MSG(
"put-range of "+
std::to_string(data.size())+
" elem in "+rb->toString(), rb->put( &(*data.begin()), &(*data.end()) ) );
143 INFO_STR(
"\n\ntest01a_Read1Write1\n");
145 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
147 fprintf(stderr,
"test01a_Read1Write1: %s\n", rb->get_info().c_str());
148 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
149 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
151 std::thread getThread01(&TestRingbuffer13::getThreadType01,
this,
"test01a.get01", rb, capacity);
152 std::thread putThread01(&TestRingbuffer13::putThreadType01,
this,
"test01a.put01", rb, capacity, 0);
156 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
157 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
161 INFO_STR(
"\n\ntest01b_Read1Write1_Range\n");
163 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
165 fprintf(stderr,
"test01b_Read1Write1_Range: %s\n", rb->get_info().c_str());
166 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
167 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
169 std::thread getThread01(&TestRingbuffer13::getRangeThreadType02,
this,
"test01b.getR01", rb, capacity);
170 std::thread putThread01(&TestRingbuffer13::putRangeThreadType02,
this,
"test01b.putR01", rb, capacity, 0);
174 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
175 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
179 INFO_STR(
"\n\ntest02a_Read4Write1\n");
181 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
182 rb->setMultiPCEnabled(
true);
184 fprintf(stderr,
"test02a_Read4Write1: %s\n", rb->get_info().c_str());
185 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
186 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
188 std::thread getThread01(&TestRingbuffer13::getThreadType01,
this,
"test02a.get01", rb, capacity/4);
189 std::thread getThread02(&TestRingbuffer13::getThreadType01,
this,
"test02a.get02", rb, capacity/4);
190 std::thread putThread01(&TestRingbuffer13::putThreadType01,
this,
"test02a.put01", rb, capacity, 0);
191 std::thread getThread03(&TestRingbuffer13::getThreadType01,
this,
"test02a.get03", rb, capacity/4);
192 std::thread getThread04(&TestRingbuffer13::getThreadType01,
this,
"test02a.get04", rb, capacity/4);
199 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
200 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
204 INFO_STR(
"\n\ntest02b_Read4Write1_Range\n");
206 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
207 rb->setMultiPCEnabled(
true);
209 fprintf(stderr,
"test02b_Read4Write1_Range: %s\n", rb->get_info().c_str());
210 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
211 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
213 std::thread getThread01(&TestRingbuffer13::getRangeThreadType02,
this,
"test02b.getR01", rb, capacity/4);
214 std::thread getThread02(&TestRingbuffer13::getRangeThreadType02,
this,
"test02b.getR02", rb, capacity/4);
215 std::thread putThread01(&TestRingbuffer13::putRangeThreadType02,
this,
"test02b.putR01", rb, capacity, 0);
216 std::thread getThread03(&TestRingbuffer13::getRangeThreadType02,
this,
"test02b.getR03", rb, capacity/4);
217 std::thread getThread04(&TestRingbuffer13::getRangeThreadType02,
this,
"test02b.getR04", rb, capacity/4);
224 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
225 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
229 INFO_STR(
"\n\ntest03a_Read8Write2\n");
231 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
232 rb->setMultiPCEnabled(
true);
234 fprintf(stderr,
"test03a_Read8Write2: %s\n", rb->get_info().c_str());
235 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
236 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
238 std::thread getThread01(&TestRingbuffer13::getThreadType01,
this,
"test03a.get01", rb, capacity/8);
239 std::thread getThread02(&TestRingbuffer13::getThreadType01,
this,
"test03a.get02", rb, capacity/8);
240 std::thread putThread01(&TestRingbuffer13::putThreadType01,
this,
"test03a.put01", rb, capacity/2, 0);
241 std::thread getThread03(&TestRingbuffer13::getThreadType01,
this,
"test03a.get03", rb, capacity/8);
242 std::thread getThread04(&TestRingbuffer13::getThreadType01,
this,
"test03a.get04", rb, capacity/8);
244 std::thread getThread05(&TestRingbuffer13::getThreadType01,
this,
"test03a.get05", rb, capacity/8);
245 std::thread getThread06(&TestRingbuffer13::getThreadType01,
this,
"test03a.get06", rb, capacity/8);
246 std::thread putThread02(&TestRingbuffer13::putThreadType01,
this,
"test03a.put02", rb, capacity/2, 400);
247 std::thread getThread07(&TestRingbuffer13::getThreadType01,
this,
"test03a.get07", rb, capacity/8);
248 std::thread getThread08(&TestRingbuffer13::getThreadType01,
this,
"test03a.get08", rb, capacity/8);
261 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
262 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
266 INFO_STR(
"\n\ntest03b_Read8Write2_Range\n");
268 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
269 rb->setMultiPCEnabled(
true);
271 fprintf(stderr,
"test03b_Read8Write2_Range: %s\n", rb->get_info().c_str());
272 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
273 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
275 std::thread getThread01(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR01", rb, capacity/8);
276 std::thread getThread02(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR02", rb, capacity/8);
277 std::thread putThread01(&TestRingbuffer13::putRangeThreadType02,
this,
"test03b.putR01", rb, capacity/2, 0);
278 std::thread getThread03(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR03", rb, capacity/8);
279 std::thread getThread04(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR04", rb, capacity/8);
281 std::thread getThread05(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR05", rb, capacity/8);
282 std::thread getThread06(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR06", rb, capacity/8);
283 std::thread putThread02(&TestRingbuffer13::putRangeThreadType02,
this,
"test03b.putR02", rb, capacity/2, 400);
284 std::thread getThread07(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR07", rb, capacity/8);
285 std::thread getThread08(&TestRingbuffer13::getRangeThreadType02,
this,
"test03b.getR08", rb, capacity/8);
298 REQUIRE_MSG(
"empty "+rb->toString(), rb->isEmpty());
299 REQUIRE_MSG(
"empty size "+rb->toString(), 0 == rb->size());
#define REQUIRE_MSG(MSG,...)
Integer(const Integer &o) noexcept=default
static Integer valueOf(const IntegralType i)
Integer(Integer &&o) noexcept=default
Integer & operator=(Integer &&o) noexcept=default
IntegralType intValue() const
Integer & operator=(const Integer &o) noexcept=default
void test01b_Read1Write1_Range()
void test03b_Read8Write2_Range()
void test01a_Read1Write1()
void test02b_Read4Write1_Range()
void test03a_Read8Write2()
void test02a_Read4Write1()
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.
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
jau::snsize_t IntegralType
std::shared_ptr< Integer > SharedType
constexpr const std::nullptr_t SharedTypeNullElem
METHOD_AS_TEST_CASE(TestRingbuffer13::test_sequential, "Test TestRingbuffer 13- test_sequential")
ringbuffer< SharedType, jau::nsize_t > SharedTypeRingbuffer