-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-list.c
114 lines (91 loc) · 2.59 KB
/
example-list.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<stdio.h>
#include "list.h"
#include <time.h>
// #include <pthread.h>
// pthread_mutex_t mx_concent = PTHREAD_MUTEX_INITIALIZER;
// #define LOCK pthread_mutex_lock(&mx_concent)
// #define UNLOCK pthread_mutex_unlock(&mx_concent)
void main( void )
{
uint64_t timestamp = 0;
char key[128] = { 0 };
DataFrame *data = NULL;
link* list = initLink();
if( list == NULL )
{
printf("initLink failed !\r\n");
return;
}
for( uint16_t i = 0; i < 1024; i ++ )
{
data = NULL;
data = (DataFrame *)malloc(sizeof(DataFrame));
if( data )
{
memset( data->key, 0, sizeof(data->key) );
sprintf( data->key, "%04x", i );
if( enterQueueByRear( list, data ) == false )
{
free(data);
}
}
}
for( uint16_t i = 0; i < 1024; i ++ )
{
memset( key, 0, sizeof(key) );
sprintf( key, "%04x", i );
//if( deleteQueue( list, (void **)(&data) ) )
if( deleteQueueByKey( list, (void **)(&data), key ) )
{
printf("key[%s] index[%d]\r\n",data->key,i);
free(data);
}
}
for( uint16_t i = 0; i < 1024; i ++ )
{
data = NULL;
data = (DataFrame *)malloc(sizeof(DataFrame));
if( data )
{
time( &data->timestamp );
memset( data->key, 0, sizeof(data->key) );
sprintf( data->key, "%04x", i );
if( enterQueueByRear( list, data ) == false )
{
free(data);
}
}
}
uint32_t queue_count = 0;
while ( true )
{
queue_count = getQueueCount( list );
if( queue_count == 0 )
{
printf( "Queue is empty, exit\r\n" );
break;
}
for( int i = 0; i < queue_count; i ++ )
{
if( deleteQueue( list, (void **)(&data) ) )
{
time( ×tamp );
if( timestamp > (data->timestamp+1*60) )
{
printf("KEY[%s] Out of queue\r\n", data->key );
free(data);
}
else
{
if( enterQueueByRear( list, data ) == false )
{
free(data);
}
}
}
}
printf( "Scanning\r\n" );
sleep( 1 );
}
free( list );
}