kern_thr.c (166188) | kern_thr.c (170307) |
---|---|
1/*- 2 * Copyright (c) 2003, Jeffrey Roberson <jeff@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003, Jeffrey Roberson <jeff@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/kern/kern_thr.c 166188 2007-01-23 08:46:51Z jeff $"); | 28__FBSDID("$FreeBSD: head/sys/kern/kern_thr.c 170307 2007-06-05 00:00:57Z jeff $"); |
29 30#include "opt_compat.h" 31#include "opt_posix.h" 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/lock.h> 35#include <sys/mutex.h> 36#include <sys/priv.h> --- 184 unchanged lines hidden (view full) --- 221 crfree(td->td_ucred); 222 return (error); 223 } 224 } 225 226 PROC_LOCK(td->td_proc); 227 td->td_proc->p_flag |= P_HADTHREADS; 228 newtd->td_sigmask = td->td_sigmask; | 29 30#include "opt_compat.h" 31#include "opt_posix.h" 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/lock.h> 35#include <sys/mutex.h> 36#include <sys/priv.h> --- 184 unchanged lines hidden (view full) --- 221 crfree(td->td_ucred); 222 return (error); 223 } 224 } 225 226 PROC_LOCK(td->td_proc); 227 td->td_proc->p_flag |= P_HADTHREADS; 228 newtd->td_sigmask = td->td_sigmask; |
229 mtx_lock_spin(&sched_lock); | 229 PROC_SLOCK(p); |
230 thread_link(newtd, p); | 230 thread_link(newtd, p); |
231 PROC_UNLOCK(p); 232 | 231 thread_lock(td); |
233 /* let the scheduler know about these things. */ 234 sched_fork_thread(td, newtd); | 232 /* let the scheduler know about these things. */ 233 sched_fork_thread(td, newtd); |
234 thread_unlock(td); 235 PROC_SUNLOCK(p); 236 PROC_UNLOCK(p); 237 thread_lock(newtd); |
|
235 if (rtp != NULL) { 236 if (!(td->td_pri_class == PRI_TIMESHARE && 237 rtp->type == RTP_PRIO_NORMAL)) { 238 rtp_to_pri(rtp, newtd); 239 sched_prio(newtd, newtd->td_user_pri); 240 } /* ignore timesharing class */ 241 } 242 TD_SET_CAN_RUN(newtd); 243 /* if ((flags & THR_SUSPENDED) == 0) */ 244 sched_add(newtd, SRQ_BORING); | 238 if (rtp != NULL) { 239 if (!(td->td_pri_class == PRI_TIMESHARE && 240 rtp->type == RTP_PRIO_NORMAL)) { 241 rtp_to_pri(rtp, newtd); 242 sched_prio(newtd, newtd->td_user_pri); 243 } /* ignore timesharing class */ 244 } 245 TD_SET_CAN_RUN(newtd); 246 /* if ((flags & THR_SUSPENDED) == 0) */ 247 sched_add(newtd, SRQ_BORING); |
245 mtx_unlock_spin(&sched_lock); | 248 thread_unlock(newtd); |
246 247 return (error); 248} 249 250int 251thr_self(struct thread *td, struct thr_self_args *uap) 252 /* long *id */ 253{ --- 16 unchanged lines hidden (view full) --- 270 /* Signal userland that it can free the stack. */ 271 if ((void *)uap->state != NULL) { 272 suword_lwpid(uap->state, 1); 273 kern_umtx_wake(td, uap->state, INT_MAX); 274 } 275 276 PROC_LOCK(p); 277 sigqueue_flush(&td->td_sigqueue); | 249 250 return (error); 251} 252 253int 254thr_self(struct thread *td, struct thr_self_args *uap) 255 /* long *id */ 256{ --- 16 unchanged lines hidden (view full) --- 273 /* Signal userland that it can free the stack. */ 274 if ((void *)uap->state != NULL) { 275 suword_lwpid(uap->state, 1); 276 kern_umtx_wake(td, uap->state, INT_MAX); 277 } 278 279 PROC_LOCK(p); 280 sigqueue_flush(&td->td_sigqueue); |
278 mtx_lock_spin(&sched_lock); | 281 PROC_SLOCK(p); |
279 280 /* 281 * Shutting down last thread in the proc. This will actually 282 * call exit() in the trampoline when it returns. 283 */ 284 if (p->p_numthreads != 1) { 285 thread_stopped(p); 286 thread_exit(); 287 /* NOTREACHED */ 288 } | 282 283 /* 284 * Shutting down last thread in the proc. This will actually 285 * call exit() in the trampoline when it returns. 286 */ 287 if (p->p_numthreads != 1) { 288 thread_stopped(p); 289 thread_exit(); 290 /* NOTREACHED */ 291 } |
289 mtx_unlock_spin(&sched_lock); | 292 PROC_SUNLOCK(p); |
290 PROC_UNLOCK(p); 291 return (0); 292} 293 294int 295thr_kill(struct thread *td, struct thr_kill_args *uap) 296 /* long id, int sig */ 297{ --- 76 unchanged lines hidden (view full) --- 374 return (0); 375 } 376 377 PROC_LOCK(td->td_proc); 378 if ((td->td_flags & TDF_THRWAKEUP) == 0) 379 error = msleep((void *)td, &td->td_proc->p_mtx, PCATCH, "lthr", 380 hz); 381 if (td->td_flags & TDF_THRWAKEUP) { | 293 PROC_UNLOCK(p); 294 return (0); 295} 296 297int 298thr_kill(struct thread *td, struct thr_kill_args *uap) 299 /* long id, int sig */ 300{ --- 76 unchanged lines hidden (view full) --- 377 return (0); 378 } 379 380 PROC_LOCK(td->td_proc); 381 if ((td->td_flags & TDF_THRWAKEUP) == 0) 382 error = msleep((void *)td, &td->td_proc->p_mtx, PCATCH, "lthr", 383 hz); 384 if (td->td_flags & TDF_THRWAKEUP) { |
382 mtx_lock_spin(&sched_lock); | 385 thread_lock(td); |
383 td->td_flags &= ~TDF_THRWAKEUP; | 386 td->td_flags &= ~TDF_THRWAKEUP; |
384 mtx_unlock_spin(&sched_lock); | 387 thread_unlock(td); |
385 PROC_UNLOCK(td->td_proc); 386 return (0); 387 } 388 PROC_UNLOCK(td->td_proc); 389 if (error == EWOULDBLOCK) 390 error = ETIMEDOUT; 391 else if (error == ERESTART) { 392 if (hz != 0) --- 16 unchanged lines hidden (view full) --- 409 410 p = td->td_proc; 411 PROC_LOCK(p); 412 ttd = thread_find(p, uap->id); 413 if (ttd == NULL) { 414 PROC_UNLOCK(p); 415 return (ESRCH); 416 } | 388 PROC_UNLOCK(td->td_proc); 389 return (0); 390 } 391 PROC_UNLOCK(td->td_proc); 392 if (error == EWOULDBLOCK) 393 error = ETIMEDOUT; 394 else if (error == ERESTART) { 395 if (hz != 0) --- 16 unchanged lines hidden (view full) --- 412 413 p = td->td_proc; 414 PROC_LOCK(p); 415 ttd = thread_find(p, uap->id); 416 if (ttd == NULL) { 417 PROC_UNLOCK(p); 418 return (ESRCH); 419 } |
417 mtx_lock_spin(&sched_lock); | 420 thread_lock(ttd); |
418 ttd->td_flags |= TDF_THRWAKEUP; | 421 ttd->td_flags |= TDF_THRWAKEUP; |
419 mtx_unlock_spin(&sched_lock); | 422 thread_unlock(ttd); |
420 wakeup((void *)ttd); 421 PROC_UNLOCK(p); 422 return (0); 423} 424 425int 426thr_set_name(struct thread *td, struct thr_set_name_args *uap) 427{ --- 25 unchanged lines hidden --- | 423 wakeup((void *)ttd); 424 PROC_UNLOCK(p); 425 return (0); 426} 427 428int 429thr_set_name(struct thread *td, struct thr_set_name_args *uap) 430{ --- 25 unchanged lines hidden --- |