| 111 | } |
| 112 | |
| 113 | static int queue_wait(QUEUE *que, const struct timespec *ptimeo) |
| 114 | { |
| 115 | int status; |
| 116 | |
| 117 | while (que->first == NULL && que->quit == 0) { |
| 118 | if (ptimeo != NULL) { |
| 119 | status = pthread_cond_timedwait(&que->cond, |
| 120 | &que->lock, ptimeo); |
| 121 | } else { |
| 122 | status = pthread_cond_wait(&que->cond, &que->lock); |
| 123 | } |
| 124 | |
| 125 | if (ptimeo && status == FIBER_ETIME) { |
| 126 | status = pthread_mutex_unlock(&que->lock); |
| 127 | if (status != 0) { |
| 128 | msg_error("%s(%d): unlock error(%s)", |
| 129 | __FUNCTION__, __LINE__, last_serror()); |
| 130 | } |
| 131 | |
| 132 | que->error = QUEUE_ERR_TIMEOUT; |
| 133 | return -1; |
| 134 | } else if (status != 0) { |
| 135 | status = pthread_mutex_unlock(&que->lock); |
| 136 | if (status != 0) { |
| 137 | msg_error("%s(%d): unlock error(%s)", |
| 138 | __FUNCTION__, __LINE__, last_serror()); |
| 139 | } |
| 140 | |
| 141 | que->error = QUEUE_ERR_COND_WAIT; |
| 142 | msg_error("%s: cond wait error(%s)", |
| 143 | __FUNCTION__, last_serror()); |
| 144 | return -1; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | void *queue_pop_timedwait(QUEUE *que, int tmo_sec, int tmo_usec) |
| 152 | { |
no test coverage detected
searching dependent graphs…