예제 #1
0
파일: ioq_linux.c 프로젝트: dlbeer/libdlb
static struct ioq_fd *mod_dequeue(struct ioq *q, int *flags,
				  ioq_fd_mask_t *requested)
{
	struct slist_node *n;
	struct ioq_fd *r = NULL;

	thr_mutex_lock(&q->lock);
	n = slist_pop(&q->mod_list);
	if (n) {
		r = container_of(n, struct ioq_fd, mod_list);
		r->flags &= ~IOQ_FLAG_MOD_LIST;
		*flags = r->flags;
		*requested = r->requested;
	}
	thr_mutex_unlock(&q->lock);

	return r;
}
예제 #2
0
static int frames_to_sample_list()
{
	int new_samples = 0;

	pthread_mutex_lock(&unsent_frame_count_mutex);
	while (g_unsent_frame_count > 0) {
		for (int i = 0; i < SAMPLES_PER_FRAME; i++) {
			struct sample *s = malloc(sizeof(struct sample));
			assert(s);
			memcpy(s, &(g_raw_samples->samples[i]),
			       sizeof(struct sample));
			struct slist *ln = malloc(sizeof(struct slist));
			assert(ln);
			ln->s = s;
			slist_push(sample_list, ln);
			g_sample_count++;
			new_samples++;
		}
		g_unsent_frame_count--;
	}
	pthread_mutex_unlock(&unsent_frame_count_mutex);

	int overflow = (slist_size(sample_list) > MAX_LIST_LEN)
	                   ? slist_size(sample_list) - MAX_LIST_LEN
	                   : 0;

	while (overflow--) {
		struct slist *ln = slist_pop(sample_list);
		assert(ln);
		assert(ln->s);
		free(ln->s);
		free(ln);
	}

	if (g_sample_count > MAX_LIST_LEN) {
		g_sample_count -= MAX_LIST_LEN;
	}
	return new_samples;
}