summaryrefslogtreecommitdiffstats
path: root/lib/libc_r/uthread/uthread_spinlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc_r/uthread/uthread_spinlock.c')
-rw-r--r--lib/libc_r/uthread/uthread_spinlock.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/lib/libc_r/uthread/uthread_spinlock.c b/lib/libc_r/uthread/uthread_spinlock.c
index 9da115e..4da3f8c 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.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: */
OpenPOWER on IntegriCloud