Example #1
0
void
mread_yield(struct mread_pool * self) {
	if (self->active == -1) {
		return;
	}
	struct socket *s = &self->sockets[self->active];
	ringbuffer_free(self->rb , s->temp);
	s->temp = NULL;
	if (s->status == SOCKET_CLOSED && s->node == NULL) {
		--self->closed;
		s->status = SOCKET_INVALID;
		s->fd = self->free_socket - self->sockets;
		self->free_socket = s;
		self->skip = 0;
		self->active = -1;
	} else {
		if (s->node) {
			s->node = ringbuffer_yield(self->rb, s->node, self->skip);
		}
		self->skip = 0;
		if (s->node == NULL) {
			self->active = -1;
		}
	}
}
Example #2
0
static void
test(struct ringbuffer *rb) {
	struct ringbuffer_block * blk;
	blk = ringbuffer_alloc(rb,80);
	blk->id = 0;
	ringbuffer_free(rb,blk);
	blk = ringbuffer_alloc(rb,50);
	blk->id = 1;
	struct ringbuffer_block * next = ringbuffer_alloc(rb, 40);
	next->id = 1;
	ringbuffer_link(rb, blk, next);
	ringbuffer_dump(rb);
	blk = ringbuffer_alloc(rb,4);
	printf("%p\n",blk);
	int id = ringbuffer_collect(rb);
	printf("collect %d\n",id);

	blk = ringbuffer_alloc(rb,4);
	blk->id = 2;
	init(blk,4);

	next = ringbuffer_alloc(rb,5);
	init(next,5);
	ringbuffer_link(rb, blk, next);

	next = ringbuffer_alloc(rb,6);
	init(next,6);
	ringbuffer_link(rb, blk , next);


	dump(rb, blk , 3);
	dump(rb, blk , 6);
	dump(rb, blk , 16);

	blk = ringbuffer_yield(rb, blk, 5);

	next = ringbuffer_alloc(rb, 7);
	ringbuffer_copy(rb, blk, 1, next);
	dump(rb, next, 7);

	blk = ringbuffer_yield(rb, blk , 5);

	ringbuffer_dump(rb);
}