Beispiel #1
0
int bb_wq_push(struct bb_session *bbs, char *buf, size_t len, int free_it) {

	if (wq_push(&bbs->writer, buf, len, free_it, 0)) return -1;
	// an item has been pushed, start the ev_io
	ev_io_start(blastbeat.loop, &bbs->writer.writer);
	return 0;
}
Beispiel #2
0
int bb_wq_push_close(struct bb_session *bbs) {

	if (wq_push(&bbs->writer, NULL, 0, 0, 1)) return -1;
	// an item has been pushed, start the ev_io
	ev_io_start(blastbeat.loop, &bbs->writer.writer);
	return 0;
}
Beispiel #3
0
// thread relinquish use of the processor
// and wait in the ready queuee
void th_yield()
{
	entry_section();

	if (threads[curr]->state == RUNNING)
		rq_push(curr);
	else if (threads[curr]->state == WAITING)
		wq_push(curr);

	// transfer the control to the next thread
	if (rq_begin != rq_end) {
		int old = curr;
		
		curr = rq_front();
		rq_pop();

		threads[curr]->state = RUNNING;

		exit_section();
		th_swap(threads[old], threads[curr]);
		entry_section();

		recycle_dead();
	}
	exit_section();
}
Beispiel #4
0
int bb_wq_push_copy(struct bb_session *bbs, char *buf, size_t len, int free_it) {

	char *new_buf = malloc(len);
	if (!new_buf) {
		bb_error("unable to allocate memory for writequeue item: malloc()");
		return -1;
	}
	memcpy(new_buf, buf, len);

	if (wq_push(&bbs->writer, new_buf, len, free_it, 0)) return -1;
	// an item has been pushed, start the ev_io
	ev_io_start(blastbeat.loop, &bbs->writer.writer);
	return 0;
}