comparison src/synchronizedQueue/synchronizedQueueForSem.c @ 48:1b71266af056

Add CAS loop to synchronizedQueueForCas
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Fri, 22 May 2015 18:42:25 +0900
parents 2e7e66ccb3db
children
comparison
equal deleted inserted replaced
45:2e7e66ccb3db 48:1b71266af056
9 #ifdef CLANG 9 #ifdef CLANG
10 #define _CbC_retrun __return 10 #define _CbC_retrun __return
11 #define _CbC_environment __environment 11 #define _CbC_environment __environment
12 #endif 12 #endif
13 13
14 #define NUM 10 14 #define NUM 100
15 15
16 extern __code initSynchronizedQueueContext(struct Context* context); 16 extern __code initSynchronizedQueueContext(struct Context* context);
17 17
18 //__code code1(struct Context* context) { 18 //__code code1(struct Context* context) {
19 // context->data[Allocate]->allocate.size = sizeof(struct Element); 19 // context->data[Allocate]->allocate.size = sizeof(struct Element);
135 pthread_cond_wait(&context->data[Queue]->queue.queue_count->cond, &context->data[Queue]->queue.queue_count->mutex); 135 pthread_cond_wait(&context->data[Queue]->queue.queue_count->cond, &context->data[Queue]->queue.queue_count->mutex);
136 } 136 }
137 context->data[Queue]->queue.queue_count->value--; 137 context->data[Queue]->queue.queue_count->value--;
138 pthread_mutex_unlock(&context->data[Queue]->queue.queue_count->mutex); 138 pthread_mutex_unlock(&context->data[Queue]->queue.queue_count->mutex);
139 139
140 printf("Get %d\n\n", context->data[Queue]->queue.first->element.value); 140 printf(" Get %d\n\n", context->data[Queue]->queue.first->element.value);
141 context->data[Queue]->queue.first = (context->data[Queue]->queue.first->element.next) ? context->data[Queue]->queue.first->element.next : 0; 141 context->data[Queue]->queue.first = (context->data[Queue]->queue.first->element.next) ? context->data[Queue]->queue.first->element.next : 0;
142 142
143 // sem_v 143 // sem_v
144 pthread_mutex_lock(&context->data[Queue]->queue.queue_remain->mutex); 144 pthread_mutex_lock(&context->data[Queue]->queue.queue_remain->mutex);
145 context->data[Queue]->queue.queue_remain->value++; 145 context->data[Queue]->queue.queue_remain->value++;