Пример #1
0
void acl_fiber_sem_set_tid(ACL_FIBER_SEM *sem, acl_pthread_t tid)
{
	if (sem->tid != tid && acl_ring_size(&sem->waiting) > 0) {
		acl_msg_fatal("%s(%d), %s: curr sem waiting=%d not empty",
			__FILE__, __LINE__, __FUNCTION__,
			(int) acl_ring_size(&sem->waiting));
	}

	sem->tid = tid;
}
Пример #2
0
int acl_fiber_yield(void)
{
	int  n;

	if (acl_ring_size(&__thread_fiber->ready) == 0)
		return 0;

	n = __thread_fiber->switched;
	acl_fiber_ready(__thread_fiber->running);
	acl_fiber_switch();

	return __thread_fiber->switched - n - 1;
}
Пример #3
0
static void fiber_swap(ACL_FIBER *from, ACL_FIBER *to)
{
	if (from->status == FIBER_STATUS_EXITING) {
		size_t slot = from->slot;
		int n = acl_ring_size(&__thread_fiber->dead);

		/* if the cached dead fibers reached the limit,
		 * some will be freed
		 */
		if (n > MAX_CACHE) {
			n -= MAX_CACHE;
			fiber_kick(n);
		}

		if (!from->sys)
			__thread_fiber->count--;

		__thread_fiber->fibers[slot] =
			__thread_fiber->fibers[--__thread_fiber->slot];
		__thread_fiber->fibers[slot]->slot = slot;

		acl_ring_prepend(&__thread_fiber->dead, &from->me);
	}

#ifdef	USE_JMP
	/* use setcontext() for the initial jump, as it allows us to set up
	 * a stack, but continue with longjmp() as it's much faster.
	 */
	if (SETJMP(from->env) == 0) {
		/* context just be used once for set up a stack, which will
		 * be freed in fiber_start. The context in __thread_fiber
		 * was set NULL.
		 */
		if (to->context != NULL)
			setcontext(to->context);
		else
			LONGJMP(to->env);
	}
#else
	if (swapcontext(from->context, to->context) < 0)
		acl_msg_fatal("%s(%d), %s: swapcontext error %s",
			__FILE__, __LINE__, __FUNCTION__, acl_last_serror());
#endif
}
Пример #4
0
int   json_node::children_count(void) const
{
	return acl_ring_size(&node_me_->children);
}
Пример #5
0
int acl_fiber_ndead(void)
{
	if (__thread_fiber == NULL)
		return 0;
	return acl_ring_size(&__thread_fiber->dead);
}
Пример #6
0
int icmp_chat_finish(ICMP_CHAT *chat)
{
	if (chat->count == acl_ring_size(&chat->host_head))
		return (1);
	return (0);
}
Пример #7
0
int icmp_chat_size(ICMP_CHAT *chat)
{
	return (acl_ring_size(&chat->host_head));
}
Пример #8
0
			acl_ring_prepend(&__ring_header, &my_type->ring_entry);
		else
			acl_ring_append(&__ring_header, &my_type->ring_entry);
	}
}

int test_ring(AUT_LINE *test_line acl_unused, void *arg acl_unused)
{
	ACL_RING_ITER ring_iter;
	MY_TYPE *my_type;

	acl_ring_init(&__ring_header);

	__create_ring(0, 10);

	printf("\nring loop printf:> len=%d\n", acl_ring_size(&__ring_header));

	acl_ring_foreach(ring_iter, &__ring_header) {
		my_type = ACL_RING_TO_APPL(ring_iter.ptr, MY_TYPE, ring_entry);
		printf("name=%s, value=%s\n", my_type->name, my_type->value);
	}

	printf("\nring pop head loop printf:> len=%d\n", acl_ring_size(&__ring_header));

	while (1) {
		ring_iter.ptr = acl_ring_pop_head(&__ring_header);
		if (ring_iter.ptr == NULL)
			break;

		my_type = ACL_RING_TO_APPL(ring_iter.ptr, MY_TYPE, ring_entry);
		printf("name=%s, value=%s\n", my_type->name, my_type->value);