summaryrefslogtreecommitdiff
path: root/components/pthreads/pthread_spin.c
diff options
context:
space:
mode:
author[email protected] <[email protected]>2010-11-15 00:25:37 +0000
committer[email protected] <[email protected]>2010-11-15 00:25:37 +0000
commit468db501592d68a3576a42cc42e2c7c7fb527b8d (patch)
tree9cde7754f5147ecccfb013528cf8bf1a85eef60d /components/pthreads/pthread_spin.c
parent45461f8afe87d96c3bdb5fe26c94c323dff1452d (diff)
update pthreads components.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1046 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/pthreads/pthread_spin.c')
-rw-r--r--components/pthreads/pthread_spin.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/components/pthreads/pthread_spin.c b/components/pthreads/pthread_spin.c
index 4332ec1db8..c38c611616 100644
--- a/components/pthreads/pthread_spin.c
+++ b/components/pthreads/pthread_spin.c
@@ -2,25 +2,50 @@
int pthread_spin_init (pthread_spinlock_t *lock, int pshared)
{
+ if (!lock) return EINVAL;
+
+ lock->lock = 0;
return 0;
}
int pthread_spin_destroy (pthread_spinlock_t *lock)
{
+ if (!lock) return EINVAL;
+
return 0;
}
-int pthread_spin_lock (pthread_spinlock_t * lock)
+int pthread_spin_lock (pthread_spinlock_t *lock)
{
+ if (!lock) return EINVAL;
+
+ while (!(lock->lock))
+ {
+ lock->lock = 1;
+ }
+
return 0;
}
-int pthread_spin_trylock (pthread_spinlock_t * lock)
+int pthread_spin_trylock (pthread_spinlock_t *lock)
{
- return 0;
+ if (!lock) return EINVAL;
+
+ if (!(lock->lock))
+ {
+ lock->lock = 1;
+ return 0;
+ }
+
+ return EBUSY;
}
-int pthread_spin_unlock (pthread_spinlock_t * lock)
+int pthread_spin_unlock (pthread_spinlock_t *lock)
{
+ if (!lock) return EINVAL;
+ if (!(lock->lock)) return EPERM;
+
+ lock->lock = 0;
+
return 0;
}