Bug...................................
This commit is contained in:
parent
85071d3130
commit
a5c5ecd64b
1 changed files with 38 additions and 2 deletions
40
driver.c
40
driver.c
|
@ -11,16 +11,52 @@ int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
struct RingBuf rb;
|
struct RingBuf rb;
|
||||||
|
int d;
|
||||||
rb_init(&rb, 10, malloc, sizeof(int));
|
rb_init(&rb, 10, malloc, sizeof(int));
|
||||||
|
const int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||||
|
|
||||||
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
// Single writes
|
||||||
|
printf("\n=== Single writes ===\n\n");
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < 5) {
|
||||||
|
if(rb_push_back(&rb, &arr[idx], memcpy) != WriteOk) {
|
||||||
|
printf("Failed to write data to buffer...\n");
|
||||||
|
}
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pop the last n elements
|
||||||
|
for(int a = 0; a < 1; a++) {
|
||||||
|
if(rb_pop_front(&rb, &d, memcpy) != ReadOk) {
|
||||||
|
printf("Failed to read data from buffer...\n");
|
||||||
|
}
|
||||||
|
printf("Data: %d\n", d);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("idx: %d\n", idx);
|
||||||
|
|
||||||
|
// Push the rest
|
||||||
|
while (rb_push_back(&rb, &arr[idx], memcpy) == WriteOk) {
|
||||||
|
printf("Wrote: %d\n", arr[idx]);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Data: [");
|
||||||
|
while(rb_pop_front(&rb, &d, memcpy) == ReadOk)
|
||||||
|
printf("%d,", d);
|
||||||
|
printf("\b]\n");
|
||||||
|
|
||||||
|
// Multiple writes
|
||||||
|
printf("\n=== Multiple writes ===\n\n");
|
||||||
|
|
||||||
|
rb_clear(&rb);
|
||||||
|
|
||||||
int ok = WriteOk; // Assume we can write
|
int ok = WriteOk; // Assume we can write
|
||||||
if(rb_push_many(&rb, arr, memcpy, 8) != WriteOk) {
|
if(rb_push_many(&rb, arr, memcpy, 8) != WriteOk) {
|
||||||
printf("Failed to write data to buffer...\n");
|
printf("Failed to write data to buffer...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int d;
|
|
||||||
printf("Data: [");
|
printf("Data: [");
|
||||||
while(rb_pop_front(&rb, &d, memcpy) == ReadOk)
|
while(rb_pop_front(&rb, &d, memcpy) == ReadOk)
|
||||||
printf("%d,", d);
|
printf("%d,", d);
|
||||||
|
|
Loading…
Reference in a new issue