Date: Sat, 20 Nov 2004 05:06:42 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 65528 for review Message-ID: <200411200506.iAK56gqn013684@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=65528 Change 65528 by davidxu@davidxu_alona on 2004/11/20 05:05:45 use umtx lock. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_pspinlock.c#2 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_pspinlock.c#2 (text+ko) ==== @@ -29,7 +29,6 @@ #include <errno.h> #include <stdlib.h> #include <pthread.h> -#include <atomic_ops.h> #include "thr_private.h" #define SPIN_COUNT 10000 @@ -51,8 +50,7 @@ else if ((lck = malloc(sizeof(struct pthread_spinlock))) == NULL) ret = ENOMEM; else { - lck->s_lock = 0; - lck->s_owner= NULL; + _lock_init(&lck->s_lock); *lock = lck; ret = 0; } @@ -67,9 +65,8 @@ if (lock == NULL || *lock == NULL) ret = EINVAL; - else if ((*lock)->s_owner != NULL) - ret = EBUSY; else { + _lock_destroy(&(*lock)->s_lock); free(*lock); *lock = NULL; ret = 0; @@ -83,23 +80,12 @@ { struct pthread_spinlock *lck; struct pthread *self = _pthread_self(); - int oldval, ret; + int ret; if (lock == NULL || (lck = *lock) == NULL) ret = EINVAL; - else if (lck->s_owner == self) - ret = EDEADLK; - else if (lck->s_lock != 0) - ret = EBUSY; - else { - atomic_swap_int((int *)&(lck)->s_lock, 1, &oldval); - if (oldval) - ret = EBUSY; - else { - lck->s_owner = _pthread_self(); - ret = 0; - } - } + else + ret = _lock_trylock(&lck->s_lock, self->tid); return (ret); } @@ -108,30 +94,20 @@ { struct pthread_spinlock *lck; struct pthread *self = _pthread_self(); - int count, oldval, ret; + int ret, count; if (lock == NULL || (lck = *lock) == NULL) ret = EINVAL; - else if (lck->s_owner == self) - ret = EDEADLK; else { - do { - count = SPIN_COUNT; - while (lck->s_lock) { -#ifdef __i386__ - /* tell cpu we are spinning */ - __asm __volatile("pause"); -#endif - if (--count <= 0) { - count = SPIN_COUNT; - _pthread_yield(); - } + count = SPIN_COUNT; + while ((ret = _lock_trylock(&lck->s_lock, self->tid)) != 0) { + if (ret != EINTR && ret != EAGAIN && ret != EBUSY) + break; + if (--count <= 0) { + count = SPIN_COUNT; + _pthread_yield(); } - atomic_swap_int((int *)&(lck)->s_lock, 1, &oldval); - } while (oldval); - - lck->s_owner = self; - ret = 0; + } } return (ret); @@ -141,20 +117,14 @@ _pthread_spin_unlock(pthread_spinlock_t *lock) { struct pthread_spinlock *lck; + struct pthread *self = _pthread_self(); int ret; if (lock == NULL || (lck = *lock) == NULL) ret = EINVAL; else { - if (lck->s_owner != _pthread_self()) - ret = EPERM; - else { - lck->s_owner = NULL; - atomic_swap_int((int *)&lck->s_lock, 0, &ret); - ret = 0; - } + _lock_release(&lck->s_lock, self->tid); + ret = 0; } - return (ret); } -
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411200506.iAK56gqn013684>