Example #1
0
/*!
 * End current thread (exit from it)
 * \param status Exit status number
 */
int sys__thread_exit ( void *p )
{
	int status;

	status = *( (int *) p );

	active_thread->state = THR_STATE_PASSIVE;
	active_thread->ref_cnt--;
	active_thread->exit_status = status;

	active_thread->proc->thr_count--;

#ifdef	MESSAGES
	k_msgq_clean ( &active_thread->msg.msgq );
#endif
	/* release thread stack */
	if ( active_thread->stack )
	{
		if ( active_thread->proc->m.start ) /* user level thread */
			ffs_free ( active_thread->proc->stack_pool,
				   active_thread->stack );
		else /* kernel level thread */
			kfree ( active_thread->stack );
	}

	k_delete_thread_private_storage ( active_thread,
					  active_thread->private_storage );

	if ( active_thread->proc->thr_count == 0 && active_thread->proc->pi )
	{
		/* last (non-kernel) thread - remove process */
		ASSERT ( list_remove ( &procs, FIRST, &active_thread->proc->all ) );
		active_thread->proc->prog->started = FALSE;
		kfree ( active_thread->proc );
	}

	if ( !active_thread->ref_cnt )
	{
		k_remove_thread_descriptor ( active_thread );

		active_thread = NULL;
	}
	else {
		k_release_all_threads ( &active_thread->join_queue );
	}

	k_schedule_threads ();

	return 0;
}
Example #2
0
/*! restore previously saved state (last saved) */
int kthread_restore_state ( kthread_t *kthread )
{
	ASSERT ( kthread );

	kthread_state_t *state;
	/* perform cleanup of current state */
	kthread_state_cleanup_t *iter;
	while ( (iter = list_remove ( &kthread->state.cleanup, FIRST, NULL )) )
	{
		iter->cleanup ( iter->param1, iter->param2, iter->param3 );
		kfree (iter);
	}

	/* release thread stack */
	if ( kthread->state.stack )
	{
		if ( kthread->proc->stack_pool ) /* user level thread */
			ffs_free ( kthread->proc->stack_pool,
				   kthread->state.stack );
		else /* kernel level thread */
			kfree ( kthread->state.stack );
	}

	int retval = FALSE;

	/* overwrite state with first from list (if not empty) */
	state = list_remove ( &kthread->states, FIRST, NULL );
	if ( state )
	{
		kthread->state = *state;
		kfree ( state );
		retval = TRUE;
	}

	return retval;
}
Example #3
0
inline void k_delete_thread_private_storage ( kthread_t *kthr, void *ps )
{
	if ( ps )
		ffs_free ( kthr->proc->stack_pool, ps );
}
Example #4
0
/*! kfree for cleanup */
void kthread_param_free ( param_t p1, param_t p2, param_t p3 )
{
	ffs_free ( p1.p_ptr, p2.p_ptr );
}