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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| #include "list_in_shm.h"
| #include <string.h>
| #include <unistd.h>
| #include <stdlib.h>
| #define SHM_NAME "pollcontrol"
| #define SEM_FILE "/sem_pollcontrol"
| #define ID 0xdeadbeef
| #define MAX_NODES 1000
|
| typedef struct data
| {
| uint32_t p_off ;
| uint32_t n_off ;
| uint32_t data;
| }data_t;
|
| int main(int argc, char * argv[])
| {
| list_in_shm_handle_t h = {0,};
| data_t * temp= NULL ;
| uint8_t *temp2=NULL ;
| int i =0;
| if( 2 != argc )
| exit(-1);
| if (strcmp(argv[1],"test")== 0)
| {
| list_in_shm_init(&h,SHM_NAME,sizeof(data_t),MAX_NODES,SEM_FILE,1);
| #if 1
| for(i=0;i<MAX_NODES;i++)
| {
| temp=get_node_from_shm(&h,FROM_FREE_LIST);
| if(NULL != temp)
| {
| temp->data=i;
| put_node_in_list(&h,(node_sm_t *)temp,FROM_LIST);
| }
| }
|
| for(i=0;i<MAX_NODES;i++)
| {
| temp=get_node_from_shm(&h,FROM_LIST|FROM_FRONT);
| if(NULL != temp)
| {
| printf("\n %d %d",i,temp->data);
| }
| }
| #endif
| }
| else if (strcmp(argv[1],"write")== 0)
| {
| list_in_shm_init(&h,SHM_NAME,sizeof(data_t),MAX_NODES,SEM_FILE,1);
| #if 1
| for(i=0;i<MAX_NODES;i++)
| {
| temp=get_node_from_shm(&h,FROM_FREE_LIST);
| if(NULL != temp)
| {
| temp->data=i;
| put_node_in_list(&h,(node_sm_t *)temp,FROM_LIST|FROM_LIST);
| }
| }
| #endif
| }
| else if (strcmp(argv[1],"read")==0)
| {
| list_in_shm_init(&h,SHM_NAME,sizeof(data_t),MAX_NODES,SEM_FILE,0);
| for(i=0;i<MAX_NODES;i++)
| {
| temp=get_node_from_shm(&h,FROM_LIST);
| if(NULL != temp)
| {
| printf("\n %d %d",i,temp->data);
| }
| }
|
| }
| else if (strcmp(argv[1],"dump")== 0)
| {
| list_in_shm_init(&h,SHM_NAME,sizeof(data_t),MAX_NODES,SEM_FILE,0);
| temp2=h.ptr;
| for(i=0;i<h.size;i++)
| {
| if(0 != i && i % 16 == 0 )
| printf("\n");
| printf("%02x",temp2[i]);
| }
| }
| }
|
|