summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/alpha/include/spinlock.h12
-rw-r--r--sys/arch/amd64/include/spinlock.h12
-rw-r--r--sys/arch/arm/include/spinlock.h12
-rw-r--r--sys/arch/hppa/include/spinlock.h12
-rw-r--r--sys/arch/hppa64/include/spinlock.h12
-rw-r--r--sys/arch/i386/include/spinlock.h12
-rw-r--r--sys/arch/m68k/include/spinlock.h12
-rw-r--r--sys/arch/m88k/include/spinlock.h12
-rw-r--r--sys/arch/mips64/include/spinlock.h12
-rw-r--r--sys/arch/powerpc/include/spinlock.h12
-rw-r--r--sys/arch/sh/include/spinlock.h12
-rw-r--r--sys/arch/sparc/include/spinlock.h12
-rw-r--r--sys/arch/sparc64/include/spinlock.h12
-rw-r--r--sys/arch/vax/include/spinlock.h12
-rw-r--r--sys/kern/kern_synch.c48
15 files changed, 147 insertions, 69 deletions
diff --git a/sys/arch/alpha/include/spinlock.h b/sys/arch/alpha/include/spinlock.h
index 463ac57ddfb..688d5837e12 100644
--- a/sys/arch/alpha/include/spinlock.h
+++ b/sys/arch/alpha/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.1 1999/01/08 08:25:33 d Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/amd64/include/spinlock.h b/sys/arch/amd64/include/spinlock.h
index be9e806ff5e..688d5837e12 100644
--- a/sys/arch/amd64/include/spinlock.h
+++ b/sys/arch/amd64/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.1 2004/01/28 01:39:39 mickey Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/arm/include/spinlock.h b/sys/arch/arm/include/spinlock.h
index 5b68222836d..e8a52d59f17 100644
--- a/sys/arch/arm/include/spinlock.h
+++ b/sys/arch/arm/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.1 2004/02/01 05:09:49 drahn Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _ARM_SPINLOCK_H_
#define _ARM_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/hppa/include/spinlock.h b/sys/arch/hppa/include/spinlock.h
index a53dc35aa62..6ce31ca3e95 100644
--- a/sys/arch/hppa/include/spinlock.h
+++ b/sys/arch/hppa/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.3 2011/11/14 14:29:53 deraadt Exp $ */
+/* $OpenBSD: spinlock.h,v 1.4 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (1)
-#define _SPINLOCK_LOCKED (0)
-typedef long _spinlock_lock_t __attribute__((__aligned__(16)));
+#define _ATOMIC_LOCK_UNLOCKED (1)
+#define _ATOMIC_LOCK_LOCKED (0)
+typedef long _atomic_lock_t __attribute__((__aligned__(16)));
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/hppa64/include/spinlock.h b/sys/arch/hppa64/include/spinlock.h
index 613d06300df..24c3d89ff02 100644
--- a/sys/arch/hppa64/include/spinlock.h
+++ b/sys/arch/hppa64/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.2 2011/11/14 14:29:57 deraadt Exp $ */
+/* $OpenBSD: spinlock.h,v 1.3 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (1)
-#define _SPINLOCK_LOCKED (0)
-typedef long _spinlock_lock_t __attribute__((__aligned__(16)));
+#define _ATOMIC_LOCK_UNLOCKED (1)
+#define _ATOMIC_LOCK_LOCKED (0)
+typedef long _atomic_lock_t __attribute__((__aligned__(16)));
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/i386/include/spinlock.h b/sys/arch/i386/include/spinlock.h
index a245c351fd4..688d5837e12 100644
--- a/sys/arch/i386/include/spinlock.h
+++ b/sys/arch/i386/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.1 1999/01/08 08:25:34 d Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/m68k/include/spinlock.h b/sys/arch/m68k/include/spinlock.h
index 44d38732d2d..30ba8fbdb70 100644
--- a/sys/arch/m68k/include/spinlock.h
+++ b/sys/arch/m68k/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.2 1999/01/26 23:39:28 d Exp $ */
+/* $OpenBSD: spinlock.h,v 1.3 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _M68K_SPINLOCK_H_
#define _M68K_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/m88k/include/spinlock.h b/sys/arch/m88k/include/spinlock.h
index cce8d02ec4c..c4dfcedb5ba 100644
--- a/sys/arch/m88k/include/spinlock.h
+++ b/sys/arch/m88k/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.1 2004/04/26 12:34:05 miod Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _M88K_SPINLOCK_H_
#define _M88K_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/mips64/include/spinlock.h b/sys/arch/mips64/include/spinlock.h
index 87e9be5a768..766e8fd1523 100644
--- a/sys/arch/mips64/include/spinlock.h
+++ b/sys/arch/mips64/include/spinlock.h
@@ -1,11 +1,15 @@
-/* $OpenBSD: spinlock.h,v 1.3 2011/03/23 16:54:36 pirofti Exp $ */
+/* $OpenBSD: spinlock.h,v 1.4 2013/06/01 20:47:40 tedu Exp $ */
/* Public domain */
#ifndef _MIPS64_SPINLOCK_H_
#define _MIPS64_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif /* !_MIPS64_SPINLOCK_H_ */
diff --git a/sys/arch/powerpc/include/spinlock.h b/sys/arch/powerpc/include/spinlock.h
index 9058f266343..95a1271fd62 100644
--- a/sys/arch/powerpc/include/spinlock.h
+++ b/sys/arch/powerpc/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.2 2001/09/01 15:49:05 drahn Exp $ */
+/* $OpenBSD: spinlock.h,v 1.3 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _POWERPC_SPINLOCK_H_
#define _POWERPC_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/sh/include/spinlock.h b/sys/arch/sh/include/spinlock.h
index 5d8516aab3e..f35a7effd9d 100644
--- a/sys/arch/sh/include/spinlock.h
+++ b/sys/arch/sh/include/spinlock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: spinlock.h,v 1.3 2008/06/26 05:42:13 ray Exp $ */
+/* $OpenBSD: spinlock.h,v 1.4 2013/06/01 20:47:40 tedu Exp $ */
/* $NetBSD: lock.h,v 1.10 2006/01/03 01:29:46 uwe Exp $ */
/*-
@@ -37,9 +37,13 @@
#ifndef _SH_SPINLOCK_H_
#define _SH_SPINLOCK_H_
-typedef u_int8_t _spinlock_lock_t;
+typedef u_int8_t _atomic_lock_t;
-#define _SPINLOCK_LOCKED 0x80
-#define _SPINLOCK_UNLOCKED 0x00
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
+
+#define _ATOMIC_LOCK_LOCKED 0x80
+#define _ATOMIC_LOCK_UNLOCKED 0x00
#endif /* !_SH_SPINLOCK_H_ */
diff --git a/sys/arch/sparc/include/spinlock.h b/sys/arch/sparc/include/spinlock.h
index 0a4519f2db9..432d8459edc 100644
--- a/sys/arch/sparc/include/spinlock.h
+++ b/sys/arch/sparc/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.2 1999/02/07 23:50:59 d Exp $ */
+/* $OpenBSD: spinlock.h,v 1.3 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0x00)
-#define _SPINLOCK_LOCKED (0xFF)
-typedef unsigned char _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0x00)
+#define _ATOMIC_LOCK_LOCKED (0xFF)
+typedef unsigned char _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/sparc64/include/spinlock.h b/sys/arch/sparc64/include/spinlock.h
index e237ff88803..89a19f128d0 100644
--- a/sys/arch/sparc64/include/spinlock.h
+++ b/sys/arch/sparc64/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.1 2001/09/10 20:00:14 jason Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0x00)
-#define _SPINLOCK_LOCKED (0xFF)
-typedef unsigned char _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0x00)
+#define _ATOMIC_LOCK_LOCKED (0xFF)
+typedef unsigned char _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/arch/vax/include/spinlock.h b/sys/arch/vax/include/spinlock.h
index 7c38641bc01..b050c25e885 100644
--- a/sys/arch/vax/include/spinlock.h
+++ b/sys/arch/vax/include/spinlock.h
@@ -1,10 +1,14 @@
-/* $OpenBSD: spinlock.h,v 1.2 2002/11/01 20:15:03 miod Exp $ */
+/* $OpenBSD: spinlock.h,v 1.3 2013/06/01 20:47:40 tedu Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
-#define _SPINLOCK_UNLOCKED (0)
-#define _SPINLOCK_LOCKED (1)
-typedef int _spinlock_lock_t;
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#ifndef _KERNEL
+int _atomic_lock(volatile _atomic_lock_t *);
+#endif
#endif
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index ebbdcc70f05..0f5cdf1d33c 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.105 2013/04/06 03:44:34 tedu Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.106 2013/06/01 20:47:40 tedu Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@@ -393,6 +393,31 @@ sys_sched_yield(struct proc *p, void *v, register_t *retval)
return (0);
}
+int thrsleep_unlock(void *, int);
+int
+thrsleep_unlock(void *lock, int lockflags)
+{
+ static _atomic_lock_t unlocked = _ATOMIC_LOCK_UNLOCKED;
+ _atomic_lock_t *atomiclock = lock;
+ uint32_t *ticket = lock;
+ uint32_t ticketvalue;
+ int error;
+
+ if (!lock)
+ return (0);
+
+ if (lockflags) {
+ if ((error = copyin(ticket, &ticketvalue, sizeof(ticketvalue))))
+ return (error);
+ ticketvalue++;
+ error = copyout(&ticketvalue, ticket, sizeof(ticketvalue));
+ } else {
+ error = copyout(&unlocked, atomiclock, sizeof(unlocked));
+ }
+ return (error);
+}
+
+
int
sys___thrsleep(struct proc *p, void *v, register_t *retval)
{
@@ -404,10 +429,11 @@ sys___thrsleep(struct proc *p, void *v, register_t *retval)
syscallarg(const int *) abort;
} */ *uap = v;
long ident = (long)SCARG(uap, ident);
- _spinlock_lock_t *lock = SCARG(uap, lock);
- static _spinlock_lock_t unlocked = _SPINLOCK_UNLOCKED;
+ void *lock = SCARG(uap, lock);
long long to_ticks = 0;
int abort, error;
+ clockid_t clock_id = SCARG(uap, clock_id) & 0x7;
+ int lockflags = SCARG(uap, clock_id) & 0x8;
if (ident == 0) {
*retval = EINVAL;
@@ -417,7 +443,7 @@ sys___thrsleep(struct proc *p, void *v, register_t *retval)
struct timespec now, ats;
if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) ||
- (error = clock_gettime(p, SCARG(uap, clock_id), &now))) {
+ (error = clock_gettime(p, clock_id, &now))) {
*retval = error;
return (0);
}
@@ -428,12 +454,9 @@ sys___thrsleep(struct proc *p, void *v, register_t *retval)
if (timespeccmp(&ats, &now, <)) {
/* already passed: still do the unlock */
- if (lock) {
- if ((error = copyout(&unlocked, lock,
- sizeof(unlocked))) != 0) {
- *retval = error;
- return (0);
- }
+ if ((error = thrsleep_unlock(lock, lockflags))) {
+ *retval = error;
+ return (0);
}
*retval = EWOULDBLOCK;
return (0);
@@ -448,9 +471,8 @@ sys___thrsleep(struct proc *p, void *v, register_t *retval)
p->p_thrslpid = ident;
- if (lock) {
- if ((error = copyout(&unlocked, lock, sizeof(unlocked))) != 0)
- goto out;
+ if ((error = thrsleep_unlock(lock, lockflags))) {
+ goto out;
}
if (SCARG(uap, abort) != NULL) {