Mercurial > pt1
comparison recpt1/recpt1.c @ 125:a910b49dfbee
work in progress improvement:
- fix bugs around cond_timedwait
- try to avoid sticking in PMT analysis
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 21 Feb 2012 15:46:04 +0900 |
parents | d89f0da0a7e4 |
children | 8e0f7191b92e |
comparison
equal
deleted
inserted
replaced
124:f2ae5ddeed7e | 125:a910b49dfbee |
---|---|
207 void | 207 void |
208 enqueue(QUEUE_T *p_queue, BUFSZ *data) | 208 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
209 { | 209 { |
210 struct timeval now; | 210 struct timeval now; |
211 struct timespec spec; | 211 struct timespec spec; |
212 | 212 int retry_count = 0; |
213 gettimeofday(&now, NULL); | |
214 spec.tv_sec = now.tv_sec + 1; | |
215 spec.tv_nsec = now.tv_usec * 1000; | |
216 | 213 |
217 pthread_mutex_lock(&p_queue->mutex); | 214 pthread_mutex_lock(&p_queue->mutex); |
218 /* entered critical section */ | 215 /* entered critical section */ |
219 | 216 |
220 /* wait while queue is full */ | 217 /* wait while queue is full */ |
221 while(p_queue->num_avail == 0) { | 218 while(p_queue->num_avail == 0) { |
219 | |
220 gettimeofday(&now, NULL); | |
221 spec.tv_sec = now.tv_sec + 1; | |
222 spec.tv_nsec = now.tv_usec * 1000; | |
223 | |
222 pthread_cond_timedwait(&p_queue->cond_avail, | 224 pthread_cond_timedwait(&p_queue->cond_avail, |
223 &p_queue->mutex, &spec); | 225 &p_queue->mutex, &spec); |
226 retry_count++; | |
227 if(retry_count > 60) { | |
228 f_exit = TRUE; | |
229 } | |
224 if(f_exit) { | 230 if(f_exit) { |
225 pthread_mutex_unlock(&p_queue->mutex); | 231 pthread_mutex_unlock(&p_queue->mutex); |
226 return; | 232 return; |
227 } | 233 } |
228 } | 234 } |
247 dequeue(QUEUE_T *p_queue) | 253 dequeue(QUEUE_T *p_queue) |
248 { | 254 { |
249 struct timeval now; | 255 struct timeval now; |
250 struct timespec spec; | 256 struct timespec spec; |
251 BUFSZ *buffer; | 257 BUFSZ *buffer; |
252 | 258 int retry_count = 0; |
253 gettimeofday(&now, NULL); | |
254 spec.tv_sec = now.tv_sec + 1; | |
255 spec.tv_nsec = now.tv_usec * 1000; | |
256 | 259 |
257 pthread_mutex_lock(&p_queue->mutex); | 260 pthread_mutex_lock(&p_queue->mutex); |
258 /* entered the critical section*/ | 261 /* entered the critical section*/ |
259 | 262 |
260 /* wait while queue is empty */ | 263 /* wait while queue is empty */ |
261 while(p_queue->num_used == 0) { | 264 while(p_queue->num_used == 0) { |
265 | |
266 gettimeofday(&now, NULL); | |
267 spec.tv_sec = now.tv_sec + 1; | |
268 spec.tv_nsec = now.tv_usec * 1000; | |
269 | |
262 pthread_cond_timedwait(&p_queue->cond_used, | 270 pthread_cond_timedwait(&p_queue->cond_used, |
263 &p_queue->mutex, &spec); | 271 &p_queue->mutex, &spec); |
272 retry_count++; | |
273 if(retry_count > 60) { | |
274 f_exit = TRUE; | |
275 } | |
264 if(f_exit) { | 276 if(f_exit) { |
265 pthread_mutex_unlock(&p_queue->mutex); | 277 pthread_mutex_unlock(&p_queue->mutex); |
266 return NULL; | 278 return NULL; |
267 } | 279 } |
268 } | 280 } |