コード例 #1
0
int
cloudabi_sys_thread_exit(struct thread *td,
    struct cloudabi_sys_thread_exit_args *uap)
{
	struct cloudabi_sys_lock_unlock_args cloudabi_sys_lock_unlock_args = {
		.lock = uap->lock,
		.scope = uap->scope,
	};

	umtx_thread_exit(td);

        /* Wake up joining thread. */
	cloudabi_sys_lock_unlock(td, &cloudabi_sys_lock_unlock_args);

        /*
	 * Attempt to terminate the thread. Terminate the process if
	 * it's the last thread.
	 */
	kern_thr_exit(td);
	exit1(td, 0, 0);
	/* NOTREACHED */
}

int
cloudabi_sys_thread_yield(struct thread *td,
    struct cloudabi_sys_thread_yield_args *uap)
{

	sched_relinquish(td);
	return (0);
}
コード例 #2
0
int
kern_thr_exit(struct thread *td)
{
	struct proc *p;

	p = td->td_proc;

	rw_wlock(&tidhash_lock);
	PROC_LOCK(p);

	if (p->p_numthreads != 1) {
		racct_sub(p, RACCT_NTHR, 1);
		LIST_REMOVE(td, td_hash);
		rw_wunlock(&tidhash_lock);
		tdsigcleanup(td);
		umtx_thread_exit(td);
		PROC_SLOCK(p);
		thread_stopped(p);
		thread_exit();
		/* NOTREACHED */
	}

	/*
	 * Ignore attempts to shut down last thread in the proc.  This
	 * will actually call _exit(2) in the usermode trampoline when
	 * it returns.
	 */
	PROC_UNLOCK(p);
	rw_wunlock(&tidhash_lock);
	return (0);
}
コード例 #3
0
ファイル: kern_kthread.c プロジェクト: lilinj2000/freebsd
void
kthread_exit(void)
{
	struct proc *p;

	p = curthread->td_proc;

	/* A module may be waiting for us to exit. */
	wakeup(curthread);

	/*
	 * The last exiting thread in a kernel process must tear down
	 * the whole process.
	 */
	rw_wlock(&tidhash_lock);
	PROC_LOCK(p);
	if (p->p_numthreads == 1) {
		PROC_UNLOCK(p);
		rw_wunlock(&tidhash_lock);
		kproc_exit(0);
	}
	LIST_REMOVE(curthread, td_hash);
	rw_wunlock(&tidhash_lock);
	umtx_thread_exit(curthread);
	PROC_SLOCK(p);
	thread_exit();
}
コード例 #4
0
ファイル: kern_thr.c プロジェクト: outbackdingo/uBSD
int
kern_thr_exit(struct thread *td)
{
	struct proc *p;

	p = td->td_proc;

	/*
	 * If all of the threads in a process call this routine to
	 * exit (e.g. all threads call pthread_exit()), exactly one
	 * thread should return to the caller to terminate the process
	 * instead of the thread.
	 *
	 * Checking p_numthreads alone is not sufficient since threads
	 * might be committed to terminating while the PROC_LOCK is
	 * dropped in either ptracestop() or while removing this thread
	 * from the tidhash.  Instead, the p_pendingexits field holds
	 * the count of threads in either of those states and a thread
	 * is considered the "last" thread if all of the other threads
	 * in a process are already terminating.
	 */
	PROC_LOCK(p);
	if (p->p_numthreads == p->p_pendingexits + 1) {
		/*
		 * Ignore attempts to shut down last thread in the
		 * proc.  This will actually call _exit(2) in the
		 * usermode trampoline when it returns.
		 */
		PROC_UNLOCK(p);
		return (0);
	}

	p->p_pendingexits++;
	td->td_dbgflags |= TDB_EXIT;
	if (p->p_flag & P_TRACED && p->p_flag2 & P2_LWP_EVENTS)
		ptracestop(td, SIGTRAP);
	PROC_UNLOCK(p);
	tidhash_remove(td);
	PROC_LOCK(p);
	p->p_pendingexits--;

	/*
	 * The check above should prevent all other threads from this
	 * process from exiting while the PROC_LOCK is dropped, so
	 * there must be at least one other thread other than the
	 * current thread.
	 */
	KASSERT(p->p_numthreads > 1, ("too few threads"));
	racct_sub(p, RACCT_NTHR, 1);
	tdsigcleanup(td);
	umtx_thread_exit(td);
	PROC_SLOCK(p);
	thread_stopped(p);
	thread_exit();
	/* NOTREACHED */
}
コード例 #5
0
ファイル: kern_thr.c プロジェクト: bhimanshu1997/freebsd
int
sys_thr_exit(struct thread *td, struct thr_exit_args *uap)
    /* long *state */
{

	umtx_thread_exit(td);

	/* Signal userland that it can free the stack. */
	if ((void *)uap->state != NULL) {
		suword_lwpid(uap->state, 1);
		kern_umtx_wake(td, uap->state, INT_MAX, 0);
	}

	return (kern_thr_exit(td));
}
コード例 #6
0
ファイル: linux_fork.c プロジェクト: 2asoft/freebsd
int
linux_exit(struct thread *td, struct linux_exit_args *args)
{
	struct linux_emuldata *em;

	em = em_find(td);
	KASSERT(em != NULL, ("exit: emuldata not found.\n"));

	LINUX_CTR2(exit, "thread(%d) (%d)", em->em_tid, args->rval);

	umtx_thread_exit(td);

	linux_thread_detach(td);

	/*
	 * XXX. When the last two threads of a process
	 * exit via pthread_exit() try thr_exit() first.
	 */
	kern_thr_exit(td);
	exit1(td, args->rval, 0);
		/* NOTREACHED */
}