3 prefetchthreadqueue_t queue; //Global shared prefetch queue
5 void queueInsert(int *array) {
6 pthread_mutex_lock(&queue.qlock);
7 queue.rear = queue.rear % ARRAY_SIZE;
8 if(queue.front == queue.rear && queue.buffer[queue.front] != NULL) {
9 printf("The Circular Queue is Full : OVERFLOW\n");
10 pthread_mutex_unlock(&queue.qlock);
13 queue.buffer[queue.rear] = array;
16 pthread_mutex_unlock(&queue.qlock);
22 pthread_mutex_lock(&queue.qlock);
23 if(queue.front == queue.rear && queue.buffer[queue.front] == NULL) {
24 printf("The Circular Queue is Empty : UNDERFLOW\n");
25 pthread_mutex_unlock(&queue.qlock);
28 i = queue.buffer[queue.front];
29 queue.buffer[queue.front] = NULL;
31 queue.front = queue.front % ARRAY_SIZE;
32 pthread_mutex_unlock(&queue.qlock);
41 for(i = 0; i< ARRAY_SIZE; i++)
42 queue.buffer[i] = NULL;
43 /* Initialize the pthread_mutex variable */
44 pthread_mutex_init(&queue.qlock, NULL);
47 /* For testing purposes */
52 int a[] = {5, 2, 8, -1};
53 int b[] = {11, 8, 4, 19, -1};
54 int c[] = {16, 8, 4, -1};
55 printf("Front = %d, Rear = %d\n",queue.front, queue.rear);
57 printf("Front = %d, Rear = %d\n",queue.front, queue.rear);
59 printf("Enqueued ptr is %x\n", a);
60 printf("1st Insert Front = %d, Rear = %d\n",queue.front, queue.rear);
62 printf("Enqueued ptr is %x\n", b);
63 printf("2nd Insert Front = %d, Rear = %d\n",queue.front, queue.rear);
65 printf("3rd Insert Front = %d, Rear = %d\n",queue.front, queue.rear);
67 printf("Dequeued ptr is %x\n", d);
68 printf("After 1st del Front = %d, Rear = %d\n",queue.front, queue.rear);
70 printf("Enqueued ptr is %x\n", c);
71 printf("After 4th insert Front = %d, Rear = %d\n",queue.front, queue.rear);
73 printf("Dequeued ptr is %x\n", d);
74 printf("After 2nd del Front = %d, Rear = %d\n",queue.front, queue.rear);
76 printf("Dequeued ptr is %x\n", d);
77 printf("After 3rd del Front = %d, Rear = %d\n",queue.front, queue.rear);
79 printf("Dequeued ptr is %x\n", d);
80 printf("After 4th del Front = %d, Rear = %d\n",queue.front, queue.rear);