MCPcopy Create free account
hub / github.com/acl-dev/acl / queue_pop_timedwait

Function queue_pop_timedwait

lib_fiber/c/src/common/queue.c:151–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151void *queue_pop_timedwait(QUEUE *que, int tmo_sec, int tmo_usec)
152{
153 QUEUE_ITEM *qi;
154 struct timeval tv;
155 struct timespec timeo, *ptimeo;
156 int status;
157 void *data;
158
159 if (que == NULL) {
160 msg_fatal("%s: que null", __FUNCTION__);
161 }
162
163 que->error = QUEUE_OK;
164
165 status = pthread_mutex_lock(&que->lock);
166 if (status) {
167 que->error = QUEUE_ERR_LOCK;
168 msg_error("%s: lock error(%s)", __FUNCTION__, last_serror());
169 return NULL;
170 }
171
172 qi = NULL;
173
174 while (1) {
175 if (tmo_sec < 0 || tmo_usec < 0) {
176 ptimeo = NULL;
177 } else {
178 gettimeofday(&tv, NULL);
179 timeo.tv_sec = tv.tv_sec + tmo_sec;
180 timeo.tv_nsec = tv.tv_usec * 1000 + tmo_usec * 1000;
181 timeo.tv_sec += timeo.tv_nsec / 1000000000;
182 timeo.tv_nsec %= 1000000000;
183 ptimeo = &timeo;
184 }
185
186 if (queue_wait(que, ptimeo) < 0) {
187 return NULL;
188 }
189
190 qi = que->first;
191 if (qi != NULL) {
192 que->first = qi->next;
193 que->qlen--;
194 if (que->last == qi) {
195 que->last = NULL;
196 }
197 break;
198 }
199 if (que->quit != 0) {
200 status = pthread_mutex_unlock(&que->lock);
201 if (status != 0) {
202 msg_error("%s(%d): unlock error(%s)",
203 __FUNCTION__, __LINE__, last_serror());
204 que->error = QUEUE_ERR_UNLOCK;
205 }
206
207 return NULL;
208 }

Callers 1

queue_popFunction · 0.85

Calls 8

msg_fatalFunction · 0.85
pthread_mutex_lockFunction · 0.85
queue_waitFunction · 0.85
pthread_mutex_unlockFunction · 0.85
freeFunction · 0.85
msg_errorFunction · 0.70
last_serrorFunction · 0.70
gettimeofdayFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…