diff options
| author | John Birrell <jb@FreeBSD.org> | 1999-03-23 05:07:56 +0000 | 
|---|---|---|
| committer | John Birrell <jb@FreeBSD.org> | 1999-03-23 05:07:56 +0000 | 
| commit | 58a7cc5d1be640708d2c5e05bf48a8ae379a8d3e (patch) | |
| tree | eea0761f32968ad5456e1c13f86e990df50fa554 /lib/libpthread/thread/thr_spinlock.c | |
| parent | f5a78334492dccb1f3e9debe40f6e1deb14638fd (diff) | |
Notes
Diffstat (limited to 'lib/libpthread/thread/thr_spinlock.c')
| -rw-r--r-- | lib/libpthread/thread/thr_spinlock.c | 32 | 
1 files changed, 15 insertions, 17 deletions
diff --git a/lib/libpthread/thread/thr_spinlock.c b/lib/libpthread/thread/thr_spinlock.c index 9da115e5eedb..4da3f8c1a443 100644 --- a/lib/libpthread/thread/thr_spinlock.c +++ b/lib/libpthread/thread/thr_spinlock.c @@ -29,7 +29,7 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id: uthread_spinlock.c,v 1.3 1998/06/06 07:27:06 jb Exp $ + * $Id: uthread_spinlock.c,v 1.4 1998/06/09 23:13:10 jb Exp $   *   */ @@ -56,12 +56,9 @@ _spinlock(spinlock_t *lck)  	 * it before we do.  	 */  	while(_atomic_lock(&lck->access_lock)) { -		/* Give up the time slice: */ -		sched_yield(); - -		/* Check if already locked by the running thread: */ -		if (lck->lock_owner == (long) _thread_run) -			return; +		/* Block the thread until the lock. */ +		_thread_run->data.spinlock = lck; +		_thread_kern_sched_state(PS_SPINBLOCK, __FILE__, __LINE__);  	}  	/* The running thread now owns the lock: */ @@ -81,24 +78,25 @@ _spinlock(spinlock_t *lck)  void  _spinlock_debug(spinlock_t *lck, char *fname, int lineno)  { +	int cnt = 0; +  	/*  	 * Try to grab the lock and loop if another thread grabs  	 * it before we do.  	 */  	while(_atomic_lock(&lck->access_lock)) { -		/* Give up the time slice: */ -		sched_yield(); - -		/* Check if already locked by the running thread: */ -		if (lck->lock_owner == (long) _thread_run) { +		cnt++; +		if (cnt > 100) {  			char str[256]; -			snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) which it had already locked in %s (%d)\n", __progname, _thread_run, lck, fname, lineno, lck->fname, lck->lineno); +			snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, _thread_run, lck, fname, lineno, lck->fname, lck->lineno);  			_thread_sys_write(2,str,strlen(str)); - -			/* Create a thread dump to help debug this problem: */ -			_thread_dump_info(); -			return; +			sleep(1); +			cnt = 0;  		} + +		/* Block the thread until the lock. */ +		_thread_run->data.spinlock = lck; +		_thread_kern_sched_state(PS_SPINBLOCK, fname, lineno);  	}  	/* The running thread now owns the lock: */  | 
