MCPcopy Create free account
hub / github.com/F-Stack/f-stack / thread_suspend_check

Function thread_suspend_check

freebsd/kern/kern_thread.c:1320–1410  ·  view source on GitHub ↗

* Called in from locations that can safely check to see * whether we have to suspend or at least throttle for a * single-thread event (e.g. fork). * * Such locations include userret(). * If the "return_instead" argument is non zero, the thread must be able to * accept 0 (caller may continue), or 1 (caller must abort) as a result. * * The 'return_instead' argument tells the function if it m

Source from the content-addressed store, hash-verified

1318 * return_instead is set.
1319 */
1320int
1321thread_suspend_check(int return_instead)
1322{
1323 struct thread *td;
1324 struct proc *p;
1325 int wakeup_swapper;
1326
1327 td = curthread;
1328 p = td->td_proc;
1329 mtx_assert(&Giant, MA_NOTOWNED);
1330 PROC_LOCK_ASSERT(p, MA_OWNED);
1331 while (thread_suspend_check_needed()) {
1332 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
1333 KASSERT(p->p_singlethread != NULL,
1334 ("singlethread not set"));
1335 /*
1336 * The only suspension in action is a
1337 * single-threading. Single threader need not stop.
1338 * It is safe to access p->p_singlethread unlocked
1339 * because it can only be set to our address by us.
1340 */
1341 if (p->p_singlethread == td)
1342 return (0); /* Exempt from stopping. */
1343 }
1344 if ((p->p_flag & P_SINGLE_EXIT) && return_instead)
1345 return (EINTR);
1346
1347 /* Should we goto user boundary if we didn't come from there? */
1348 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE &&
1349 (p->p_flag & P_SINGLE_BOUNDARY) && return_instead)
1350 return (ERESTART);
1351
1352 /*
1353 * Ignore suspend requests if they are deferred.
1354 */
1355 if ((td->td_flags & TDF_SBDRY) != 0) {
1356 KASSERT(return_instead,
1357 ("TDF_SBDRY set for unsafe thread_suspend_check"));
1358 KASSERT((td->td_flags & (TDF_SEINTR | TDF_SERESTART)) !=
1359 (TDF_SEINTR | TDF_SERESTART),
1360 ("both TDF_SEINTR and TDF_SERESTART"));
1361 return (TD_SBDRY_INTR(td) ? TD_SBDRY_ERRNO(td) : 0);
1362 }
1363
1364 /*
1365 * If the process is waiting for us to exit,
1366 * this thread should just suicide.
1367 * Assumes that P_SINGLE_EXIT implies P_STOPPED_SINGLE.
1368 */
1369 if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) {
1370 PROC_UNLOCK(p);
1371
1372 /*
1373 * Allow Linux emulation layer to do some work
1374 * before thread suicide.
1375 */
1376 if (__predict_false(p->p_sysent->sv_thread_detach != NULL))
1377 (p->p_sysent->sv_thread_detach)(td);

Callers 6

fork_rfppwaitFunction · 0.85
kern_sigsuspendFunction · 0.85
sig_ast_checksuspFunction · 0.85
astFunction · 0.85
thread_check_suspFunction · 0.85
exit1Function · 0.85

Calls 10

mtx_assertFunction · 0.85
umtx_thread_exitFunction · 0.85
kern_thr_exitFunction · 0.85
thread_stoppedFunction · 0.85
thread_unsuspend_oneFunction · 0.85
kick_proc0Function · 0.85
thread_suspend_oneFunction · 0.85
panicFunction · 0.70
mi_switchFunction · 0.70

Tested by

no test coverage detected