summaryrefslogtreecommitdiffstats
path: root/lib/libc_r
diff options
context:
space:
mode:
authorjb <jb@FreeBSD.org>1998-06-06 07:27:06 +0000
committerjb <jb@FreeBSD.org>1998-06-06 07:27:06 +0000
commitd9ca3f69e656b094714e0e91d1a1b893f9af3445 (patch)
treeec1dd3eb20b1c347dd769f4dca4d25ffe0d022b3 /lib/libc_r
parentfa1af3c55b714cb0c83c88b0136e3b5038e4496c (diff)
downloadFreeBSD-src-d9ca3f69e656b094714e0e91d1a1b893f9af3445.zip
FreeBSD-src-d9ca3f69e656b094714e0e91d1a1b893f9af3445.tar.gz
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.
Diffstat (limited to 'lib/libc_r')
-rw-r--r--lib/libc_r/uthread/uthread_spinlock.c17
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 27e2219..01c29bd 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
OpenPOWER on IntegriCloud