void uthread_exit ()
{
	size_t space_for_mem_alloc_hdr[16]; /* just in case ... */
	uthread_t *cur_thread, *new_thread, tmp;

	/* active thread is exiting */
	cur_thread = list_remove ( &active, FIRST, NULL );

	space_for_mem_alloc_hdr[0] = (size_t) cur_thread;
	/*remove compiler 'not-used' warning */

	free ( cur_thread->stack );
	/* freeing it, but using it still - till the end of this function
	   (parameters are on stack!) */

	tmp = *cur_thread;
	free ( cur_thread );

	/* pick next ready thread */
	new_thread = list_remove ( &ready, FIRST, NULL );
	/* make it active */
	list_append ( &active, new_thread, &new_thread->list );
	/* switch to it */
	arch_switch_to_uthread ( &tmp.context, &new_thread->context );
}
void uthread_yield ()
{
	uthread_t *cur_thread, *new_thread;

	/* remove current thread from 'active' and put it as last in 'ready' */
	cur_thread = list_remove ( &active, FIRST, NULL );
	list_append ( &ready, cur_thread, &cur_thread->list );

	/* remove first thread from 'ready' and put it in 'active' */
	new_thread = list_remove ( &ready, FIRST, NULL );
	list_append ( &active, new_thread, &new_thread->list );

	/* switch to new active thread */
	arch_switch_to_uthread ( &cur_thread->context, &new_thread->context );
}
Esempio n. 3
0
void uthread_exit ()
{
	uthread_t *cur_thread, *new_thread, tmp;

	/* active thread is exiting */
	cur_thread = list_remove ( &active, FIRST, NULL );

	free ( cur_thread->stack );
	/* freeing it, but using it still - till the end of this function
	   (parameters are on stack!) */

	tmp = *cur_thread;
	free ( cur_thread );

	/* pick next ready thread */
	new_thread = list_remove ( &ready, FIRST, NULL );
	/* make it active */
	list_append ( &active, new_thread, &new_thread->list );
	/* switch to it */
	arch_switch_to_uthread ( &tmp.context, &new_thread->context );
}