summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorPaul Irofti <pirofti@cvs.openbsd.org>2012-05-03 09:07:18 +0000
committerPaul Irofti <pirofti@cvs.openbsd.org>2012-05-03 09:07:18 +0000
commite80bf7425576ea69b4d12d80cc8031bf730710f4 (patch)
treeb02022cfbc8a1d7b25b2235814ab4049039afe16 /regress
parentac991706e149d4917b8169f9cf03311896fb2f30 (diff)
Add pthread spinlock support.
Implementation, documentation and naive regression tests for: - pthread_spin_init() - pthread_spin_destroy() - pthread_spin_lock() - pthread_spin_trylock() - pthread_spin_unlock() Implementation okay guenther@, documentation okay jmc@.
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libpthread/Makefile4
-rw-r--r--regress/lib/libpthread/spinlock/Makefile5
-rw-r--r--regress/lib/libpthread/spinlock/spinlock.c50
3 files changed, 57 insertions, 2 deletions
diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile
index 8b5f85d70de..5d42f1ef5cc 100644
--- a/regress/lib/libpthread/Makefile
+++ b/regress/lib/libpthread/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.38 2012/04/13 19:04:09 kurt Exp $
+# $OpenBSD: Makefile,v 1.39 2012/05/03 09:07:17 pirofti Exp $
# disabled because it requires a buggy behavior that uthread had:
# dup2_race
@@ -11,7 +11,7 @@ SUBDIR= barrier blocked_close blocked_dup2 blocked_fifo blocked_shutdown \
pthread_rwlock pthread_specific \
readdir restart select semaphore setjmp setsockopt sigdeliver siginfo \
siginterrupt signal signals signodefer sigsuspend sigwait sleep \
- socket stack stdarg stdio switch system
+ socket spinlock stack stdarg stdio switch system
# Not available or disabled: fcntl, getaddrinfo, pause, pw, sigmask, stdfiles
diff --git a/regress/lib/libpthread/spinlock/Makefile b/regress/lib/libpthread/spinlock/Makefile
new file mode 100644
index 00000000000..0c029e43dc0
--- /dev/null
+++ b/regress/lib/libpthread/spinlock/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2012/05/03 09:07:17 pirofti Exp $
+
+PROG= spinlock
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/spinlock/spinlock.c b/regress/lib/libpthread/spinlock/spinlock.c
new file mode 100644
index 00000000000..dadfe14d1f0
--- /dev/null
+++ b/regress/lib/libpthread/spinlock/spinlock.c
@@ -0,0 +1,50 @@
+/* $OpenBSD: spinlock.c,v 1.1 2012/05/03 09:07:17 pirofti Exp $ */
+/* Paul Irofti <pirofti@openbsd.org>, 2012. Public Domain. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <errno.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include "test.h"
+
+void *
+foo(void *arg)
+{
+ int rc = 0;
+ pthread_spinlock_t l = (pthread_spinlock_t)arg;
+ rc = pthread_spin_trylock(&l);
+ if (rc != 0 && rc != EBUSY) {
+ PANIC("pthread_trylock returned %d", rc);
+ }
+ if (rc == 0) {
+ CHECKr(pthread_spin_unlock(&l));
+ }
+ CHECKr(pthread_spin_lock(&l));
+ CHECKr(pthread_spin_unlock(&l));
+ return NULL;
+}
+
+int main()
+{
+ int i;
+ pthread_t thr[10];
+ pthread_spinlock_t l;
+
+ _CHECK(pthread_spin_init(&l, PTHREAD_PROCESS_SHARED), == ENOTSUP,
+ strerror(_x));
+
+ CHECKr(pthread_spin_init(&l, PTHREAD_PROCESS_PRIVATE));
+ for (i = 0; i < 10; i++) {
+ printf("Thread %d started\n", i);
+ CHECKr(pthread_create(&thr[i], NULL, foo, (void *)l));
+ }
+ for (i = 0; i < 10; i++) {
+ CHECKr(pthread_join(thr[i], NULL));
+ }
+ CHECKr(pthread_spin_destroy(&l));
+
+ SUCCEED;
+}