diff options
author | John Birrell <jb@FreeBSD.org> | 1998-06-06 07:27:06 +0000 |
---|---|---|
committer | John Birrell <jb@FreeBSD.org> | 1998-06-06 07:27:06 +0000 |
commit | 2d8a580416ad72ecd6638affdb949d8cdba6fadc (patch) | |
tree | e8ee06cc75580c7d80460f94b7293211d87895a9 /lib/libc_r/uthread | |
parent | c6831395f47e99ed4db1a41f680ca1c0177682a9 (diff) | |
download | src-2d8a580416ad72ecd6638affdb949d8cdba6fadc.tar.gz src-2d8a580416ad72ecd6638affdb949d8cdba6fadc.zip |
Add a warning message for a thread locking against itself. This is
not supposed to happen, but I have seen bogus g++ code that causes
it.
Notes
Notes:
svn path=/head/; revision=36698
Diffstat (limited to 'lib/libc_r/uthread')
-rw-r--r-- | lib/libc_r/uthread/uthread_spinlock.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/libc_r/uthread/uthread_spinlock.c b/lib/libc_r/uthread/uthread_spinlock.c index 27e2219f79ee..01c29bdd12da 100644 --- a/lib/libc_r/uthread/uthread_spinlock.c +++ b/lib/libc_r/uthread/uthread_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.1 1998/04/29 09:59:28 jb Exp $ + * $Id: uthread_spinlock.c,v 1.2 1998/05/05 21:47:58 jb Exp $ * */ @@ -37,6 +37,7 @@ #include <sched.h> #include <unistd.h> #include <pthread.h> +#include <string.h> #include "spinlock.h" #include "pthread_private.h" @@ -47,15 +48,25 @@ * assumes that the lock will be available very soon. */ void -_spinlock(volatile long *lck) +_spinlock(volatile long * volatile lck) { do { /* * Allow other threads to run if the lock is not * available: */ - while (*lck != 0) + while (*lck != 0) { + /* Check if already locked by the running thread: */ + if (*lck == (long) _thread_run) { + char str[40]; + snprintf(str,sizeof(str),"Warning: Thread %p attempted to lock %p which it had already locked!\n",_thread_run,lck); + _thread_sys_write(2,str,strlen(str)); + return; + } + + /* Give up the time slice: */ sched_yield(); + } /* * Try to grab the lock and loop if another thread grabs |