Example #1
0
void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms)
{
	double t;
	void *work = NULL;
	struct timespec timeout;

	t = PIL_check_seconds_timer();
	wait_timeout(&timeout, ms);

	/* wait until there is work */
	pthread_mutex_lock(&queue->mutex);
	while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) {
		if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT)
			break;
		else if (PIL_check_seconds_timer() - t >= ms * 0.001)
			break;
	}

	/* if we have something, pop it */
	if (!BLI_gsqueue_is_empty(queue->queue)) {
		BLI_gsqueue_pop(queue->queue, &work);
		
		if (BLI_gsqueue_is_empty(queue->queue))
			pthread_cond_broadcast(&queue->finish_cond);
	}
	
	pthread_mutex_unlock(&queue->mutex);

	return work;
}
Example #2
0
void *BLI_thread_queue_pop(ThreadQueue *queue)
{
	void *work= NULL;

	/* wait until there is work */
	pthread_mutex_lock(&queue->mutex);
	while(BLI_gsqueue_is_empty(queue->queue) && !queue->nowait)
		pthread_cond_wait(&queue->cond, &queue->mutex);

	/* if we have something, pop it */
	if(!BLI_gsqueue_is_empty(queue->queue))
		BLI_gsqueue_pop(queue->queue, &work);

	pthread_mutex_unlock(&queue->mutex);

	return work;
}
Example #3
0
void BLI_thread_queue_wait_finish(ThreadQueue *queue)
{
	/* wait for finish condition */
	pthread_mutex_lock(&queue->mutex);

	while (!BLI_gsqueue_is_empty(queue->queue))
		pthread_cond_wait(&queue->finish_cond, &queue->mutex);

	pthread_mutex_unlock(&queue->mutex);
}
Example #4
0
void BLI_gsqueue_push(GSQueue *gq, void *item)
{
	GSQueueElem *elem;
	
	/* compare: prevent events added double in row */
	if (!BLI_gsqueue_is_empty(gq)) {
		if(0==memcmp(item, &gq->head[1], gq->elem_size))
			return;
	}
	elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push");
	memcpy(&elem[1], item, gq->elem_size);
	elem->next= NULL;
	
	if (BLI_gsqueue_is_empty(gq)) {
		gq->tail= gq->head= elem;
	} else {
		gq->tail= gq->tail->next= elem;
	}
}
Example #5
0
void BLI_gsqueue_pushback(GSQueue *gq, void *item)
{
	GSQueueElem *elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push");
	memcpy(&elem[1], item, gq->elem_size);
	elem->next= gq->head;

	if (BLI_gsqueue_is_empty(gq)) {
		gq->head= gq->tail= elem;
	} else {
		gq->head= elem;
	}
}