kern_mutex.c (131473) | kern_mutex.c (131481) |
---|---|
1/*- 2 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 20 unchanged lines hidden (view full) --- 29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ 30 */ 31 32/* 33 * Machine independent bits of mutex implementation. 34 */ 35 36#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 20 unchanged lines hidden (view full) --- 29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ 30 */ 31 32/* 33 * Machine independent bits of mutex implementation. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 131473 2004-07-02 19:09:50Z jhb $"); | 37__FBSDID("$FreeBSD: head/sys/kern/kern_mutex.c 131481 2004-07-02 20:21:44Z jhb $"); |
38 39#include "opt_adaptive_mutexes.h" 40#include "opt_ddb.h" 41#include "opt_mutex_wake_all.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/bus.h> --- 570 unchanged lines hidden (view full) --- 616 * 617 * We are only called here if the lock is recursed or contested (i.e. we 618 * need to wake up a blocked thread). 619 */ 620void 621_mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line) 622{ 623 struct turnstile *ts; | 38 39#include "opt_adaptive_mutexes.h" 40#include "opt_ddb.h" 41#include "opt_mutex_wake_all.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/bus.h> --- 570 unchanged lines hidden (view full) --- 616 * 617 * We are only called here if the lock is recursed or contested (i.e. we 618 * need to wake up a blocked thread). 619 */ 620void 621_mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line) 622{ 623 struct turnstile *ts; |
624#ifndef PREEMPTION |
|
624 struct thread *td, *td1; | 625 struct thread *td, *td1; |
626#endif |
|
625 626 if (mtx_recursed(m)) { 627 if (--(m->mtx_recurse) == 0) 628 atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED); 629 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 630 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p unrecurse", m); 631 return; 632 } --- 8 unchanged lines hidden (view full) --- 641 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 642 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p no sleepers", m); 643 turnstile_release(&m->mtx_object); 644 return; 645 } 646#else 647 MPASS(ts != NULL); 648#endif | 627 628 if (mtx_recursed(m)) { 629 if (--(m->mtx_recurse) == 0) 630 atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED); 631 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 632 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p unrecurse", m); 633 return; 634 } --- 8 unchanged lines hidden (view full) --- 643 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 644 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p no sleepers", m); 645 turnstile_release(&m->mtx_object); 646 return; 647 } 648#else 649 MPASS(ts != NULL); 650#endif |
651#ifndef PREEMPTION |
|
649 /* XXX */ 650 td1 = turnstile_head(ts); | 652 /* XXX */ 653 td1 = turnstile_head(ts); |
654#endif |
|
651#ifdef MUTEX_WAKE_ALL 652 turnstile_broadcast(ts); 653 _release_lock_quick(m); 654#else 655 if (turnstile_signal(ts)) { 656 _release_lock_quick(m); 657 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 658 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p not held", m); 659 } else { 660 m->mtx_lock = MTX_CONTESTED; 661 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 662 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p still contested", 663 m); 664 } 665#endif 666 turnstile_unpend(ts); 667 | 655#ifdef MUTEX_WAKE_ALL 656 turnstile_broadcast(ts); 657 _release_lock_quick(m); 658#else 659 if (turnstile_signal(ts)) { 660 _release_lock_quick(m); 661 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 662 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p not held", m); 663 } else { 664 m->mtx_lock = MTX_CONTESTED; 665 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 666 CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p still contested", 667 m); 668 } 669#endif 670 turnstile_unpend(ts); 671 |
672#ifndef PREEMPTION |
|
668 /* 669 * XXX: This is just a hack until preemption is done. However, 670 * once preemption is done we need to either wrap the 671 * turnstile_signal() and release of the actual lock in an 672 * extra critical section or change the preemption code to 673 * always just set a flag and never do instant-preempts. 674 */ 675 td = curthread; --- 20 unchanged lines hidden (view full) --- 696 (void *)m->mtx_lock); 697 698 mi_switch(SW_INVOL, NULL); 699 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 700 CTR2(KTR_LOCK, "_mtx_unlock_sleep: %p resuming lock=%p", 701 m, (void *)m->mtx_lock); 702 } 703 mtx_unlock_spin(&sched_lock); | 673 /* 674 * XXX: This is just a hack until preemption is done. However, 675 * once preemption is done we need to either wrap the 676 * turnstile_signal() and release of the actual lock in an 677 * extra critical section or change the preemption code to 678 * always just set a flag and never do instant-preempts. 679 */ 680 td = curthread; --- 20 unchanged lines hidden (view full) --- 701 (void *)m->mtx_lock); 702 703 mi_switch(SW_INVOL, NULL); 704 if (LOCK_LOG_TEST(&m->mtx_object, opts)) 705 CTR2(KTR_LOCK, "_mtx_unlock_sleep: %p resuming lock=%p", 706 m, (void *)m->mtx_lock); 707 } 708 mtx_unlock_spin(&sched_lock); |
709#endif |
|
704 705 return; 706} 707 708/* 709 * All the unlocking of MTX_SPIN locks is done inline. 710 * See the _rel_spin_lock() macro for the details. 711 */ --- 179 unchanged lines hidden --- | 710 711 return; 712} 713 714/* 715 * All the unlocking of MTX_SPIN locks is done inline. 716 * See the _rel_spin_lock() macro for the details. 717 */ --- 179 unchanged lines hidden --- |