-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyclicRead.c
53 lines (51 loc) · 1.28 KB
/
cyclicRead.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdbool.h>
#include <unistd.h>
#include "cyclicBuf.h"
#include "gen.h"
int main()
{
int shmFd = shm_open( "shared_buffer", O_RDONLY, 0 );
if( shmFd == -1 )
{
perror("Can't open file");
return 1;
}
struct cyclic_buf* mem = mmap( NULL, sizeof(struct cyclic_buf), PROT_READ, MAP_SHARED, shmFd, 0 );
if( mem == NULL )
{
perror("Can't mmap");
return -1;
}
uint64_t cur_pos = mem -> pos;
if(cur_pos == 0){
cur_pos = 1;
}
uint64_t prev_seed = verify((void *)mem->BUFFER[cur_pos % 1000 - 1].arr); //get the seed of the previous element before we start reading
printf("starting at %ld\n", cur_pos);
while( true )
{
if(mem -> pos - cur_pos >= 1000){
printf("Lap error!");
break;
}
while(mem -> pos == cur_pos){};
int64_t cur_seed = verify((void *)mem->BUFFER[cur_pos % 1000].arr);
if(cur_seed == -1){
printf("Error!");
break;
}
if(cur_seed != prev_seed +1){ // checking if the seed of the current element is 1 less than previous one
printf("Wrong seed!");
break;
}
prev_seed +=1;
printf("Verified at %ld with seed %ld\n", cur_pos % 1000, cur_seed);
cur_pos ++;
//sleep(1); seems like the lap error check is working if this is not commented ;d
}
return 0;
}