diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-09-01 00:32:25 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-09-01 00:32:25 +0000 |
commit | 1526394b06893bd355c5a7261041969a34e2796e (patch) | |
tree | 2efd20c0136e66623513b5de255e772c04871617 /lib/libpthread | |
parent | 495e89e19983b1ff079c2bf298d975639f9d5d99 (diff) |
So passes uthreads
Like autumn leaves on water
don't fear the tedu@
Diffstat (limited to 'lib/libpthread')
199 files changed, 0 insertions, 21836 deletions
diff --git a/lib/libpthread/arch/alpha/uthread_machdep.c b/lib/libpthread/arch/alpha/uthread_machdep.c deleted file mode 100644 index fa9c604d06f..00000000000 --- a/lib/libpthread/arch/alpha/uthread_machdep.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.2 2002/05/10 10:17:22 art Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Machine-dependent thread state functions for OpenBSD/alpha - */ - -#include <pthread.h> -#include "pthread_private.h" - -#define ALIGNBYTES 15 - -struct frame { - long ra; - long s[7]; - long t12; - long fs[8]; -}; - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - - f = (struct frame *)(((u_int64_t)base + len - sizeof *f) & ~ALIGNBYTES); - f->ra = f->t12 = (u_int64_t)entry; - - statep->sp = (u_int64_t)f; -} - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ -} diff --git a/lib/libpthread/arch/alpha/uthread_machdep.h b/lib/libpthread/arch/alpha/uthread_machdep.h deleted file mode 100644 index 9bd580d5f1c..00000000000 --- a/lib/libpthread/arch/alpha/uthread_machdep.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.8 2002/01/04 14:46:18 art Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -struct _machdep_state { - u_int64_t sp; -}; diff --git a/lib/libpthread/arch/alpha/uthread_machdep_asm.S b/lib/libpthread/arch/alpha/uthread_machdep_asm.S deleted file mode 100644 index 054d8a52d22..00000000000 --- a/lib/libpthread/arch/alpha/uthread_machdep_asm.S +++ /dev/null @@ -1,79 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.4 2002/12/12 18:26:18 marc Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> - -#define INTOFF(n) ((n)*8) -#define FPOFF(n) (INTOFF(9) + (n)*8) -#define ALIGN(x) (((x)+15)&~15) -#define FRAMESIZE ALIGN(FPOFF(8)) - - .set noreorder - .globl _thread_machdep_switch - .ent _thread_machdep_switch, 2 -_thread_machdep_switch: - .frame sp, FRAMESIZE, ra - ldgp gp, 0(pv) - lda sp, -FRAMESIZE(sp) - - stq ra, INTOFF(0)(sp) - stq s0, INTOFF(1)(sp) - stq s1, INTOFF(2)(sp) - stq s2, INTOFF(3)(sp) - stq s3, INTOFF(4)(sp) - stq s4, INTOFF(5)(sp) - stq s5, INTOFF(6)(sp) - stq s6, INTOFF(7)(sp) - stq t12, INTOFF(8)(sp) - - stt fs0, FPOFF(0)(sp) - stt fs1, FPOFF(1)(sp) - stt fs2, FPOFF(2)(sp) - stt fs3, FPOFF(3)(sp) - stt fs4, FPOFF(4)(sp) - stt fs5, FPOFF(5)(sp) - stt fs6, FPOFF(6)(sp) - stt fs7, FPOFF(7)(sp) - - stq sp, 0(a1) - or a0, zero, pv - ldq sp, 0(a0) - - ldt fs7, FPOFF(7)(sp) - ldt fs6, FPOFF(6)(sp) - ldt fs5, FPOFF(5)(sp) - ldt fs4, FPOFF(4)(sp) - ldt fs3, FPOFF(3)(sp) - ldt fs2, FPOFF(2)(sp) - ldt fs1, FPOFF(1)(sp) - ldt fs0, FPOFF(0)(sp) - - ldq t12, INTOFF(8)(sp) - ldq s6, INTOFF(7)(sp) - ldq s5, INTOFF(6)(sp) - ldq s4, INTOFF(5)(sp) - ldq s3, INTOFF(4)(sp) - ldq s2, INTOFF(3)(sp) - ldq s1, INTOFF(2)(sp) - ldq s0, INTOFF(1)(sp) - ldq ra, INTOFF(0)(sp) - - lda sp,FRAMESIZE(sp) - RET - - .end _thread_machdep_switch - -LEAF(_atomic_lock,1) - LDGP(pv) - - /* NOTE: using ldl_l/stl_c instead of - ldq_l and ldq_c as machine/spinlock.h - defines _spinlock_lock_t as int */ -0: ldl_l v0, 0(a0) /* read existing lock value */ - mov 1, t0 /* locked value to store */ - stl_c t0, 0(a0) /* attempt to store, status in t0 */ - beq t0, 1f /* branch forward to optimise prediction */ - mb /* sync with other processors */ - RET /* return with v0==0 if lock obtained */ -1: br 0b /* loop to try again */ -END(_atomic_lock) diff --git a/lib/libpthread/arch/amd64/_atomic_lock.c b/lib/libpthread/arch/amd64/_atomic_lock.c deleted file mode 100644 index e2cadd6f26a..00000000000 --- a/lib/libpthread/arch/amd64/_atomic_lock.c +++ /dev/null @@ -1,26 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.4 2009/06/01 22:52:38 guenther Exp $ */ - -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Atomic lock for amd64 -- taken from i386 code. - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - /* - * Use the eXCHanGe instruction to swap the lock value with - * a local variable containing the locked state. - */ - old = _SPINLOCK_LOCKED; - __asm__("xchg %0,(%2)" - : "=r" (old) - : "0" (old), "r" (lock)); - - return (old != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/amd64/uthread_machdep.c b/lib/libpthread/arch/amd64/uthread_machdep.c deleted file mode 100644 index 29a8de00718..00000000000 --- a/lib/libpthread/arch/amd64/uthread_machdep.c +++ /dev/null @@ -1,108 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.5 2011/01/04 05:34:09 guenther Exp $ */ - -/* - * Copyright (c) 2004 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include <machine/param.h> -#include <pthread.h> -#include "pthread_private.h" - -struct frame { - long fr_gs; - long fr_fs; - long fr_es; - long fr_ds; - - long flag; - long fr_r15; - long fr_r14; - long fr_r13; - long fr_r12; - - long fr_r11; - long fr_r10; - long fr_r9; - long fr_r8; - - long fr_rdi; - long fr_rsi; - long fr_rbp; - - long fr_rbx; - long fr_rdx; - long fr_rcx; - long fr_rax; - - long fr_rip; - int fr_cs; /* XXX unreachable? */ - int pad; -}; - -#define copyreg(reg, lval) \ - __asm__("mov %%" #reg ", %0" : "=g"(lval)) - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(struct _machdep_state* statep, void *base, int len, - void (*entry)(void)) -{ - struct frame *f; - int foo; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((long)base + len - sizeof *f) & ~ALIGNBYTES); - - copyreg(cs, foo); - f->fr_cs = foo; - copyreg(ds, foo); - f->fr_ds = foo; - copyreg(es, foo); - f->fr_es = foo; - copyreg(fs, foo); - f->fr_fs = foo; - copyreg(gs, foo); - f->fr_gs = foo; - - f->fr_rbp = (long)-1; - f->fr_rip = (long)entry; - - statep->rsp = (long)f; - - _thread_machdep_save_float_state(statep); -} - -#define fxsave(addr) __asm("fxsave %0" : "=m" (*addr)) -#define fxrstor(addr) __asm("fxrstor %0" : : "m" (*addr)) -#define fwait() __asm("fwait") -#define fninit() __asm("fninit") - -void -_thread_machdep_save_float_state(struct _machdep_state *ms) -{ - fxsave(&ms->fpreg); - fninit(); - fwait(); -} - -void -_thread_machdep_restore_float_state(struct _machdep_state *ms) -{ - fxrstor(&ms->fpreg); -} diff --git a/lib/libpthread/arch/amd64/uthread_machdep.h b/lib/libpthread/arch/amd64/uthread_machdep.h deleted file mode 100644 index 34532db8b48..00000000000 --- a/lib/libpthread/arch/amd64/uthread_machdep.h +++ /dev/null @@ -1,26 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.3 2004/02/25 04:10:53 deraadt Exp $ */ - -/* - * Copyright (c) 2004 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/types.h> -#include <machine/fpu.h> - -struct _machdep_state { - long rsp; - /* must be 128-bit aligned */ - struct savefpu fpreg __attribute__ ((aligned (16))); -}; diff --git a/lib/libpthread/arch/amd64/uthread_machdep_asm.S b/lib/libpthread/arch/amd64/uthread_machdep_asm.S deleted file mode 100644 index 818d157de93..00000000000 --- a/lib/libpthread/arch/amd64/uthread_machdep_asm.S +++ /dev/null @@ -1,88 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.3 2004/02/25 04:10:53 deraadt Exp $ */ - -/* - * Copyright (c) 2004 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <machine/asm.h> - -/* - * Switch stacks - */ - -/* void _thread_machdep_switch(new, oldsave); */ -ENTRY(_thread_machdep_switch) - pushq %rax - pushq %rcx - pushq %rdx - pushq %rbx - - pushq %rbp - pushq %rsi - pushq %rdi - - pushq %r8 - pushq %r9 - pushq %r10 - pushq %r11 - - pushq %r12 - pushq %r13 - pushq %r14 - pushq %r15 - movq $0xdeaf12345678beaf, %r15 - pushq %r15 - - movl %ds,%eax - pushq %rax - movl %es,%eax - pushq %rax - movl %fs,%eax - pushq %rax - movl %gs,%eax - pushq %rax - - movq %rsp, 0(%rsi) /* *arg2 = %rsp */ - movq 0(%rdi), %rsp /* %rsp = *arg1 */ - - popq %rax - movl %eax,%gs - popq %rax - movl %eax,%fs - popq %rax - movl %eax,%es - popq %rax - movl %eax,%ds - - popq %r15 # flag word. - popq %r15 - popq %r14 - popq %r13 - popq %r12 - - popq %r11 - popq %r10 - popq %r9 - popq %r8 - - popq %rdi - popq %rsi - popq %rbp - - popq %rbx - popq %rdx - popq %rcx - popq %rax - ret diff --git a/lib/libpthread/arch/arm/_atomic_lock.c b/lib/libpthread/arch/arm/_atomic_lock.c deleted file mode 100644 index 94637a13b74..00000000000 --- a/lib/libpthread/arch/arm/_atomic_lock.c +++ /dev/null @@ -1,43 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.2 2004/02/09 15:27:12 drahn Exp $ */ - -/* - * Copyright (c) 2004 Dale Rahn. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Atomic lock for arm - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - __asm__("swp %0, %2, [%1]" - : "=r" (old), "=r" (lock) - : "r" (_SPINLOCK_LOCKED), "1" (lock) ); - - return (old != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/arm/uthread_machdep.c b/lib/libpthread/arch/arm/uthread_machdep.c deleted file mode 100644 index 469d5a43a16..00000000000 --- a/lib/libpthread/arch/arm/uthread_machdep.c +++ /dev/null @@ -1,109 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.6 2011/08/03 20:19:46 miod Exp $ */ - -/* - * Copyright (c) 2004 Dale Rahn. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <pthread.h> -#include "pthread_private.h" - -#define ALIGNBYTES 0x7 - -/* Register save frame as it appears on the stack */ -struct frame { - int r[12-4]; - int fp; /* r12 */ - int ip; /* r13 */ - int lr; /* r14 */ - int cpsr; - double fpr[6]; /* sizeof(fp)+sizeof(fs) == 52 */ - int fs; - /* The rest are only valid in the initial frame */ - int next_fp; - int next_ip; - int next_lr; - int oldpc; -}; - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - int cpsr; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((int)base + len - sizeof *f) & ~ALIGNBYTES); - - f->fp = (int)&f->next_fp; - f->ip = (int)0; - f->lr = (int)entry; - f->next_fp = 0; /* for gdb */ - f->next_lr = 0; /* for gdb */ - - /* Initialise the new thread with all the state from this thread. */ - - __asm__ volatile ("mrs %0, cpsr_all" : "=r" (cpsr)); - f->cpsr = cpsr; - - __asm__ volatile ("stmia %0, {r4-r12}":: "r"(&f->r[0])); - -#ifndef __SOFTFP__ - __asm__ volatile ("sfm f4, 4, [%0], #0":: "r"(&f->fpr[0])); - - __asm__ volatile ("rfs 0; stfd 0, %0" : "=m"(f->fs)); -#endif - - statep->frame = (int)f; -} - - -/* - * No-op float saves. - * (Floating point registers were saved in _thread_machdep_switch()) - */ - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ -#if !defined(__SOFTFP__) && !defined (__lint__) -#error finish FP save -#endif -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ -#if !defined(__SOFTFP__) && !defined (__lint__) -#error finish FP save -#endif -} diff --git a/lib/libpthread/arch/arm/uthread_machdep.h b/lib/libpthread/arch/arm/uthread_machdep.h deleted file mode 100644 index 7572667faf1..00000000000 --- a/lib/libpthread/arch/arm/uthread_machdep.h +++ /dev/null @@ -1,30 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.2 2004/02/25 04:16:54 drahn Exp $ */ - -/* - * Copyright (c) 2004 Dale Rahn. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct _machdep_state { - int frame; -}; - diff --git a/lib/libpthread/arch/arm/uthread_machdep_asm.S b/lib/libpthread/arch/arm/uthread_machdep_asm.S deleted file mode 100644 index 272f8c3bf39..00000000000 --- a/lib/libpthread/arch/arm/uthread_machdep_asm.S +++ /dev/null @@ -1,76 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.2 2004/02/21 05:29:16 drahn Exp $ */ - -/* - * Copyright (c) 2004 Dale Rahn. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <machine/asm.h> - -/* THESE MUST BE IN SYNC WITH uthread_machdep.c:struct frame */ -#define OFFSET_R 0 /* offsetof(struct frame, r) */ -#define OFFSET_FP ((12-4)*4) -#define OFFSET_LR (OFFSET_FP+4) -#define OFFSET_CPSR (OFFSET_LR+4) -#define OFFSET_FPR (OFFSET_CPSR+4) -#define OFFSET_FS (OFFSET_FPR+(6*8)) -#define FRAME_SIZE (OFFSET_FS+4) - - -/* - * r0 is pointer to new save area - restore from here - * r1 is pointer to old save area - put pointer to stack save area here - */ -ENTRY(_thread_machdep_switch) - mov ip, sp - sub sp, sp, #FRAME_SIZE+4 - add r2, sp, #4 - stmia r2, {r4-r11} - str fp, [r2, #OFFSET_FP] - str lr, [r2, #OFFSET_LR] - - mrs r3, cpsr_all - str r3, [r2, #OFFSET_CPSR] -#ifndef __VFP_FP__ - sfm f4, 4, [r2, #OFFSET_FPR] - rfs r3 - str r3, [r2, #OFFSET_FS] -#endif - - str sp, [r1, #0] - ldr sp, [r0, #0] - add r2, sp, #4 - - ldmfd r2, {r4-r11} - ldr fp, [r2, #OFFSET_FP] - ldr lr, [r2, #OFFSET_LR] - - ldr r3, [r2, #OFFSET_CPSR] - msr cpsr_f, r3 -#ifndef __VFP_FP__ - lfm f4, 4, [r2, #OFFSET_FPR] - ldr r3, [r2, #OFFSET_FS] - wfs r3 -#endif - - add sp, sp, #FRAME_SIZE+4 - mov pc, lr diff --git a/lib/libpthread/arch/hppa/_atomic_lock.c b/lib/libpthread/arch/hppa/_atomic_lock.c deleted file mode 100644 index 427a8108d95..00000000000 --- a/lib/libpthread/arch/hppa/_atomic_lock.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.3 2011/11/14 15:16:12 jsing Exp $ */ -/* - * Atomic lock for hppa - */ -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - register register_t old; - - __asm__("ldcws 0(%1), %0" : "=r" (old): "r" (lock)); - - return (old == _SPINLOCK_LOCKED); -} diff --git a/lib/libpthread/arch/hppa/uthread_machdep.h b/lib/libpthread/arch/hppa/uthread_machdep.h deleted file mode 100644 index cb9325f7c7c..00000000000 --- a/lib/libpthread/arch/hppa/uthread_machdep.h +++ /dev/null @@ -1,7 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.6 2002/11/01 00:05:45 mickey Exp $ */ - -struct _machdep_state { - u_long sp; - u_long fp; - u_int64_t fpregs[32]; -}; diff --git a/lib/libpthread/arch/hppa/uthread_machdep_asm.S b/lib/libpthread/arch/hppa/uthread_machdep_asm.S deleted file mode 100644 index fe476df338d..00000000000 --- a/lib/libpthread/arch/hppa/uthread_machdep_asm.S +++ /dev/null @@ -1,168 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.3 2007/07/07 15:46:56 kettenis Exp $ */ -/* Michael Shalayeff <mickey@openbsd.org>. Public Domain. */ - -#include <machine/asm.h> -#define _LOCORE -#include <machine/frame.h> - -#define FRAMESIZE 0x60 - -/* - * void _thread_machdep_init(statep, base, len, entry) - * struct _machdep_state *statep; - * void *base; - * int len; - * void (*entry)(void); - */ -ENTRY(_thread_machdep_init,FRAMESIZE) - ldo 7(arg1), arg1 - dep r0, 31, 3, arg1 - ldo HPPA_FRAME_SIZE(arg1), arg1 - ldo FRAMESIZE(arg1), t1 - stw t1, 0(arg0) - stw arg1, 4(arg0) - - bb,>=,n arg3, 30, _thread$noplabel - depi 0, 31, 2, arg3 - ldw 4(arg3), t1 - ldw 0(arg3), arg3 - stw t1, 0x44(arg1) - -_thread$noplabel - bv r0(rp) - stw arg3, 0(arg1) -EXIT(_thread_machdep_init) - -/* - * void _thread_machdep_switch(newstate, oldstate); - * struct _machdep_state *newstate, *oldstate; - */ -ENTRY(_thread_machdep_switch,0) - copy sp, t1 - ldo FRAMESIZE(sp), sp - stw sp, 0(arg1) - stw t1, 4(arg1) - stw r2, 0x00(t1) - stw r3, 0x04(t1) - stw r4, 0x08(t1) - stw r5, 0x0c(t1) - stw r6, 0x10(t1) - stw r7, 0x14(t1) - stw r8, 0x18(t1) - stw r9, 0x1c(t1) - stw r10, 0x20(t1) - stw r11, 0x24(t1) - stw r12, 0x28(t1) - stw r13, 0x2c(t1) - stw r14, 0x30(t1) - stw r15, 0x34(t1) - stw r16, 0x38(t1) - stw r17, 0x3c(t1) - stw r18, 0x40(t1) - stw r19, 0x44(t1) - - ldw 0(arg0), sp - ldw 4(arg0), t1 - ldw 0x00(t1), r2 - ldw 0x04(t1), r3 - ldw 0x08(t1), r4 - ldw 0x0c(t1), r5 - ldw 0x10(t1), r6 - ldw 0x14(t1), r7 - ldw 0x18(t1), r8 - ldw 0x1c(t1), r9 - ldw 0x20(t1), r10 - ldw 0x24(t1), r11 - ldw 0x28(t1), r12 - ldw 0x2c(t1), r13 - ldw 0x30(t1), r14 - ldw 0x34(t1), r15 - ldw 0x38(t1), r16 - ldw 0x3c(t1), r17 - ldw 0x40(t1), r18 - ldw 0x44(t1), r19 - bv r0(rp) - ldo -FRAMESIZE(sp), sp -EXIT(_thread_machdep_switch) - -/* - * void _thread_machdep_save_float_state(struct _machdep_state* statep); - */ -ENTRY(_thread_machdep_save_float_state,0) - ldo 8(arg0), arg0 - fstds,ma fr0 , 8(arg0) - fstds,ma fr1 , 8(arg0) - fstds,ma fr2 , 8(arg0) - fstds,ma fr3 , 8(arg0) - fstds,ma fr4 , 8(arg0) - fstds,ma fr5 , 8(arg0) - fstds,ma fr6 , 8(arg0) - fstds,ma fr7 , 8(arg0) - fstds,ma fr8 , 8(arg0) - fstds,ma fr9 , 8(arg0) - fstds,ma fr10, 8(arg0) - fstds,ma fr11, 8(arg0) - fstds,ma fr12, 8(arg0) - fstds,ma fr13, 8(arg0) - fstds,ma fr14, 8(arg0) - fstds,ma fr15, 8(arg0) - fstds,ma fr16, 8(arg0) - fstds,ma fr17, 8(arg0) - fstds,ma fr18, 8(arg0) - fstds,ma fr19, 8(arg0) - fstds,ma fr20, 8(arg0) - fstds,ma fr21, 8(arg0) - fstds,ma fr22, 8(arg0) - fstds,ma fr23, 8(arg0) - fstds,ma fr24, 8(arg0) - fstds,ma fr25, 8(arg0) - fstds,ma fr26, 8(arg0) - fstds,ma fr27, 8(arg0) - fstds,ma fr28, 8(arg0) - fstds,ma fr29, 8(arg0) - fstds,ma fr30, 8(arg0) - bv r0(rp) - fstd,ma fr31, 8(arg0) -EXIT(_thread_machdep_save_float_state) - -/* - * void _thread_machdep_restore_float_state(struct _machdep_state* statep); - */ -ENTRY(_thread_machdep_restore_float_state,0) - ldo 8*32(arg0), arg0 - fldds,ma -8(arg0), fr31 - fldds,ma -8(arg0), fr30 - fldds,ma -8(arg0), fr29 - fldds,ma -8(arg0), fr28 - fldds,ma -8(arg0), fr27 - fldds,ma -8(arg0), fr26 - fldds,ma -8(arg0), fr25 - fldds,ma -8(arg0), fr24 - fldds,ma -8(arg0), fr23 - fldds,ma -8(arg0), fr22 - fldds,ma -8(arg0), fr21 - fldds,ma -8(arg0), fr20 - fldds,ma -8(arg0), fr19 - fldds,ma -8(arg0), fr18 - fldds,ma -8(arg0), fr17 - fldds,ma -8(arg0), fr16 - fldds,ma -8(arg0), fr15 - fldds,ma -8(arg0), fr14 - fldds,ma -8(arg0), fr13 - fldds,ma -8(arg0), fr12 - fldds,ma -8(arg0), fr11 - fldds,ma -8(arg0), fr10 - fldds,ma -8(arg0), fr9 - fldds,ma -8(arg0), fr8 - fldds,ma -8(arg0), fr7 - fldds,ma -8(arg0), fr6 - fldds,ma -8(arg0), fr5 - fldds,ma -8(arg0), fr4 - fldds,ma -8(arg0), fr3 - fldds,ma -8(arg0), fr2 - fldds,ma -8(arg0), fr1 - bv %r0(rp) - fldds,ma -8(arg0), fr0 -EXIT(_thread_machdep_restore_float_state) - - .end diff --git a/lib/libpthread/arch/hppa64/_atomic_lock.c b/lib/libpthread/arch/hppa64/_atomic_lock.c deleted file mode 100644 index e9ca71cf721..00000000000 --- a/lib/libpthread/arch/hppa64/_atomic_lock.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.2 2011/11/14 15:16:12 jsing Exp $ */ -/* - * Atomic lock for hppa - */ -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - register register_t old; - - __asm__("ldcws 0(%1), %0" : "=r" (old): "r" (lock)); - - return (old == _SPINLOCK_LOCKED); -} diff --git a/lib/libpthread/arch/hppa64/uthread_machdep.h b/lib/libpthread/arch/hppa64/uthread_machdep.h deleted file mode 100644 index da0810bab10..00000000000 --- a/lib/libpthread/arch/hppa64/uthread_machdep.h +++ /dev/null @@ -1,7 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.1 2011/08/04 14:23:36 kettenis Exp $ */ - -struct _machdep_state { - u_long sp; - u_long fp; - u_int64_t fpregs[32]; -}; diff --git a/lib/libpthread/arch/hppa64/uthread_machdep_asm.S b/lib/libpthread/arch/hppa64/uthread_machdep_asm.S deleted file mode 100644 index 2fa991fc62f..00000000000 --- a/lib/libpthread/arch/hppa64/uthread_machdep_asm.S +++ /dev/null @@ -1,109 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.1 2011/08/04 14:23:36 kettenis Exp $ */ -/* Michael Shalayeff <mickey@openbsd.org>. Public Domain. */ - -#include <machine/asm.h> -#define _LOCORE -#include <machine/frame.h> - -/* - * void _thread_machdep_init(statep, base, len, entry) - * struct _machdep_state *statep; - * void *base; - * int len; - * void (*entry)(void); - */ -ENTRY(_thread_machdep_init,0) - bv %r0(%rp) - nop -EXIT(_thread_machdep_init) - -/* - * void _thread_machdep_switch(newstate, oldstate); - * struct _machdep_state *newstate, *oldstate; - */ -ENTRY(_thread_machdep_switch,0) - bv %r0(%rp) - nop -EXIT(_thread_machdep_switch) - -/* - * void _thread_machdep_save_float_state(struct _machdep_state* statep); - */ -ENTRY(_thread_machdep_save_float_state,0) - ldo 8(%arg0), %arg0 - fstd,ma %fr0, 8(%arg0) - fstd,ma %fr1, 8(%arg0) - fstd,ma %fr2, 8(%arg0) - fstd,ma %fr3, 8(%arg0) - fstd,ma %fr4, 8(%arg0) - fstd,ma %fr5, 8(%arg0) - fstd,ma %fr6, 8(%arg0) - fstd,ma %fr7, 8(%arg0) - fstd,ma %fr8, 8(%arg0) - fstd,ma %fr9, 8(%arg0) - fstd,ma %fr10, 8(%arg0) - fstd,ma %fr11, 8(%arg0) - fstd,ma %fr12, 8(%arg0) - fstd,ma %fr13, 8(%arg0) - fstd,ma %fr14, 8(%arg0) - fstd,ma %fr15, 8(%arg0) - fstd,ma %fr16, 8(%arg0) - fstd,ma %fr17, 8(%arg0) - fstd,ma %fr18, 8(%arg0) - fstd,ma %fr19, 8(%arg0) - fstd,ma %fr20, 8(%arg0) - fstd,ma %fr21, 8(%arg0) - fstd,ma %fr22, 8(%arg0) - fstd,ma %fr23, 8(%arg0) - fstd,ma %fr24, 8(%arg0) - fstd,ma %fr25, 8(%arg0) - fstd,ma %fr26, 8(%arg0) - fstd,ma %fr27, 8(%arg0) - fstd,ma %fr28, 8(%arg0) - fstd,ma %fr29, 8(%arg0) - fstd,ma %fr30, 8(%arg0) - bv %r0(%rp) - fstd,ma %fr31, 8(%arg0) -EXIT(_thread_machdep_save_float_state) - -/* - * void _thread_machdep_restore_float_state(struct _machdep_state* statep); - */ -ENTRY(_thread_machdep_restore_float_state,0) - ldo 8*32(%arg0), %arg0 - fldd,ma -8(%arg0), %fr31 - fldd,ma -8(%arg0), %fr30 - fldd,ma -8(%arg0), %fr29 - fldd,ma -8(%arg0), %fr28 - fldd,ma -8(%arg0), %fr27 - fldd,ma -8(%arg0), %fr26 - fldd,ma -8(%arg0), %fr25 - fldd,ma -8(%arg0), %fr24 - fldd,ma -8(%arg0), %fr23 - fldd,ma -8(%arg0), %fr22 - fldd,ma -8(%arg0), %fr21 - fldd,ma -8(%arg0), %fr20 - fldd,ma -8(%arg0), %fr19 - fldd,ma -8(%arg0), %fr18 - fldd,ma -8(%arg0), %fr17 - fldd,ma -8(%arg0), %fr16 - fldd,ma -8(%arg0), %fr15 - fldd,ma -8(%arg0), %fr14 - fldd,ma -8(%arg0), %fr13 - fldd,ma -8(%arg0), %fr12 - fldd,ma -8(%arg0), %fr11 - fldd,ma -8(%arg0), %fr10 - fldd,ma -8(%arg0), %fr9 - fldd,ma -8(%arg0), %fr8 - fldd,ma -8(%arg0), %fr7 - fldd,ma -8(%arg0), %fr6 - fldd,ma -8(%arg0), %fr5 - fldd,ma -8(%arg0), %fr4 - fldd,ma -8(%arg0), %fr3 - fldd,ma -8(%arg0), %fr2 - fldd,ma -8(%arg0), %fr1 - bv %r0(%rp) - fldd,ma -8(%arg0), %fr0 -EXIT(_thread_machdep_restore_float_state) - - .end diff --git a/lib/libpthread/arch/i386/_atomic_lock.c b/lib/libpthread/arch/i386/_atomic_lock.c deleted file mode 100644 index 9bf4d82b994..00000000000 --- a/lib/libpthread/arch/i386/_atomic_lock.c +++ /dev/null @@ -1,25 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.8 2010/12/03 19:44:22 miod Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Atomic lock for i386 - */ - -#include <spinlock.h> - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - /* - * Use the eXCHanGe instruction to swap the lock value with - * a local variable containing the locked state. - */ - old = _SPINLOCK_LOCKED; - __asm__("xchg %0,(%2)" - : "=r" (old) - : "0" (old), "r" (lock)); - - return (old != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/i386/uthread_machdep.c b/lib/libpthread/arch/i386/uthread_machdep.c deleted file mode 100644 index 8d9d5da9da5..00000000000 --- a/lib/libpthread/arch/i386/uthread_machdep.c +++ /dev/null @@ -1,136 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.6 2008/01/28 18:48:41 kettenis Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Machine-dependent thread state functions for OpenBSD/i386. - */ - -#include <sys/param.h> -#include <sys/sysctl.h> -#include <machine/cpu.h> -#include <pthread.h> -#include "pthread_private.h" - -struct frame { - int fr_gs; - int fr_fs; - int fr_es; - int fr_ds; - - int fr_edi; - int fr_esi; - int fr_ebp; - int fr_esp; - int fr_ebx; - int fr_edx; - int fr_ecx; - int fr_eax; - - int fr_eip; - int fr_cs; /* XXX unreachable? */ -}; - -#define copyreg(reg, lval) \ - __asm__("mov %%" #reg ", %0" : "=g"(lval)) - -static int _thread_machdep_osfxsr(void); - -static int -_thread_machdep_osfxsr(void) -{ - int mib[] = { CTL_MACHDEP, CPU_OSFXSR }; - static int sse = -1; - size_t len; - int val; - - if (sse == -1) { - len = sizeof (val); - if (sysctl(mib, 2, &val, &len, NULL, 0) == -1) - return (0); - if (val) - sse = 1; - else - sse = 0; - } - return (sse); -} - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(struct _machdep_state* statep, void *base, int len, - void (*entry)(void)) -{ - struct frame *f; - - /* - * Locate the initial frame at the top of the stack. For the - * stack to end up properly (16-byte) aligned, we need to - * align the frame at an odd 8-byte boundary. - */ - f = (struct frame *)((((int)base + len - sizeof *f) & ~15) - 8); - - /* Set up initial frame */ - f->fr_esp = (int)&f->fr_edi; - copyreg(cs, f->fr_cs); - copyreg(ds, f->fr_ds); - copyreg(es, f->fr_es); - copyreg(fs, f->fr_fs); - copyreg(gs, f->fr_gs); - f->fr_ebp = (int)-1; - f->fr_eip = (int)entry; - - statep->esp = (int)f; - - _thread_machdep_save_float_state(statep); - /* - * The current thread float state is saved into the new thread stack. - * Later pthread_create calls _thread_kern_sched which saves the current - * thread float state again into its own stack. However all float state - * saves must be balanced with a restore on i386 due to the fninit(). - * Restore the current thread float state here so that the next save - * gets the correct state. - */ - _thread_machdep_restore_float_state(statep); -} - -/* - * Floating point save restore copied from code in npx.c - * (without really understanding what it does). - */ -#define fldcw(addr) __asm("fldcw %0" : : "m" (*addr)) -#define fnsave(addr) __asm("fnsave %0" : "=m" (*addr)) -#define fninit() __asm("fninit") -#define frstor(addr) __asm("frstor %0" : : "m" (*addr)) -#define fxsave(addr) __asm("fxsave %0" : "=m" (*addr)) -#define fxrstor(addr) __asm("fxrstor %0" : : "m" (*addr)) -#define fwait() __asm("fwait") - -void -_thread_machdep_save_float_state(struct _machdep_state *ms) -{ - union savefpu *addr = &ms->fpreg; - - if (_thread_machdep_osfxsr()) { - fwait(); - fxsave(&addr->sv_xmm); - fninit(); - } else - fnsave(&addr->sv_87); - fwait(); -} - -void -_thread_machdep_restore_float_state(struct _machdep_state *ms) -{ - union savefpu *addr = &ms->fpreg; - - if (_thread_machdep_osfxsr()) { - fxrstor(&addr->sv_xmm); - fwait(); - } else - frstor(&addr->sv_87); - -} diff --git a/lib/libpthread/arch/i386/uthread_machdep.h b/lib/libpthread/arch/i386/uthread_machdep.h deleted file mode 100644 index becb026755f..00000000000 --- a/lib/libpthread/arch/i386/uthread_machdep.h +++ /dev/null @@ -1,10 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.10 2010/06/30 19:04:51 kettenis Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/npx.h> - -struct _machdep_state { - int esp; - /* must be 128-bit aligned */ - union savefpu fpreg __attribute__ ((aligned (16))); -}; diff --git a/lib/libpthread/arch/i386/uthread_machdep_asm.S b/lib/libpthread/arch/i386/uthread_machdep_asm.S deleted file mode 100644 index 06652fd210f..00000000000 --- a/lib/libpthread/arch/i386/uthread_machdep_asm.S +++ /dev/null @@ -1,27 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.1 2000/09/25 01:16:40 d Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> - -/* - * Switch stacks - */ - -/* void _thread_machdep_switch(new, oldsave); */ -ENTRY(_thread_machdep_switch) - pushal /* pushl %eax,%ecx,%edx,%ebx,%esp,%ebp,%esi,%edi */ - pushl %ds - pushl %es - pushl %fs - pushl %gs -#define DISTANCE ((8+1+1+1+1)*4) - movl (DISTANCE+8)(%esp), %eax /* %eax = arg2 */ - movl %esp, 0(%eax) /* *arg2 = %esp */ - movl (DISTANCE+4)(%esp), %eax /* %eax = arg1 */ - movl 0(%eax), %esp /* %esp = *arg1 */ - popl %gs - popl %fs - popl %es - popl %ds - popal /* popl %edi,%esi,%ebp,%esp,%ebx,%edx,%ecx,%eax */ - ret diff --git a/lib/libpthread/arch/m68k/_atomic_lock.c b/lib/libpthread/arch/m68k/_atomic_lock.c deleted file mode 100644 index cc4effe06f9..00000000000 --- a/lib/libpthread/arch/m68k/_atomic_lock.c +++ /dev/null @@ -1,38 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.7 2008/10/02 23:27:23 deraadt Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Atomic lock for m68k - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - /* - * The Compare And Swap instruction (mc68020 and above) - * compares its first operand with the memory addressed by - * the third. If they are the same value, the second operand - * is stored at the address. Otherwise the 1st operand (register) - * is loaded with the contents of the 3rd operand. - * - * old = 0; - * CAS(old, 1, *lock); - * if (old == 1) { lock was acquired } - * - * From the MC68030 User's Manual (Motorola), page `3-13': - * CAS Dc,Du,<ea>: - * (<ea> - Dc) -> cc; - * if Z then Du -> <ea> - * else <ea> -> Dc; - */ - old = _SPINLOCK_UNLOCKED; - __asm__("casl %0, %2, %1" : "=d" (old), "=m" (*lock) - : "d" (_SPINLOCK_LOCKED), - "0" (old), "1" (*lock) - : "cc"); - return (old != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/m68k/uthread_machdep.c b/lib/libpthread/arch/m68k/uthread_machdep.c deleted file mode 100644 index 77c8019d1da..00000000000 --- a/lib/libpthread/arch/m68k/uthread_machdep.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.2 2003/06/02 08:11:15 miod Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Machine-dependent thread state functions for OpenBSD/m68k - */ - -#include <pthread.h> -#include "pthread_private.h" - -#define ALIGNBYTES 0x3 - -struct frame { - int d2,d3,d4,d5,d6,d7; - int a2,a3,a4,a5,fp; - int link; /* frame link */ - int ra; -}; - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((int)base + len - sizeof *f) & ~ALIGNBYTES); - - f->ra = (int)entry; - f->link = 0; - f->fp = (int)&f->link; - statep->sp = (int)f; -} - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ - /* fsave is a privileged instruction */ -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ - /* frestore is a privileged instruction */ -} diff --git a/lib/libpthread/arch/m68k/uthread_machdep.h b/lib/libpthread/arch/m68k/uthread_machdep.h deleted file mode 100644 index d9bb9935ca6..00000000000 --- a/lib/libpthread/arch/m68k/uthread_machdep.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.4 2000/10/04 05:55:34 d Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -struct _machdep_state { - int sp; -}; diff --git a/lib/libpthread/arch/m68k/uthread_machdep_asm.S b/lib/libpthread/arch/m68k/uthread_machdep_asm.S deleted file mode 100644 index 30e4397b838..00000000000 --- a/lib/libpthread/arch/m68k/uthread_machdep_asm.S +++ /dev/null @@ -1,18 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.1 2000/09/25 09:03:44 d Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> - -#define SA(x) (((x)+3)&~3) -#define FRAMESIZE 4*11 - -ENTRY(_thread_machdep_switch) - link a6, #-SA(FRAMESIZE) - moveml #0x7CFC, sp@ /* d2-d7,a2-a6 */ - movel a6@(8), a0 - movel a6@(12), a1 - movel sp, a1@ - movel a0@, sp - moveml sp@, #0x7CFC - unlk a6 - rts diff --git a/lib/libpthread/arch/m88k/_atomic_lock.c b/lib/libpthread/arch/m88k/_atomic_lock.c deleted file mode 100644 index c156eb7da57..00000000000 --- a/lib/libpthread/arch/m88k/_atomic_lock.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.4 2004/02/27 22:19:46 deraadt Exp $ */ - -/* - * Copyright (c) 2003, Miodrag Vallat. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Atomic lock for m88k - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - old = _SPINLOCK_LOCKED; - __asm__ __volatile__ - ("xmem %0, %2, r0" : "=r" (old) : "0" (old), "r" (lock)); - - return (old != _SPINLOCK_UNLOCKED); -} - -int -_atomic_is_locked(volatile _spinlock_lock_t *lock) -{ - - return (*lock != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/m88k/uthread_machdep.c b/lib/libpthread/arch/m88k/uthread_machdep.c deleted file mode 100644 index c73fe479eb0..00000000000 --- a/lib/libpthread/arch/m88k/uthread_machdep.c +++ /dev/null @@ -1,73 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.2 2004/03/02 23:41:29 miod Exp $ */ - -/* - * Copyright (c) 2004 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Machine-dependent thread state functions for m88k - */ - -#include <pthread.h> -#include "pthread_private.h" - -#define ALIGNBYTES 7 - -struct frame { - long regs[28]; /* r4-r30, r1 */ -}; - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - - f = (struct frame *)(((u_int32_t)base + len - sizeof *f) & ~ALIGNBYTES); - f->regs[27] = (u_int32_t)entry; /* ``saved'' r1 */ - - statep->sp = (int)f; -} - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ - int fpreg; - - __asm__ __volatile__ ("fldcr %0, fcr62" : "=r" (fpreg)); - statep->fpsr = fpreg; - __asm__ __volatile__ ("fldcr %0, fcr63" : "=r" (fpreg)); - statep->fpcr = fpreg; -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ - int fpreg; - - fpreg = statep->fpsr; - __asm__ __volatile__ ("fstcr %0, fcr62" : : "r" (fpreg)); - fpreg = statep->fpcr; - __asm__ __volatile__ ("fstcr %0, fcr63" : : "r" (fpreg)); -} diff --git a/lib/libpthread/arch/m88k/uthread_machdep.h b/lib/libpthread/arch/m88k/uthread_machdep.h deleted file mode 100644 index 073af3e031c..00000000000 --- a/lib/libpthread/arch/m88k/uthread_machdep.h +++ /dev/null @@ -1,23 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.5 2004/02/27 22:19:46 deraadt Exp $ */ - -/* - * Copyright (c) 2004 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -struct _machdep_state { - u_int sp; - int fpsr; - int fpcr; -}; diff --git a/lib/libpthread/arch/m88k/uthread_machdep_asm.S b/lib/libpthread/arch/m88k/uthread_machdep_asm.S deleted file mode 100644 index dcf997650d8..00000000000 --- a/lib/libpthread/arch/m88k/uthread_machdep_asm.S +++ /dev/null @@ -1,66 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.2 2004/03/02 23:41:29 miod Exp $ */ - -/* - * Copyright (c) 2004 Theo de Raadt - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <machine/asm.h> - -/* - * void _thread_machdep_switch(new, oldsave); - */ -ENTRY(_thread_machdep_switch) - subu r31, r31, 4 * 28 - - /* save all registers but r0, r2, r3 and r31 on stack */ - st.d r4, r31, 4 * 0 - st.d r6, r31, 4 * 2 - st.d r8, r31, 4 * 4 - st.d r10, r31, 4 * 6 - st.d r12, r31, 4 * 8 - st.d r14, r31, 4 * 10 - st.d r16, r31, 4 * 12 - st.d r18, r31, 4 * 14 - st.d r20, r31, 4 * 16 - st.d r22, r31, 4 * 18 - st.d r24, r31, 4 * 20 - st.d r26, r31, 4 * 22 - st.d r28, r31, 4 * 24 - st r30, r31, 4 * 26 - st r1, r31, 4 * 27 - - /* exchange stacks */ - st r31, r3, 0 /* oldsave->frame = r31 */ - ld r31, r2, 0 /* r31 = oldsave->frame */ - - /* restore registers */ - ld.d r4, r31, 4 * 0 - ld.d r6, r31, 4 * 2 - ld.d r8, r31, 4 * 4 - ld.d r10, r31, 4 * 6 - ld.d r12, r31, 4 * 8 - ld.d r14, r31, 4 * 10 - ld.d r16, r31, 4 * 12 - ld.d r18, r31, 4 * 14 - ld.d r20, r31, 4 * 16 - ld.d r22, r31, 4 * 18 - ld.d r24, r31, 4 * 20 - ld.d r26, r31, 4 * 22 - ld.d r28, r31, 4 * 24 - ld r30, r31, 4 * 26 - ld r1, r31, 4 * 27 - - jmp.n r1 - addu r31, r31, 4 * 28 diff --git a/lib/libpthread/arch/mips64/_atomic_lock.c b/lib/libpthread/arch/mips64/_atomic_lock.c deleted file mode 100644 index e85335f7466..00000000000 --- a/lib/libpthread/arch/mips64/_atomic_lock.c +++ /dev/null @@ -1,24 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.3 2009/06/01 23:17:52 miod Exp $ */ - -/* - * Atomic lock for mips - * Written by Miodrag Vallat <miod@openbsd.org> - placed in the public domain. - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - __asm__ __volatile__ ( - "1: ll %0, 0(%1)\n" - " sc %2, 0(%1)\n" - " beqz %2, 1b\n" - " nop\n" : - "=r"(old) : - "r"(lock), "r"(_SPINLOCK_LOCKED) : "memory"); - - return (old != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/mips64/_spinlock.h b/lib/libpthread/arch/mips64/_spinlock.h deleted file mode 100644 index d1f543f2faa..00000000000 --- a/lib/libpthread/arch/mips64/_spinlock.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: _spinlock.h,v 1.1 2004/08/11 17:41:34 pefo Exp $ */ - -#define _SPINLOCK_UNLOCKED (0) -#define _SPINLOCK_LOCKED (1) -typedef int _spinlock_lock_t; - diff --git a/lib/libpthread/arch/mips64/uthread_machdep.c b/lib/libpthread/arch/mips64/uthread_machdep.c deleted file mode 100644 index 66e57641cb7..00000000000 --- a/lib/libpthread/arch/mips64/uthread_machdep.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.3 2004/11/02 21:36:11 pefo Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Machine-dependent thread state functions for OpenBSD/mips - */ - -#include <pthread.h> -#include "pthread_private.h" - -#define ALIGNBYTES 0x3 - -struct frame { - long s[9]; /* s0..s8 */ - double f[8]; /* $f24..$f31 */ - long fcr; - long t9; /* XXX only used when bootstrapping */ - long ra; - -/* XXX args should not be here for N32 or N64 ABIs */ - long arg[4], cra, cfp; /* ABI space for debuggers */ -}; - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((long)base + len - sizeof *f) & ~ALIGNBYTES); - - f->ra = (long)entry; - f->t9 = (long)entry; - f->fcr = 0; - - statep->frame = (long)f; -} - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ -} diff --git a/lib/libpthread/arch/mips64/uthread_machdep.h b/lib/libpthread/arch/mips64/uthread_machdep.h deleted file mode 100644 index e3d31729b7b..00000000000 --- a/lib/libpthread/arch/mips64/uthread_machdep.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.2 2004/09/09 16:59:21 pefo Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -struct _machdep_state { - long frame; -}; diff --git a/lib/libpthread/arch/mips64/uthread_machdep_asm.S b/lib/libpthread/arch/mips64/uthread_machdep_asm.S deleted file mode 100644 index a3c0a6e8366..00000000000 --- a/lib/libpthread/arch/mips64/uthread_machdep_asm.S +++ /dev/null @@ -1,96 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.3 2004/11/02 21:36:11 pefo Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> - -/* - * Save layout: - * - * ----------- - * +152 | sp | - * +144 | t9 | - * ----------- - * +136 | fcr | - * ----------- - * +128 | f31 | - * +120 | f30 | - * +112 | f29 | - * +104 | f28 | - * +96 | f27 | - * +88 | f26 | - * +80 | f25 | - * +72 | f24 | - * ----------- - * +64 | s8 | - * +56 | s7 | - * +48 | s6 | - * +40 | s5 | - * +32 | s4 | - * +24 | s3 | - * +16 | s2 | - * +8 | s1 | - * sp -> | s0 | - * ----------- - */ - -#define SOFF(n) ((n)*REGSZ) -#define FPOFF(n) (SOFF(9) + (n)*8) -#define REGOFF(n) (FPOFF(9) + (n)*REGSZ) - -#define FRAMESIZE (REGOFF(2) + REGSZ*4+REGSZ+REGSZ) - -NON_LEAF(_thread_machdep_switch, FRAMESIZE, ra) - PTR_ADDU sp, sp, -FRAMESIZE - - REG_S s0, SOFF(0)(sp) - REG_S s1, SOFF(1)(sp) - REG_S s2, SOFF(2)(sp) - REG_S s3, SOFF(3)(sp) - REG_S s4, SOFF(4)(sp) - REG_S s5, SOFF(5)(sp) - REG_S s6, SOFF(6)(sp) - REG_S s7, SOFF(7)(sp) - REG_S s8, SOFF(8)(sp) - s.d $f24, FPOFF(0)(sp) - s.d $f25, FPOFF(1)(sp) - s.d $f26, FPOFF(2)(sp) - s.d $f27, FPOFF(3)(sp) - s.d $f28, FPOFF(4)(sp) - s.d $f29, FPOFF(5)(sp) - s.d $f30, FPOFF(6)(sp) - s.d $f31, FPOFF(7)(sp) - REG_S t9, REGOFF(0)(sp) - REG_S ra, REGOFF(1)(sp) - cfc1 t9, $31 - REG_S t9, FPOFF(8)(sp) - - REG_S sp, 0(a1) - REG_L sp, 0(a0) - - .set noreorder /* avoid nops */ - REG_L t9, FPOFF(8)(sp) - ctc1 t9, $31 - REG_L ra, REGOFF(1)(sp) - REG_L t9, REGOFF(0)(sp) - l.d $f24, FPOFF(0)(sp) - l.d $f25, FPOFF(1)(sp) - l.d $f26, FPOFF(2)(sp) - l.d $f27, FPOFF(3)(sp) - l.d $f28, FPOFF(4)(sp) - l.d $f29, FPOFF(5)(sp) - l.d $f30, FPOFF(6)(sp) - l.d $f31, FPOFF(7)(sp) - REG_L s8, SOFF(8)(sp) - REG_L s7, SOFF(7)(sp) - REG_L s6, SOFF(6)(sp) - REG_L s5, SOFF(5)(sp) - REG_L s4, SOFF(4)(sp) - REG_L s3, SOFF(3)(sp) - REG_L s2, SOFF(2)(sp) - REG_L s1, SOFF(1)(sp) - REG_L s0, SOFF(0)(sp) - .set reorder - - PTR_ADDU sp, sp, FRAMESIZE - j ra -END(_thread_machdep_switch) diff --git a/lib/libpthread/arch/powerpc/_atomic_lock.c b/lib/libpthread/arch/powerpc/_atomic_lock.c deleted file mode 100644 index f7a80bd9697..00000000000 --- a/lib/libpthread/arch/powerpc/_atomic_lock.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.8 2008/10/01 14:59:18 drahn Exp $ */ -/* - * Copyright (c) 1998 Dale Rahn <drahn@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Atomic lock for powerpc - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - __asm__("1: lwarx 0,0,%1 \n" - " stwcx. %2,0,%1 \n" - " bne- 1b \n" - " mr %0, 0 \n" - : "=r" (old), "=r" (lock) - : "r" (_SPINLOCK_LOCKED), "1" (lock) : "0" - ); - - return (old != _SPINLOCK_UNLOCKED); - - /* - * Dale <drahn@openbsd.org> says: - * Side note. to prevent two processes from accessing - * the same address with the lwarx in one instruction - * and the stwcx in another process, the current powerpc - * kernel uses a stwcx instruction without the corresponding - * lwarx which causes any reservation of a process - * to be removed. if a context switch occurs - * between the two accesses the store will not occur - * and the condition code will cause it to loop. If on - * a dual processor machine, the reserve will cause - * appropriate bus cycle accesses to notify other - * processors. - */ -} diff --git a/lib/libpthread/arch/powerpc/uthread_machdep.c b/lib/libpthread/arch/powerpc/uthread_machdep.c deleted file mode 100644 index 51735790825..00000000000 --- a/lib/libpthread/arch/powerpc/uthread_machdep.c +++ /dev/null @@ -1,86 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.5 2006/09/29 14:35:28 otto Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain */ - -#include <pthread.h> -#include "pthread_private.h" - -#define ALIGNBYTES 0xf - -/* Register save frame as it appears on the stack */ -struct frame { - int r1; - int reserved; - int gp[32-14]; - int lr, cr, ctr, xer; - double fp[32]; - double fs; - /* The rest are only valid in the initial frame */ - int next_r1; - int next_lr; -}; - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((int)base - 16 + len - sizeof *f) & ~ALIGNBYTES); - - f->r1 = (int)&f->next_r1; - f->reserved = 0; - f->lr = (int)entry; - f->next_r1 = 0; /* for gdb */ - f->next_lr = 0; /* for gdb */ - - /* Initialise the new thread with all the state from this thread. */ - -#define copyreg(x) __asm__ volatile ("stw " #x ", %0" : "=m"(f->gp[x-14])) - copyreg(14); copyreg(15); copyreg(16); copyreg(17); copyreg(18); - copyreg(19); copyreg(20); copyreg(21); copyreg(22); copyreg(23); - copyreg(24); copyreg(25); copyreg(26); copyreg(27); copyreg(28); - copyreg(29); copyreg(30); copyreg(31); - -#define copysreg(nm) __asm__ volatile ("mf" #nm " %0" : "=r"(f->nm)) - copysreg(cr); copysreg(ctr); copysreg(xer); - -#define copyfreg(x) __asm__ volatile ("stfd " #x ", %0" : "=m"(f->fp[x])) - copyfreg(0); copyfreg(1); copyfreg(2); copyfreg(3); - copyfreg(4); copyfreg(5); copyfreg(6); copyfreg(7); - copyfreg(8); copyfreg(9); copyfreg(10); copyfreg(11); - copyfreg(12); copyfreg(13); copyfreg(14); copyfreg(15); - copyfreg(16); copyfreg(17); copyfreg(18); copyfreg(19); - copyfreg(20); copyfreg(21); copyfreg(22); copyfreg(23); - copyfreg(24); copyfreg(25); copyfreg(26); copyfreg(27); - copyfreg(28); copyfreg(29); copyfreg(30); copyfreg(31); - - __asm__ volatile ("mffs 0; stfd 0, %0" : "=m"(f->fs)); - - statep->frame = (int)f; -} - - -/* - * No-op float saves. - * (Floating point registers were saved in _thread_machdep_switch()) - */ - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ -} diff --git a/lib/libpthread/arch/powerpc/uthread_machdep.h b/lib/libpthread/arch/powerpc/uthread_machdep.h deleted file mode 100644 index 54c864e71a4..00000000000 --- a/lib/libpthread/arch/powerpc/uthread_machdep.h +++ /dev/null @@ -1,7 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:35 d Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -struct _machdep_state { - int frame; -}; - diff --git a/lib/libpthread/arch/powerpc/uthread_machdep_asm.S b/lib/libpthread/arch/powerpc/uthread_machdep_asm.S deleted file mode 100644 index b6a5a1acbea..00000000000 --- a/lib/libpthread/arch/powerpc/uthread_machdep_asm.S +++ /dev/null @@ -1,135 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.2 2003/01/27 21:45:24 drahn Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> - -/* These need to be kept in sync with uthread_machdep.c */ -#define REGOFF(n) (2*4 + (n-14)*4) -#define FPOFF(n) (REGOFF(36) + (n)*8) -#define FRAMESIZE FPOFF(33) - -#define SA(x) (((x)+0xf)&~0xf) - -ENTRY(_thread_machdep_switch) - stwu 1, -SA(FRAMESIZE)(1) - - /* Save context into frame */ - stw 14, REGOFF(14)(1) - stw 15, REGOFF(15)(1) - stw 16, REGOFF(16)(1) - stw 17, REGOFF(17)(1) - stw 18, REGOFF(18)(1) - stw 19, REGOFF(19)(1) - stw 20, REGOFF(20)(1) - stw 21, REGOFF(21)(1) - stw 22, REGOFF(22)(1) - stw 23, REGOFF(23)(1) - stw 24, REGOFF(24)(1) - stw 25, REGOFF(25)(1) - stw 26, REGOFF(26)(1) - stw 27, REGOFF(27)(1) - stw 28, REGOFF(28)(1) - stw 29, REGOFF(29)(1) - stw 30, REGOFF(30)(1) - stw 31, REGOFF(31)(1) - mflr 0; stw 0, REGOFF(32)(1) - mfcr 0; stw 0, REGOFF(33)(1) - mfctr 0; stw 0, REGOFF(34)(1) - mfxer 0; stw 0, REGOFF(35)(1) - stfd 0, FPOFF(0)(1) - stfd 1, FPOFF(1)(1) - stfd 2, FPOFF(2)(1) - stfd 3, FPOFF(3)(1) - stfd 4, FPOFF(4)(1) - stfd 5, FPOFF(5)(1) - stfd 6, FPOFF(6)(1) - stfd 7, FPOFF(7)(1) - stfd 8, FPOFF(8)(1) - stfd 9, FPOFF(9)(1) - stfd 10, FPOFF(10)(1) - stfd 11, FPOFF(11)(1) - stfd 12, FPOFF(12)(1) - stfd 13, FPOFF(13)(1) - stfd 14, FPOFF(14)(1) - stfd 15, FPOFF(15)(1) - stfd 16, FPOFF(16)(1) - stfd 17, FPOFF(17)(1) - stfd 18, FPOFF(18)(1) - stfd 19, FPOFF(19)(1) - stfd 20, FPOFF(20)(1) - stfd 21, FPOFF(21)(1) - stfd 22, FPOFF(22)(1) - stfd 23, FPOFF(23)(1) - stfd 24, FPOFF(24)(1) - stfd 25, FPOFF(25)(1) - stfd 26, FPOFF(26)(1) - stfd 27, FPOFF(27)(1) - stfd 28, FPOFF(28)(1) - stfd 29, FPOFF(29)(1) - stfd 30, FPOFF(30)(1) - stfd 31, FPOFF(31)(1) - mffs 0; stfd 0, FPOFF(32)(1) - - /* Switch stacks */ - stw 1, 0(4) - lwz 1, 0(3) - - /* Restore context from the frame */ - lfd 0, FPOFF(32)(1); mtfsf 0xff, 0 - lfd 31, FPOFF(31)(1) - lfd 30, FPOFF(30)(1) - lfd 29, FPOFF(29)(1) - lfd 28, FPOFF(28)(1) - lfd 27, FPOFF(27)(1) - lfd 26, FPOFF(26)(1) - lfd 25, FPOFF(25)(1) - lfd 24, FPOFF(24)(1) - lfd 23, FPOFF(23)(1) - lfd 22, FPOFF(22)(1) - lfd 21, FPOFF(21)(1) - lfd 20, FPOFF(20)(1) - lfd 19, FPOFF(19)(1) - lfd 18, FPOFF(18)(1) - lfd 17, FPOFF(17)(1) - lfd 16, FPOFF(16)(1) - lfd 15, FPOFF(15)(1) - lfd 14, FPOFF(14)(1) - lfd 13, FPOFF(13)(1) - lfd 12, FPOFF(12)(1) - lfd 11, FPOFF(11)(1) - lfd 10, FPOFF(10)(1) - lfd 9, FPOFF(9)(1) - lfd 8, FPOFF(8)(1) - lfd 7, FPOFF(7)(1) - lfd 6, FPOFF(6)(1) - lfd 5, FPOFF(5)(1) - lfd 4, FPOFF(4)(1) - lfd 3, FPOFF(3)(1) - lfd 2, FPOFF(2)(1) - lfd 1, FPOFF(1)(1) - lfd 0, FPOFF(0)(1) - - lwz 0, REGOFF(35)(1); mtxer 0 - lwz 0, REGOFF(34)(1); mtctr 0 - lwz 0, REGOFF(33)(1); mtcr 0 - lwz 0, REGOFF(32)(1); mtlr 0 - lwz 31, REGOFF(31)(1) - lwz 30, REGOFF(30)(1) - lwz 29, REGOFF(29)(1) - lwz 28, REGOFF(28)(1) - lwz 27, REGOFF(27)(1) - lwz 26, REGOFF(26)(1) - lwz 25, REGOFF(25)(1) - lwz 24, REGOFF(24)(1) - lwz 23, REGOFF(23)(1) - lwz 22, REGOFF(22)(1) - lwz 21, REGOFF(21)(1) - lwz 20, REGOFF(20)(1) - lwz 19, REGOFF(19)(1) - lwz 18, REGOFF(18)(1) - lwz 17, REGOFF(17)(1) - lwz 16, REGOFF(16)(1) - lwz 15, REGOFF(15)(1) - lwz 14, REGOFF(14)(1) - la 1, SA(FRAMESIZE)(1) - blr diff --git a/lib/libpthread/arch/sh/_atomic_lock.c b/lib/libpthread/arch/sh/_atomic_lock.c deleted file mode 100644 index 3431e69b3a8..00000000000 --- a/lib/libpthread/arch/sh/_atomic_lock.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.3 2008/06/26 05:42:05 ray Exp $ */ - -/*- - * Copyright (c) 2002 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Gregory McGarry. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - __asm volatile( - " tas.b %0 \n" - " mov #0, %1 \n" - " rotcl %1 \n" - : "=m" (*lock), "=r" (old)); - - return (old == 0); -} - -int -_atomic_is_locked(volatile _spinlock_lock_t *lock) -{ - - return (*lock != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/sh/uthread_machdep.c b/lib/libpthread/arch/sh/uthread_machdep.c deleted file mode 100644 index b507e01e440..00000000000 --- a/lib/libpthread/arch/sh/uthread_machdep.c +++ /dev/null @@ -1,83 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.2 2007/03/02 06:11:54 miod Exp $ */ - -/* - * Copyright (c) 2007 Miodrag Vallat. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice, this permission notice, and the disclaimer below - * appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <pthread.h> -#include "pthread_private.h" - -#define STACK_ALIGNMENT 4 - -struct regframe { - /* return address */ - register_t pr; - /* call-saved general registers */ - register_t r14; - register_t r13; - register_t r12; - register_t r11; - register_t r10; - register_t r9; - register_t r8; - register_t macl; - register_t mach; -#if defined(__SH4__) && !defined(__SH4_NOFPU__) - /* call-saved floating point registers */ - register_t fr12; - register_t fr13; - register_t fr14; - register_t fr15; - register_t xd12; - register_t xd13; - register_t xd14; - register_t xd15; - /* floating point control registers */ - register_t fpul; - register_t fpscr; -#endif -}; - -void -_thread_machdep_init(struct _machdep_state* statep, void *base, int len, - void (*entry)(void)) -{ - struct regframe *regs; - - regs = (struct regframe *) - (((u_int32_t)base + len - sizeof *regs) & ~(STACK_ALIGNMENT - 1)); - regs->pr = (register_t)entry; -#if defined(__SH4__) && !defined(__SH4_NOFPU__) - __asm__ __volatile__ ("sts fpscr, %0" : "=r" (regs->fpscr)); -#endif - - statep->sp = (u_int)regs; -} - -/* - * Floating point state is saved with the general registers in - * _thread_machdep_switch(). - */ - -void -_thread_machdep_save_float_state(struct _machdep_state* statep) -{ -} - -void -_thread_machdep_restore_float_state(struct _machdep_state* statep) -{ -} diff --git a/lib/libpthread/arch/sh/uthread_machdep.h b/lib/libpthread/arch/sh/uthread_machdep.h deleted file mode 100644 index 3277ec156c1..00000000000 --- a/lib/libpthread/arch/sh/uthread_machdep.h +++ /dev/null @@ -1,5 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.2 2007/02/19 21:03:50 miod Exp $ */ - -struct _machdep_state { - u_int sp; -}; diff --git a/lib/libpthread/arch/sh/uthread_machdep_asm.S b/lib/libpthread/arch/sh/uthread_machdep_asm.S deleted file mode 100644 index 13b7111a692..00000000000 --- a/lib/libpthread/arch/sh/uthread_machdep_asm.S +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.2 2007/03/02 06:11:54 miod Exp $ */ - -/* - * Copyright (c) 2007 Miodrag Vallat. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice, this permission notice, and the disclaimer below - * appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <machine/asm.h> - -/* - * void _thread_machdep_switch(new, oldsave); - */ -ENTRY(_thread_machdep_switch) - /* - * On entry: r4 = new, r5 = oldsave - */ - - /* - * Save current context on the stack. - */ -#if defined(__SH4__) && !defined(__SH4_NOFPU__) - sts.l fpscr, @-r15 - mov #0, r1 - sts.l fpul, @-r15 - lds r1, fpscr - fmov.s fr15, @-r15 /* note that we can't do double stores... */ - fmov.s fr14, @-r15 /* ...as we don't control stack alignment. */ - fmov.s fr13, @-r15 - fmov.s fr12, @-r15 - frchg - fmov.s fr15, @-r15 - fmov.s fr14, @-r15 - fmov.s fr13, @-r15 - fmov.s fr12, @-r15 -#endif - sts.l mach, @-r15 - sts.l macl, @-r15 - mov.l r8, @-r15 - mov.l r9, @-r15 - mov.l r10, @-r15 - mov.l r11, @-r15 - mov.l r12, @-r15 - mov.l r13, @-r15 - mov.l r14, @-r15 - sts.l pr, @-r15 - - /* - * Switch stacks. - */ - mov.l r15, @r5 - mov.l @r4, r15 - - /* - * Restore new context. - */ - lds.l @r15+, pr - mov.l @r15+, r14 - mov.l @r15+, r13 - mov.l @r15+, r12 - mov.l @r15+, r11 - mov.l @r15+, r10 - mov.l @r15+, r9 - mov.l @r15+, r8 - lds.l @r15+, macl -#if defined(__SH4__) && !defined(__SH4_NOFPU__) - mov #0, r1 - lds.l @r15+, mach - lds r1, fpscr - frchg - fmov.s @r15+, fr12 - fmov.s @r15+, fr13 - fmov.s @r15+, fr14 - fmov.s @r15+, fr15 - frchg - fmov.s @r15+, fr12 - fmov.s @r15+, fr13 - fmov.s @r15+, fr14 - fmov.s @r15+, fr15 - lds.l @r15+, fpul - rts - lds.l @r15+, fpscr -#else - rts - lds.l @r15+, mach -#endif diff --git a/lib/libpthread/arch/sparc/_atomic_lock.c b/lib/libpthread/arch/sparc/_atomic_lock.c deleted file mode 100644 index e45bb609837..00000000000 --- a/lib/libpthread/arch/sparc/_atomic_lock.c +++ /dev/null @@ -1,43 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.9 2008/10/02 23:27:23 deraadt Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Atomic lock for sparc - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t * lock) -{ - _spinlock_lock_t old; - - /* - * " ldstub [address], reg_rd - * - * The atomic load-store instructions copy a byte from memory - * into r[rd]m then rewrite the addressed byte in memory to all - * ones [_SPINLOCK_LOCKED]. The operation is performed - * atomically, that is, without allowing intervening interrupts - * or deferred traps. In a multiprocessor system, two or more - * processors executing atomic load-store unsigned byte [...] - * addressing the same byte [...] simultaneously are guaranteed - * to execute them in an undefined, but serial order." - * - p101, The SPARC Architecture Manual (version 8) Prentice-Hall - * - * "LDSTUB loads a byte value from memory to a register and writes - * the value FF_16 into the addressed byte atomically. LDSTUB - * is the classic test-and-set instruction. Like SWAP, it has - * a consensus number of two and so cannot resolve more than - * two contending processes in a wait-free fashion." - * - p129, The SPARC Architecture Manual (version 9) Prentice-Hall - * (See also section J.6 (spinlocks)) - * - * (No change to the condition codes are documented.) - */ - __asm__("ldstub %0,%1" - : "=m" (*lock), "=r" (old) - : "0" (*lock)); - - return (old == _SPINLOCK_LOCKED); -} diff --git a/lib/libpthread/arch/sparc/uthread_machdep.c b/lib/libpthread/arch/sparc/uthread_machdep.c deleted file mode 100644 index f7599ef4636..00000000000 --- a/lib/libpthread/arch/sparc/uthread_machdep.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.3 2003/01/31 04:46:16 marc Exp $ */ - -/* - * Machine-dependent thread state functions for OpenBSD/sparc. - */ - -#include <machine/frame.h> -#include <machine/param.h> -#include <pthread.h> -#include "pthread_private.h" - -extern void _thread_machdep_fpsave(u_int32_t *, u_int64_t *); -extern void _thread_machdep_fprestore(u_int32_t *, u_int64_t *); - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame *f; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((int)base + len - sizeof *f) & ~ALIGNBYTES); - - f->fr_fp = (struct frame *)-1; /* purposefully misaligned */ - f->fr_pc = -1; /* for gdb */ - statep->fp = (int)f; - statep->pc = -8 + (int)entry; -} - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ - _thread_machdep_fpsave(&statep->fs_csr, &statep->fs_regs[0]); -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ - _thread_machdep_fprestore(&statep->fs_csr, &statep->fs_regs[0]); -} diff --git a/lib/libpthread/arch/sparc/uthread_machdep.h b/lib/libpthread/arch/sparc/uthread_machdep.h deleted file mode 100644 index 087d47de53d..00000000000 --- a/lib/libpthread/arch/sparc/uthread_machdep.h +++ /dev/null @@ -1,11 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.6 2003/01/26 20:24:36 jason Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -struct _machdep_state { - int fp; /* frame pointer */ - int pc; /* program counter */ - - u_int32_t fs_csr; /* FP control/status */ - u_int32_t fs_enabled; /* enabled? */ - u_int64_t fs_regs[16]; /* 16 64bit registers */ -}; diff --git a/lib/libpthread/arch/sparc/uthread_machdep_asm.S b/lib/libpthread/arch/sparc/uthread_machdep_asm.S deleted file mode 100644 index 03baf530bef..00000000000 --- a/lib/libpthread/arch/sparc/uthread_machdep_asm.S +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.9 2004/02/02 20:43:37 brad Exp $ */ -/* David Leonard <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> -#include <machine/trap.h> - -/* - * Switch stacks. - * On sparc this also means we switch register windows. - */ - -#define SA(x) (((x)+7)&(~0x7)) -#define MINFRAME ((16+1+6)*4) - -/* - * void _thread_machdep_switch(newstate, oldstate); - * struct _machdep_state *newstate, *oldstate; - */ -ENTRY(_thread_machdep_switch) - - /* new window */ - save %sp, -SA(MINFRAME), %sp - - /* flush all windows (except current one) into memory frames */ - t ST_FLUSHWIN - - /* switch the stack pointer and return address */ - st %fp, [%i1 + 0] - st %i7, [%i1 + 4] - ld [%i0 + 0], %fp - ld [%i0 + 4], %i7 - - /* return to saved window at new %fp */ - ret - restore - -/* - * void _thread_machdep_fpsave(csr, regs) - * u_int32_t *csr; - * u_int64_t *regs; - */ -ENTRY(_thread_machdep_fpsave) - /* - * If %psr were readable, exitting could be faster. The EF - * bit is only set if the FPU is enabled, and we only need - * to save fpu state if it is enabled. But, RDPSR is a - * privileged instruction. - */ - - /* save registers */ - st %fsr, [%o0] - std %f0, [%o1 + 0 * 8] - std %f2, [%o1 + 1 * 8] - std %f4, [%o1 + 2 * 8] - std %f6, [%o1 + 3 * 8] - std %f8, [%o1 + 4 * 8] - std %f10, [%o1 + 5 * 8] - std %f12, [%o1 + 6 * 8] - std %f14, [%o1 + 7 * 8] - std %f16, [%o1 + 8 * 8] - std %f18, [%o1 + 9 * 8] - std %f20, [%o1 + 10 * 8] - std %f22, [%o1 + 11 * 8] - std %f24, [%o1 + 12 * 8] - std %f26, [%o1 + 13 * 8] - std %f28, [%o1 + 14 * 8] - std %f30, [%o1 + 15 * 8] - retl - nop - -/* - * void _thread_machdep_fprestore(csr, regs) - * u_int32_t *csr; - * u_int64_t *regs; - */ -ENTRY(_thread_machdep_fprestore) - ldd [%o1 + 0 * 8], %f0 - ldd [%o1 + 1 * 8], %f2 - ldd [%o1 + 2 * 8], %f4 - ldd [%o1 + 3 * 8], %f6 - ldd [%o1 + 4 * 8], %f8 - ldd [%o1 + 5 * 8], %f10 - ldd [%o1 + 6 * 8], %f12 - ldd [%o1 + 7 * 8], %f14 - ldd [%o1 + 8 * 8], %f16 - ldd [%o1 + 9 * 8], %f18 - ldd [%o1 + 10 * 8], %f20 - ldd [%o1 + 11 * 8], %f22 - ldd [%o1 + 12 * 8], %f24 - ldd [%o1 + 13 * 8], %f26 - ldd [%o1 + 14 * 8], %f28 - ldd [%o1 + 15 * 8], %f30 - ld [%o0], %fsr - /* ldfsr needs three instructions to be stable, ensure that here */ - nop - retl - nop diff --git a/lib/libpthread/arch/sparc64/_atomic_lock.c b/lib/libpthread/arch/sparc64/_atomic_lock.c deleted file mode 100644 index de4548fb3a8..00000000000 --- a/lib/libpthread/arch/sparc64/_atomic_lock.c +++ /dev/null @@ -1,43 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.5 2008/10/02 23:27:23 deraadt Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -/* - * Atomic lock for sparc64 - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t * lock) -{ - _spinlock_lock_t old; - - /* - * " ldstub [address], reg_rd - * - * The atomic load-store instructions copy a byte from memory - * into r[rd]m then rewrite the addressed byte in memory to all - * ones [_SPINLOCK_LOCKED]. The operation is performed - * atomically, that is, without allowing intervening interrupts - * or deferred traps. In a multiprocessor system, two or more - * processors executing atomic load-store unsigned byte [...] - * addressing the same byte [...] simultaneously are guaranteed - * to execute them in an undefined, but serial order." - * - p101, The SPARC Architecture Manual (version 8) Prentice-Hall - * - * "LDSTUB loads a byte value from memory to a register and writes - * the value FF_16 into the addressed byte atomically. LDSTUB - * is the classic test-and-set instruction. Like SWAP, it has - * a consensus number of two and so cannot resolve more than - * two contending processes in a wait-free fashion." - * - p129, The SPARC Architecture Manual (version 9) Prentice-Hall - * (See also section J.6 (spinlocks)) - * - * (No change to the condition codes are documented.) - */ - __asm__("ldstub %0,%1" - : "=m" (*lock), "=r" (old) - : "0" (*lock)); - - return (old == _SPINLOCK_LOCKED); -} diff --git a/lib/libpthread/arch/sparc64/uthread_machdep.c b/lib/libpthread/arch/sparc64/uthread_machdep.c deleted file mode 100644 index 06be142b4ee..00000000000 --- a/lib/libpthread/arch/sparc64/uthread_machdep.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.4 2004/02/02 10:05:55 brad Exp $ */ - -/* - * Machine-dependent thread state functions for OpenBSD/sparc64. - */ - -#include <sys/types.h> -#include <machine/frame.h> -#include <machine/param.h> -#include <pthread.h> -#include "pthread_private.h" - -/* - * Given a stack and an entry function, initialise a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(statep, base, len, entry) - struct _machdep_state* statep; - void *base; - int len; - void (*entry)(void); -{ - struct frame64 *f; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame64 *)(((long)base + len - sizeof *f) & ~ALIGNBYTES); - - f->fr_fp = 0; /* purposefully misaligned */ - f->fr_pc = -1; /* for gdb */ - statep->fp = (u_long)f - BIAS; - statep->pc = -8 + (u_long)entry; -} - -void -_thread_machdep_save_float_state(statep) - struct _machdep_state* statep; -{ - _thread_machdep_fpsave(&statep->fs_fprs); -} - -void -_thread_machdep_restore_float_state(statep) - struct _machdep_state* statep; -{ - _thread_machdep_fprestore(&statep->fs_fprs); -} diff --git a/lib/libpthread/arch/sparc64/uthread_machdep.h b/lib/libpthread/arch/sparc64/uthread_machdep.h deleted file mode 100644 index 4c746423983..00000000000 --- a/lib/libpthread/arch/sparc64/uthread_machdep.h +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.3 2003/01/24 21:05:45 jason Exp $ */ -/* Arutr Grabowski <art@openbsd.org>. Public domain. */ - -struct _machdep_state { - long fp; /* frame pointer */ - long pc; /* program counter */ - - /* floating point state */ - u_int64_t fs_fprs; /* fp register window status */ - u_int64_t fs_fsr; /* fp status */ - u_int64_t fs_regs[32]; /* 32 64 bit registers */ -}; - -extern void _thread_machdep_fpsave(u_int64_t *); -extern void _thread_machdep_fprestore(u_int64_t *); diff --git a/lib/libpthread/arch/sparc64/uthread_machdep_asm.S b/lib/libpthread/arch/sparc64/uthread_machdep_asm.S deleted file mode 100644 index 7b4ab4cea94..00000000000 --- a/lib/libpthread/arch/sparc64/uthread_machdep_asm.S +++ /dev/null @@ -1,135 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.9 2010/05/25 20:05:48 kettenis Exp $ */ -/* David Leonard <d@csee.uq.edu.au>. Public domain. */ - -#include <machine/asm.h> -#include <machine/trap.h> -#include <machine/frame.h> - -/* - * Switch stacks. - * - * On sparc64 this also means we switch register windows. - */ - -/* - * void _thread_machdep_switch(long newstate[2], long savestate[2], int flags); - */ -ENTRY(_thread_machdep_switch) - - /* new window */ - save %sp, -CC64FSZ, %sp - - /* flush all windows (except current one) into memory frames */ - flushw - - /* switch the stack pointer and return address */ - stx %fp, [%i1 + 0] - stx %i7, [%i1 + 8] - ldx [%i0 + 0], %fp - ldx [%i0 + 8], %i7 - - /* return to saved window at new %fp */ - ret - restore - -#define FPRS_ENA 0x4 /* fpu enabled */ -#define FPRS_DU 0x2 /* lower unit dirty */ -#define FPRS_DL 0x1 /* upper unit dirty */ - -ENTRY(_thread_machdep_fpsave) - rd %fprs, %o1 - stx %o1, [%o0] - andcc %o1, FPRS_ENA, %g0 - bz 1f - nop - - stx %fsr, [%o0 + 8] - add %o0, 16, %o0 - - std %f0, [%o0 + 0 * 8] /* store registers */ - std %f2, [%o0 + 1 * 8] - std %f4, [%o0 + 2 * 8] - std %f6, [%o0 + 3 * 8] - std %f8, [%o0 + 4 * 8] - std %f10, [%o0 + 5 * 8] - std %f12, [%o0 + 6 * 8] - std %f14, [%o0 + 7 * 8] - std %f16, [%o0 + 8 * 8] - std %f18, [%o0 + 9 * 8] - std %f20, [%o0 + 10 * 8] - std %f22, [%o0 + 11 * 8] - std %f24, [%o0 + 12 * 8] - std %f26, [%o0 + 13 * 8] - std %f28, [%o0 + 14 * 8] - std %f30, [%o0 + 15 * 8] - - std %f32, [%o0 + 16 * 8] /* store registers */ - std %f34, [%o0 + 17 * 8] - std %f36, [%o0 + 18 * 8] - std %f38, [%o0 + 19 * 8] - std %f40, [%o0 + 20 * 8] - std %f42, [%o0 + 21 * 8] - std %f44, [%o0 + 22 * 8] - std %f46, [%o0 + 23 * 8] - std %f48, [%o0 + 24 * 8] - std %f50, [%o0 + 25 * 8] - std %f52, [%o0 + 26 * 8] - std %f54, [%o0 + 27 * 8] - std %f56, [%o0 + 28 * 8] - std %f58, [%o0 + 29 * 8] - std %f60, [%o0 + 30 * 8] - std %f62, [%o0 + 31 * 8] - - /* disable fpu and mark both sides clean */ - wr %g0, 0, %fprs - -1: - retl - nop - -ENTRY(_thread_machdep_fprestore) - ldx [%o0], %o1 /* o1 = fprs */ - andcc %o1, FPRS_ENA, %g0 - bz 1f - nop - - wr %o1, 0, %fprs - ldx [%o0 + 8], %fsr - add %o0, 16, %o0 - - ldd [%o0 + 0 * 8], %f0 - ldd [%o0 + 1 * 8], %f2 - ldd [%o0 + 2 * 8], %f4 - ldd [%o0 + 3 * 8], %f6 - ldd [%o0 + 4 * 8], %f8 - ldd [%o0 + 5 * 8], %f10 - ldd [%o0 + 6 * 8], %f12 - ldd [%o0 + 7 * 8], %f14 - ldd [%o0 + 8 * 8], %f16 - ldd [%o0 + 9 * 8], %f18 - ldd [%o0 + 10 * 8], %f20 - ldd [%o0 + 11 * 8], %f22 - ldd [%o0 + 12 * 8], %f24 - ldd [%o0 + 13 * 8], %f26 - ldd [%o0 + 14 * 8], %f28 - ldd [%o0 + 15 * 8], %f30 - - ldd [%o0 + 16 * 8], %f32 - ldd [%o0 + 17 * 8], %f34 - ldd [%o0 + 18 * 8], %f36 - ldd [%o0 + 19 * 8], %f38 - ldd [%o0 + 20 * 8], %f40 - ldd [%o0 + 21 * 8], %f42 - ldd [%o0 + 22 * 8], %f44 - ldd [%o0 + 23 * 8], %f46 - ldd [%o0 + 24 * 8], %f48 - ldd [%o0 + 25 * 8], %f50 - ldd [%o0 + 26 * 8], %f52 - ldd [%o0 + 27 * 8], %f54 - ldd [%o0 + 28 * 8], %f56 - ldd [%o0 + 29 * 8], %f58 - ldd [%o0 + 30 * 8], %f60 - ldd [%o0 + 31 * 8], %f62 -1: - retl - nop diff --git a/lib/libpthread/arch/vax/_atomic_lock.c b/lib/libpthread/arch/vax/_atomic_lock.c deleted file mode 100644 index 5a9736995fe..00000000000 --- a/lib/libpthread/arch/vax/_atomic_lock.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $OpenBSD: _atomic_lock.c,v 1.4 2003/05/19 18:31:49 miod Exp $ */ - -/* - * Atomic lock for vax - * Written by Miodrag Vallat <miod@openbsd.org> - placed in the public domain. - */ - -#include "spinlock.h" - -int -_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - - /* - * The Branch on Bit Set and Set Interlocked instruction - * sets a given bit in a register or a memory location, as an - * atomic, interlocked operation. - * If the bit was set, execution continues at the branch - * location. - * - * For more details, please refer to the Vax Architecture - * Reference Manual, chapter 3 (Instructions), section - * ``Control instructions''. - */ - __asm__ ( - "movl $1, %1\n" /* _SPINLOCK_LOCKED */ - "bbssi $0, %0, 1f\n" - "movl $0, %1\n" /* _SPINLOCK_UNLOCKED */ - "1: \n" - : "=m" (*lock), "=r" (old) : "0" (*lock) - ); - - return (old != _SPINLOCK_UNLOCKED); -} - -int -_atomic_is_locked(volatile _spinlock_lock_t *lock) -{ - - return (*lock != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/arch/vax/uthread_machdep.c b/lib/libpthread/arch/vax/uthread_machdep.c deleted file mode 100644 index 0315cec578a..00000000000 --- a/lib/libpthread/arch/vax/uthread_machdep.c +++ /dev/null @@ -1,72 +0,0 @@ -/* $OpenBSD: uthread_machdep.c,v 1.2 2003/05/27 22:59:33 miod Exp $ */ - -/* - * Machine-dependent thread state functions for OpenBSD/vax - * Written by Miodrag Vallat <miod@openbsd.org> - placed in the public domain. - */ - -#include <pthread.h> -#include "pthread_private.h" - -/* XXX we need <machine/asm.h> but it conflicts with <machine/cdefs.h> */ -#undef _C_LABEL -#undef WEAK_ALIAS -#include <machine/asm.h> - -#define ALIGNBYTES 3 - -struct frame { - /* a CALLS frame */ - long condition; /* sp and fp point here */ - long psw; - long ap; /* r12 */ - long fp; /* r13 */ - long pc; /* r15 */ - long r[10]; /* r2 - r11 */ - long numarg; /* ap points here */ -}; - -/* - * Given a stack and an entry function, initialize a state - * structure that can be later switched to. - */ -void -_thread_machdep_init(struct _machdep_state* statep, void *base, int len, - void (*entry)(void)) -{ - struct frame *f; - - /* Locate the initial frame, aligned at the top of the stack */ - f = (struct frame *)(((long)base + len - sizeof *f) & ~ALIGNBYTES); - - /* Set up initial frame */ - f->condition = 0; - f->psw = (1 << 29) /* CALLS */ | - ((R2|R3|R4|R5|R6|R7|R8|R9|R10|R11) << 16); - f->ap = (long)&f->numarg; - f->fp = (long)f; - - /* - * DANGER WILL ROBINSON! The thread entry point is a CALLS target - * routine, hence it starts with two bytes being the entry - * mask. We rely here upon the following facts: - * - MI code will always pass _thread_start as the entry argument - * - the entry mask for _thread_start is zero (no registers saved) - */ - f->pc = (long)entry + 2; /* skip entry mask */ - f->numarg = 0; /* safety */ - - statep->frame = f->fp; -} - -void -_thread_machdep_save_float_state(struct _machdep_state* statep) -{ - /* nothing to do */ -} - -void -_thread_machdep_restore_float_state(struct _machdep_state* statep) -{ - /* nothing to do */ -} diff --git a/lib/libpthread/arch/vax/uthread_machdep.h b/lib/libpthread/arch/vax/uthread_machdep.h deleted file mode 100644 index 75fefff1655..00000000000 --- a/lib/libpthread/arch/vax/uthread_machdep.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: uthread_machdep.h,v 1.1 2001/01/27 21:23:57 hugh Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -struct _machdep_state { - int frame; -}; diff --git a/lib/libpthread/arch/vax/uthread_machdep_asm.S b/lib/libpthread/arch/vax/uthread_machdep_asm.S deleted file mode 100644 index b423a08ca93..00000000000 --- a/lib/libpthread/arch/vax/uthread_machdep_asm.S +++ /dev/null @@ -1,18 +0,0 @@ -/* $OpenBSD: uthread_machdep_asm.S,v 1.1 2003/05/27 22:59:33 miod Exp $ */ - -#include <machine/asm.h> - -/* - * Switch stacks - * Written by Miodrag Vallat <miod@openbsd.org> - placed in the public domain. - */ - -/* void _thread_machdep_switch(new, oldsave); */ -ENTRY(_thread_machdep_switch, R2|R3|R4|R5|R6|R7|R8|R9|R10|R11) - movl 8(ap), r0 /* r0 = oldsave */ - movl fp, 0(r0) /* save fp */ - - movl 4(ap), r0 /* r0 = new */ - movl 0(r0), fp - - ret diff --git a/lib/libpthread/sys/Makefile.inc b/lib/libpthread/sys/Makefile.inc deleted file mode 100644 index 10fcfe22961..00000000000 --- a/lib/libpthread/sys/Makefile.inc +++ /dev/null @@ -1,15 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.18 2010/02/03 20:49:00 miod Exp $ - -.PATH: ${SRCDIR}/sys ${SRCDIR}/arch/${MACHINE_CPU} - -SRCS+= uthread_error.c - -.if exists(${SRCDIR}/arch/${MACHINE_CPU}/_atomic_lock.c) -SRCS+= _atomic_lock.c -.endif -.if exists(${SRCDIR}/arch/${MACHINE_CPU}/uthread_machdep_asm.S) -SRCS+= uthread_machdep_asm.S -.endif -.if exists(${SRCDIR}/arch/${MACHINE_CPU}/uthread_machdep.c) -SRCS+= uthread_machdep.c -.endif diff --git a/lib/libpthread/sys/slow_atomic_lock.c b/lib/libpthread/sys/slow_atomic_lock.c deleted file mode 100644 index d8526229dac..00000000000 --- a/lib/libpthread/sys/slow_atomic_lock.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $OpenBSD: slow_atomic_lock.c,v 1.4 2008/10/02 23:27:23 deraadt Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <pthread.h> -#include "pthread_private.h" -#include "spinlock.h" -#include <signal.h> - -/* - * uthread atomic lock: - * attempt to acquire a lock (by giving it a non-zero value). - * Return zero on success, or the lock's value on failure - * This uses signal masking to make sure that no other thread - * can modify the lock while processing, hence it is very slow. - */ -int -_thread_slow_atomic_lock(volatile _spinlock_lock_t *lock) -{ - _spinlock_lock_t old; - sigset_t oldset, newset = (sigset_t)~0; - - /* block signals - incurs a context switch */ - if (_thread_sys_sigprocmask(SIG_SETMASK, &newset, &oldset) < 0) - PANIC("_atomic_lock block"); - - old = *lock; - if (old == _SPINLOCK_UNLOCKED) - *lock = _SPINLOCK_LOCKED; - - /* restore signal mask to what it was */ - if (_thread_sys_sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) - PANIC("_atomic_lock restore"); - - return (old != _SPINLOCK_UNLOCKED); -} - -int -_thread_slow_atomic_is_locked(volatile _spinlock_lock_t *lock) -{ - - return (*lock != _SPINLOCK_UNLOCKED); -} diff --git a/lib/libpthread/sys/uthread_error.c b/lib/libpthread/sys/uthread_error.c deleted file mode 100644 index 739d3abf347..00000000000 --- a/lib/libpthread/sys/uthread_error.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: uthread_error.c,v 1.3 2003/01/31 04:46:17 marc Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell - * and Chris Provenzano. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_error.c,v 1.2 1999/08/05 12:14:13 deischen Exp $ - */ -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -extern int errno; - -int * -__error(void) -{ - int *p_errno; - if (_thread_run == _thread_initial) { - p_errno = &errno; - } else { - p_errno = &_thread_run->error; - } - return(p_errno); -} -#endif diff --git a/lib/libpthread/thread/Makefile.inc b/lib/libpthread/thread/Makefile.inc deleted file mode 100644 index a7f50b57a01..00000000000 --- a/lib/libpthread/thread/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.7 2007/06/05 18:11:48 kurt Exp $ - -.PATH: ${SRCDIR}/thread - -SRCS+= thread_tag.c thread_malloc_lock.c thread_mutex.c diff --git a/lib/libpthread/thread/thread_malloc_lock.c b/lib/libpthread/thread/thread_malloc_lock.c deleted file mode 100644 index 6c2057b708e..00000000000 --- a/lib/libpthread/thread/thread_malloc_lock.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $OpenBSD: thread_malloc_lock.c,v 1.7 2008/06/13 21:18:43 otto Exp $ */ -/* Public Domain <marc@snafu.org> */ - -#include <pthread.h> -#include "pthread_private.h" - -static spinlock_t malloc_lock = _SPINLOCK_INITIALIZER; -static spinlock_t atexit_lock = _SPINLOCK_INITIALIZER; -static spinlock_t arc4_lock = _SPINLOCK_INITIALIZER; - -void -_thread_malloc_lock() -{ - _SPINLOCK(&malloc_lock); -} - -void -_thread_malloc_unlock() -{ - _SPINUNLOCK(&malloc_lock); -} - -void -_thread_atexit_lock() -{ - _SPINLOCK(&atexit_lock); -} - -void -_thread_atexit_unlock() -{ - _SPINUNLOCK(&atexit_lock); -} - -void -_thread_arc4_lock() -{ - _SPINLOCK(&arc4_lock); -} - -void -_thread_arc4_unlock() -{ - _SPINUNLOCK(&arc4_lock); -} diff --git a/lib/libpthread/thread/thread_mutex.c b/lib/libpthread/thread/thread_mutex.c deleted file mode 100644 index 979a2e2e3fc..00000000000 --- a/lib/libpthread/thread/thread_mutex.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: thread_mutex.c,v 1.1 2007/06/05 18:11:48 kurt Exp $ */ - -/* - * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/types.h> -#include "thread_private.h" -#include "pthread.h" -#include "pthread_private.h" - -void -_thread_mutex_lock(void **mutex) -{ - pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex; - - if (pthread_mutex_lock(pmutex) != 0) - PANIC("mutex lock failure"); -} - -void -_thread_mutex_unlock(void **mutex) -{ - pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex; - - if (pthread_mutex_unlock(pmutex) != 0) - PANIC("mutex unlock failure"); -} - -void -_thread_mutex_destroy(void **mutex) -{ - pthread_mutex_t *pmutex = (pthread_mutex_t *)mutex; - - if (pthread_mutex_destroy(pmutex) != 0) - PANIC("mutex destroy failure"); -} diff --git a/lib/libpthread/thread/thread_tag.c b/lib/libpthread/thread/thread_tag.c deleted file mode 100644 index 8f7f427aa8d..00000000000 --- a/lib/libpthread/thread/thread_tag.c +++ /dev/null @@ -1,121 +0,0 @@ -/* $OpenBSD: thread_tag.c,v 1.3 2007/06/05 16:30:13 kurt Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ - -#include <sys/time.h> - -#include <stdlib.h> -#include <string.h> - -#include "thread_private.h" -#include "pthread.h" -#include "pthread_private.h" - -/* - * A thread tag is a pointer to a structure of this type. An opaque - * tag is used to decouple libc from the thread library. - */ -struct _thread_tag { - pthread_mutex_t m; /* the tag's mutex */ - pthread_key_t k; /* a key for private data */ -}; - -/* - * local mutex to protect against tag creation races. - */ -static pthread_mutex_t _thread_tag_mutex = PTHREAD_MUTEX_INITIALIZER; - -/* - * Initialize a thread tag structure once. This function is called - * if the tag is null. Allocation and initialization are controlled - * by a mutex. If the tag is not null when the mutex is obtained - * the caller lost a race -- some other thread initialized the tag. - * This function will never return NULL. - */ -static void -_thread_tag_init(void **tag) -{ - struct _thread_tag *tt; - int result; - - result = pthread_mutex_lock(&_thread_tag_mutex); - if (result == 0) { - if (*tag == NULL) { - tt = malloc(sizeof *tt); - if (tt != NULL) { - result = pthread_mutex_init(&tt->m, NULL); - result |= pthread_key_create(&tt->k, free); - *tag = tt; - } - } - result |= pthread_mutex_unlock(&_thread_tag_mutex); - } - if (result != 0) - PANIC(__func__); -} - -/* - * lock the mutex associated with the given tag - */ -void -_thread_tag_lock(void **tag) -{ - struct _thread_tag *tt; - - if (__isthreaded) { - if (*tag == NULL) - _thread_tag_init(tag); - tt = *tag; - if (pthread_mutex_lock(&tt->m) != 0) - PANIC(__func__); - } -} - -/* - * unlock the mutex associated with the given tag - */ -void -_thread_tag_unlock(void **tag) -{ - struct _thread_tag *tt; - - if (__isthreaded) { - if (*tag == NULL) - _thread_tag_init(tag); - tt = *tag; - if (pthread_mutex_unlock(&tt->m) != 0) - PANIC(__func__); - } -} - -/* - * return the thread specific data for the given tag. If there - * is no data for this thread initialize it from 'storage'. - * On any error return 'err'. - */ -void * -_thread_tag_storage(void **tag, void *storage, size_t sz, void *err) -{ - struct _thread_tag *tt; - void *ret; - - if (*tag == NULL) - _thread_tag_init(tag); - tt = *tag; - - ret = pthread_getspecific(tt->k); - if (ret == NULL) { - ret = malloc(sz); - if (ret == NULL) - ret = err; - else { - if (pthread_setspecific(tt->k, ret) == 0) - memcpy(ret, storage, sz); - else { - free(ret); - ret = err; - } - } - } - return ret; -} diff --git a/lib/libpthread/uthread/Makefile.inc b/lib/libpthread/uthread/Makefile.inc deleted file mode 100644 index 573a5c64417..00000000000 --- a/lib/libpthread/uthread/Makefile.inc +++ /dev/null @@ -1,143 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.24 2012/01/17 02:52:39 guenther Exp $ -# $FreeBSD: Makefile.inc,v 1.19 1999/08/28 00:03:19 peter Exp $ - -# uthread sources -.PATH: ${SRCDIR}/uthread - -CFLAGS += -I${SRCDIR}/arch/${MACHINE_CPU} - -SRCS+= \ - sched_prio.c \ - uthread_accept.c \ - uthread_atfork.c \ - uthread_attr_destroy.c \ - uthread_attr_init.c \ - uthread_attr_getdetachstate.c \ - uthread_attr_getguardsize.c \ - uthread_attr_getinheritsched.c \ - uthread_attr_getschedparam.c \ - uthread_attr_getschedpolicy.c \ - uthread_attr_getscope.c \ - uthread_attr_getstack.c \ - uthread_attr_getstackaddr.c \ - uthread_attr_getstacksize.c \ - uthread_attr_setcreatesuspend_np.c \ - uthread_attr_setdetachstate.c \ - uthread_attr_setguardsize.c \ - uthread_attr_setinheritsched.c \ - uthread_attr_setschedparam.c \ - uthread_attr_setschedpolicy.c \ - uthread_attr_setscope.c \ - uthread_attr_setstack.c \ - uthread_attr_setstackaddr.c \ - uthread_attr_setstacksize.c \ - uthread_autoinit.c \ - uthread_bind.c \ - uthread_cancel.c \ - uthread_clean.c \ - uthread_close.c \ - uthread_closefrom.c \ - uthread_concurrency.c \ - uthread_cond.c \ - uthread_condattr_destroy.c \ - uthread_condattr_init.c \ - uthread_connect.c \ - uthread_create.c \ - uthread_detach.c \ - uthread_dup.c \ - uthread_dup2.c \ - uthread_equal.c \ - uthread_execve.c \ - uthread_exit.c \ - uthread_fchflags.c \ - uthread_fchmod.c \ - uthread_fchown.c \ - uthread_fcntl.c \ - uthread_fd.c \ - uthread_file.c \ - uthread_find_thread.c \ - uthread_flock.c \ - uthread_fork.c \ - uthread_fpathconf.c \ - uthread_fstat.c \ - uthread_fstatfs.c \ - uthread_fsync.c \ - uthread_ftruncate.c \ - uthread_gc.c \ - uthread_getdirentries.c \ - uthread_getpeername.c \ - uthread_getprio.c \ - uthread_getschedparam.c \ - uthread_getsockname.c \ - uthread_getsockopt.c \ - uthread_info_openbsd.c \ - uthread_init.c \ - uthread_ioctl.c \ - uthread_join.c \ - uthread_kern.c \ - uthread_kevent.c \ - uthread_kill.c \ - uthread_kqueue.c \ - uthread_listen.c \ - uthread_lseek.c \ - uthread_main_np.c \ - uthread_mattr_init.c \ - uthread_mattr_kind_np.c \ - uthread_msync.c \ - uthread_multi_np.c \ - uthread_mutex.c \ - uthread_mutex_prioceiling.c \ - uthread_mutex_protocol.c \ - uthread_mutexattr_destroy.c \ - uthread_nanosleep.c \ - uthread_once.c \ - uthread_open.c \ - uthread_openat.c \ - uthread_pipe.c \ - uthread_poll.c \ - uthread_pread.c \ - uthread_preadv.c \ - uthread_priority_queue.c \ - uthread_pwrite.c \ - uthread_pwritev.c \ - uthread_read.c \ - uthread_readv.c \ - uthread_recvfrom.c \ - uthread_recvmsg.c \ - uthread_resume_np.c \ - uthread_rwlock.c \ - uthread_rwlockattr.c \ - uthread_select.c \ - uthread_self.c \ - uthread_sem.c \ - uthread_sendmsg.c \ - uthread_sendto.c \ - uthread_seterrno.c \ - uthread_setprio.c \ - uthread_setschedparam.c \ - uthread_setsockopt.c \ - uthread_shutdown.c \ - uthread_sig.c \ - uthread_sigaction.c \ - uthread_sigaltstack.c \ - uthread_sigblock.c \ - uthread_sigmask.c \ - uthread_sigpending.c \ - uthread_sigprocmask.c \ - uthread_sigsetmask.c \ - uthread_sigsuspend.c \ - uthread_sigwait.c \ - uthread_single_np.c \ - uthread_socket.c \ - uthread_socketpair.c \ - uthread_spec.c \ - uthread_spinlock.c \ - uthread_stack.c \ - uthread_stackseg_np.c \ - uthread_suspend_np.c \ - uthread_switch_np.c \ - uthread_vfork.c \ - uthread_wait4.c \ - uthread_write.c \ - uthread_writev.c \ - uthread_yield.c diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h deleted file mode 100644 index 457de4247e0..00000000000 --- a/lib/libpthread/uthread/pthread_private.h +++ /dev/null @@ -1,1400 +0,0 @@ -/* $OpenBSD: pthread_private.h,v 1.79 2012/01/17 02:52:39 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Private thread definitions for the uthread kernel. - * - * $FreeBSD: pthread_private.h,v 1.27 1999/09/29 15:18:38 marcel Exp $ - */ - -#ifndef _PTHREAD_PRIVATE_H -#define _PTHREAD_PRIVATE_H - -/* - * Evaluate the storage class specifier. - */ -#ifdef GLOBAL_PTHREAD_PRIVATE -#define SCLASS -#else -#define SCLASS extern -#endif - -/* - * Include files. - */ -#include <signal.h> -#include <stdio.h> -#include <sys/poll.h> -#include <sys/queue.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sched.h> -#include <spinlock.h> -#include <pthread_np.h> -#include "thread_private.h" -#include "uthread_machdep.h" - -/* - * Kernel fatal error handler macro. - */ -#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) - -/* Output debug messages like this: */ -#define stdout_debug(_x) _thread_sys_write(1,_x,strlen(_x)); -#define stderr_debug(_x) _thread_sys_write(2,_x,strlen(_x)); - - -/* - * Priority queue manipulation macros (using pqe link): - */ -#define PTHREAD_PRIOQ_INSERT_HEAD(thrd) _pq_insert_head(&_readyq,thrd) -#define PTHREAD_PRIOQ_INSERT_TAIL(thrd) _pq_insert_tail(&_readyq,thrd) -#define PTHREAD_PRIOQ_REMOVE(thrd) _pq_remove(&_readyq,thrd) -#define PTHREAD_PRIOQ_FIRST() _pq_first(&_readyq) - -/* - * Waiting queue manipulation macros (using pqe link): - */ -#define PTHREAD_WAITQ_REMOVE(thrd) _waitq_remove(thrd) -#define PTHREAD_WAITQ_INSERT(thrd) _waitq_insert(thrd) - -#if defined(_PTHREADS_INVARIANTS) -#define PTHREAD_WAITQ_CLEARACTIVE() _waitq_clearactive() -#define PTHREAD_WAITQ_SETACTIVE() _waitq_setactive() -#else -#define PTHREAD_WAITQ_CLEARACTIVE() -#define PTHREAD_WAITQ_SETACTIVE() -#endif - -/* - * Work queue manipulation macros (using qe link): - */ -#define PTHREAD_WORKQ_INSERT(thrd) do { \ - TAILQ_INSERT_TAIL(&_workq,thrd,qe); \ - (thrd)->flags |= PTHREAD_FLAGS_IN_WORKQ; \ -} while (0) -#define PTHREAD_WORKQ_REMOVE(thrd) do { \ - TAILQ_REMOVE(&_workq,thrd,qe); \ - (thrd)->flags &= ~PTHREAD_FLAGS_IN_WORKQ; \ -} while (0) - - -/* - * State change macro without scheduling queue change: - */ -#define PTHREAD_SET_STATE(thrd, newstate) do { \ - (thrd)->state = newstate; \ - (thrd)->fname = __FILE__; \ - (thrd)->lineno = __LINE__; \ -} while (0) - -/* - * State change macro with scheduling queue change - This must be - * called with preemption deferred (see thread_kern_sched_[un]defer). - */ -#if defined(_PTHREADS_INVARIANTS) -#include <assert.h> -#define PTHREAD_ASSERT(cond, msg) do { \ - if (!(cond)) \ - PANIC(msg); \ -} while (0) -#define PTHREAD_ASSERT_NOT_IN_SYNCQ(thrd) \ - PTHREAD_ASSERT((((thrd)->flags & PTHREAD_FLAGS_IN_SYNCQ) == 0), \ - "Illegal call from signal handler"); -#define PTHREAD_NEW_STATE(thrd, newstate) do { \ - if (_thread_kern_new_state != 0) \ - PANIC("Recursive PTHREAD_NEW_STATE"); \ - _thread_kern_new_state = 1; \ - if ((thrd)->state != newstate) { \ - if ((thrd)->state == PS_RUNNING) { \ - PTHREAD_PRIOQ_REMOVE(thrd); \ - PTHREAD_WAITQ_INSERT(thrd); \ - } else if (newstate == PS_RUNNING) { \ - PTHREAD_WAITQ_REMOVE(thrd); \ - PTHREAD_PRIOQ_INSERT_TAIL(thrd); \ - } \ - } \ - _thread_kern_new_state = 0; \ - PTHREAD_SET_STATE(thrd, newstate); \ -} while (0) -#else -#define PTHREAD_ASSERT(cond, msg) -#define PTHREAD_ASSERT_NOT_IN_SYNCQ(thrd) -#define PTHREAD_NEW_STATE(thrd, newstate) do { \ - if ((thrd)->state != newstate) { \ - if ((thrd)->state == PS_RUNNING) { \ - PTHREAD_PRIOQ_REMOVE(thrd); \ - PTHREAD_WAITQ_INSERT(thrd); \ - } else if (newstate == PS_RUNNING) { \ - PTHREAD_WAITQ_REMOVE(thrd); \ - PTHREAD_PRIOQ_INSERT_TAIL(thrd); \ - } \ - } \ - PTHREAD_SET_STATE(thrd, newstate); \ -} while (0) -#endif - -/* - * Define the signals to be used for scheduling. - */ -#if defined(_PTHREADS_COMPAT_SCHED) || defined(PROF) -#define _ITIMER_SCHED_TIMER ITIMER_VIRTUAL -#define _SCHED_SIGNAL SIGVTALRM -#else -#define _ITIMER_SCHED_TIMER ITIMER_PROF -#define _SCHED_SIGNAL SIGPROF -#endif - -/* Lists with volatile elements */ -#define V_TAILQ_HEAD(name, type) \ -volatile struct name { \ - struct type * tqh_first; \ - struct type * volatile * tqh_last; \ -} - -#define V_TAILQ_ENTRY(type) \ -volatile struct { \ - struct type * tqe_next; \ - struct type * volatile * tqe_prev; \ -} - -/* List of all threads: */ -typedef V_TAILQ_HEAD(, pthread) _thread_list_t; - -/* - * Priority queues. - * - * XXX It'd be nice if these were contained in uthread_priority_queue.[ch]. - */ -typedef struct pq_list { - _thread_list_t pl_head; /* list of threads at this priority */ - TAILQ_ENTRY(pq_list) pl_link; /* link for queue of priority lists */ - int pl_prio; /* the priority of this list */ - int pl_queued; /* is this in the priority queue */ -} pq_list_t; - -typedef struct pq_queue { - TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */ - pq_list_t *pq_lists; /* array of all priority lists */ - int pq_size; /* number of priority lists */ -} pq_queue_t; - - -/* - * TailQ initialization values. - */ -#define TAILQ_INITIALIZER { NULL, NULL } - -/* - * Mutex definitions. - */ -union pthread_mutex_data { - void *m_ptr; - int m_count; -}; - -struct pthread_mutex { - enum pthread_mutextype m_type; - int m_protocol; - V_TAILQ_HEAD(mutex_head, pthread) m_queue; - struct pthread *m_owner; - union pthread_mutex_data m_data; - long m_flags; - int m_refcount; - - /* - * Used for priority inheritence and protection. - * - * m_prio - For priority inheritence, the highest active - * priority (threads locking the mutex inherit - * this priority). For priority protection, the - * ceiling priority of this mutex. - * m_saved_prio - mutex owners inherited priority before - * taking the mutex, restored when the owner - * unlocks the mutex. - */ - int m_prio; - int m_saved_prio; - - /* - * Link for list of all mutexes a thread currently owns. - */ - V_TAILQ_ENTRY(pthread_mutex volatile) m_qe; - - /* - * Lock for accesses to this structure. - */ - spinlock_t lock; -}; - -/* - * Flags for mutexes. - */ -#define MUTEX_FLAGS_PRIVATE 0x01 -#define MUTEX_FLAGS_INITED 0x02 -#define MUTEX_FLAGS_BUSY 0x04 - -/* - * Static mutex initialization values. - */ -#define PTHREAD_MUTEX_STATIC_INITIALIZER \ - { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, TAILQ_INITIALIZER, \ - NULL, { NULL }, MUTEX_FLAGS_PRIVATE, 0, 0, 0, TAILQ_INITIALIZER, \ - _SPINLOCK_INITIALIZER } - -struct pthread_mutex_attr { - enum pthread_mutextype m_type; - int m_protocol; - int m_ceiling; - long m_flags; -}; - -#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ - { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } - -/* - * Condition variable definitions. - */ -enum pthread_cond_type { - COND_TYPE_FAST, - COND_TYPE_MAX -}; - -struct pthread_cond { - enum pthread_cond_type c_type; - V_TAILQ_HEAD(cond_head, pthread) c_queue; - pthread_mutex_t c_mutex; - long c_flags; - int c_seqno; - - /* - * Lock for accesses to this structure. - */ - spinlock_t lock; -}; - -struct pthread_cond_attr { - enum pthread_cond_type c_type; - long c_flags; -}; - -/* - * Flags for condition variables. - */ -#define COND_FLAGS_PRIVATE 0x01 -#define COND_FLAGS_INITED 0x02 -#define COND_FLAGS_BUSY 0x04 - -/* - * Static cond initialization values. - */ -#define PTHREAD_COND_STATIC_INITIALIZER \ - { COND_TYPE_FAST, TAILQ_INITIALIZER, NULL, NULL, \ - 0, 0, _SPINLOCK_INITIALIZER } - -/* - * Semaphore definitions. - */ -struct sem { -#define SEM_MAGIC ((u_int32_t) 0x09fa4012) - u_int32_t magic; - pthread_mutex_t lock; - pthread_cond_t gtzero; - u_int32_t count; - u_int32_t nwaiters; -}; - -/* - * Cleanup definitions. - */ -struct pthread_cleanup { - struct pthread_cleanup *next; - void (*routine)(void*); - void *routine_arg; -}; - -struct pthread_atfork { - TAILQ_ENTRY(pthread_atfork) qe; - void (*prepare)(void); - void (*parent)(void); - void (*child)(void); -}; - -struct pthread_attr { - int sched_policy; - int sched_inherit; - int sched_interval; - int prio; - int suspend; - int flags; - void *arg_attr; - void (*cleanup_attr)(void*); - void *stackaddr_attr; - size_t stacksize_attr; - size_t guardsize_attr; -}; - -/* - * Thread creation state attributes. - */ -#define PTHREAD_CREATE_RUNNING 0 -#define PTHREAD_CREATE_SUSPENDED 1 - -/* - * Additional state for a thread suspended with pthread_suspend_np(). - */ -enum pthread_susp { - SUSP_NO, /* Not suspended. */ - SUSP_YES, /* Suspended. */ - SUSP_JOIN, /* Suspended, joining. */ - SUSP_NOWAIT, /* Suspended, was in a mutex or condition queue. */ - SUSP_MUTEX_WAIT,/* Suspended, still in a mutex queue. */ - SUSP_COND_WAIT /* Suspended, still in a condition queue. */ -}; - -/* - * Miscellaneous definitions. - */ -#ifdef __LP64__ -#define PTHREAD_STACK_DEFAULT (512 * 1024) -#else -#define PTHREAD_STACK_DEFAULT (256 * 1024) -#endif - -/* - * Maximum size of initial thread's stack. This perhaps deserves to be larger - * than the stacks of other threads, since many applications are likely to run - * almost entirely on this stack. - */ -#define PTHREAD_STACK_INITIAL 0x100000 - -/* - * Define the different priority ranges. All applications have thread - * priorities constrained within 0-31. The threads library raises the - * priority when delivering signals in order to ensure that signal - * delivery happens (from the POSIX spec) "as soon as possible". - * In the future, the threads library will also be able to map specific - * threads into real-time (cooperating) processes or kernel threads. - * The RT and SIGNAL priorities will be used internally and added to - * thread base priorities so that the scheduling queue can handle both - * normal and RT priority threads with and without signal handling. - * - * The approach taken is that, within each class, signal delivery - * always has priority over thread execution. - */ -#define PTHREAD_DEFAULT_PRIORITY 15 -#define PTHREAD_MIN_PRIORITY 0 -#define PTHREAD_MAX_PRIORITY 31 /* 0x1F */ -#define PTHREAD_SIGNAL_PRIORITY 32 /* 0x20 */ -#define PTHREAD_RT_PRIORITY 64 /* 0x40 */ -#define PTHREAD_FIRST_PRIORITY PTHREAD_MIN_PRIORITY -#define PTHREAD_LAST_PRIORITY \ - (PTHREAD_MAX_PRIORITY + PTHREAD_SIGNAL_PRIORITY + PTHREAD_RT_PRIORITY) -#define PTHREAD_BASE_PRIORITY(prio) ((prio) & PTHREAD_MAX_PRIORITY) - -/* - * Clock resolution in microseconds. - */ -#define CLOCK_RES_USEC 10000 -#define CLOCK_RES_USEC_MIN 1000 - -/* - * Time slice period in microseconds. - */ -#define TIMESLICE_USEC 20000 - -/* - * Define a thread-safe macro to get the current time of day - * which is updated at regular intervals by the scheduling signal - * handler. - */ -#define GET_CURRENT_TOD(tv) \ - do { \ - tv.tv_sec = _sched_tod.tv_sec; \ - tv.tv_usec = _sched_tod.tv_usec; \ - } while (tv.tv_sec != _sched_tod.tv_sec) - - -struct pthread_key { - spinlock_t lock; - volatile int allocated; - volatile int count; - void (*destructor)(void*); -}; - -struct pthread_rwlockattr { - int pshared; -}; - -struct pthread_rwlock { - pthread_mutex_t lock; /* monitor lock */ - int state; /* 0 = idle >0 = # of readers -1 = writer */ - pthread_cond_t read_signal; - pthread_cond_t write_signal; - int blocked_writers; -}; - -/* - * Thread states. - */ -enum pthread_state { - PS_RUNNING, - PS_SIGTHREAD, - PS_MUTEX_WAIT, - PS_COND_WAIT, - PS_FDLR_WAIT, - PS_FDLW_WAIT, - PS_FDR_WAIT, - PS_FDW_WAIT, - PS_FILE_WAIT, - PS_POLL_WAIT, - PS_SELECT_WAIT, - PS_SLEEP_WAIT, - PS_WAIT_WAIT, - PS_SIGSUSPEND, - PS_SIGWAIT, - PS_SPINBLOCK, - PS_JOIN, - PS_SUSPENDED, - PS_DEAD, - PS_DEADLOCK, - PS_KEVENT_WAIT, - PS_CONNECT_WAIT, - PS_STATE_MAX -}; - - -/* - * File descriptor locking definitions. - */ -#define FD_READ 0x1 -#define FD_WRITE 0x2 -#define FD_RDWR (FD_READ | FD_WRITE) -#define FD_RDWR_CLOSE (FD_RDWR | 0x4) - -#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) -#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) - -/* Get a suitable argument for _thread_kern_set_timeout(), given an fd */ -#define _FD_RCVTIMEO(_fd) _thread_fd_timeout((_fd), 0) -#define _FD_SNDTIMEO(_fd) _thread_fd_timeout((_fd), 1) - -/* - * File status flags structure - shared for dup'ed fd's - */ -struct fs_flags { - int flags; -#define _FD_NOTSOCK O_EXCL /* Not a socket. */ - int refcnt; - SLIST_ENTRY(fs_flags) fe; /* free list entry. */ -}; - -/* - * fd_table_entry states - */ -enum fd_entry_state { - FD_ENTRY_OPEN, - FD_ENTRY_CLOSING, - FD_ENTRY_CLOSED -}; - -/* - * Defines for _thread_fd_table_init init_mode - */ -enum fd_entry_mode { - FD_INIT_UNKNOWN, /* inherited or not created by pthreads wrapper */ - FD_INIT_NEW, /* new fd opened by pthreads */ - FD_INIT_BLOCKING, /* new user blocking fd opened by pthreads */ - FD_INIT_DUP, /* new fd with passed flags */ - FD_INIT_DUP2, /* replace status_flags and open */ -}; - -/* - * File descriptor table structure. - */ -struct fd_table_entry { - _thread_list_t r_queue; /* Read queue. */ - _thread_list_t w_queue; /* Write queue. */ - struct pthread *r_owner; /* thread owning read lock. */ - struct pthread *w_owner; /* thread owning write lock. */ - const char *r_fname; /* read lock source file name */ - int r_lineno; /* Read lock source line no. */ - const char *w_fname; /* write lock src file name */ - int w_lineno; /* Write lock src line no. */ - int r_lockcount; /* Count for FILE read locks. */ - int w_lockcount; /* Count for FILE write locks.*/ - struct fs_flags *status_flags; /* Shared file status flags. */ - enum fd_entry_state state; /* Open, closing, or closed. */ - enum fd_entry_mode init_mode; /* The mode used for init. */ - SLIST_ENTRY(fd_table_entry) fe; /* Free list entry. */ -}; - -struct pthread_poll_data { - nfds_t nfds; - struct pollfd *fds; -}; - -union pthread_wait_data { - pthread_mutex_t mutex; - pthread_cond_t cond; - const sigset_t *sigwait; /* Waiting on a signal in sigwait */ - struct { - int fd; /* Used when thread waiting on fd */ - int branch; /* Line number, for debugging. */ - const char *fname; /* Source file name for debugging.*/ - } fd; - FILE *fp; - struct pthread_poll_data *poll_data; - spinlock_t *spinlock; - struct pthread *thread; -}; - -/* Spare thread stack. */ -struct stack { - SLIST_ENTRY(stack) qe; /* Queue entry for this stack. */ - void *base; /* Bottom of useful stack */ - size_t size; /* Size of useful stack */ - size_t guardsize; /* Size of red zone */ - void *redzone; /* Red zone location */ - void *storage; /* allocated storage */ -}; - -/* - * Define a continuation routine that can be used to perform a - * transfer of control: - */ -typedef void (*thread_continuation_t) (struct pthread *); - -typedef V_TAILQ_ENTRY(pthread) pthread_entry_t; - -struct join_status { - struct pthread *thread; - void *ret; - int error; -}; - -/* - * Thread structure. - */ -struct pthread { - /* - * Magic value to help recognize a valid thread structure - * from an invalid one: - */ -#define PTHREAD_MAGIC ((u_int32_t) 0xd09ba115) - u_int32_t magic; - char *name; - - /* - * Lock for accesses to this thread structure. - */ - spinlock_t lock; - - /* Queue entry for list of all threads: */ - pthread_entry_t tle; - - /* Queue entry for list of dead threads: */ - pthread_entry_t dle; - - /* - * Thread start routine, argument, stack pointer and thread - * attributes. - */ - void *(*start_routine)(void *); - void *arg; - struct stack *stack; - struct pthread_attr attr; - - /* - * Saved signal context used in call to sigreturn by - * _thread_kern_sched if sig_saved is TRUE. - */ - struct sigcontext saved_sigcontext; - - /* - * Machine-dependent context, valid if sig_saved is FALSE. - */ - struct _machdep_state _machdep; - - /* - * TRUE if the last state saved was a signal context. FALSE if the - * last state saved was a jump buffer. - */ - int sig_saved; - - /* - * Cancelability flags - the lower 2 bits are used by cancel - * definitions in pthread.h - */ -#define PTHREAD_AT_CANCEL_POINT 0x0004 -#define PTHREAD_CANCELLING 0x0008 -#define PTHREAD_CANCEL_NEEDED 0x0010 - int cancelflags; - - enum pthread_susp suspended; - - thread_continuation_t continuation; - - /* - * Current signal mask and pending signals. - */ - sigset_t sigmask; - sigset_t sigpend; - - /* Thread state: */ - enum pthread_state state; - - /* Scheduling clock when this thread was last made active. */ - long last_active; - - /* Scheduling clock when this thread was last made inactive. */ - long last_inactive; - - /* - * Number of microseconds accumulated by this thread when - * time slicing is active. - */ - long slice_usec; - - /* - * Time to wake up thread. This is used for sleeping threads and - * for any operation which may time out (such as select). - */ - struct timespec wakeup_time; - - /* TRUE if operation has timed out. */ - int timeout; - - /* - * Error variable used instead of errno. The function __error() - * returns a pointer to this. - */ - int error; - - /* - * The joiner is the thread that is joining to this thread. The - * join status keeps track of a join operation to another thread. - */ - struct pthread *joiner; - struct join_status join_status; - - /* - * The current thread can belong to only one scheduling queue at - * a time (ready or waiting queue). It can also belong to: - * - * o A queue of threads waiting for a mutex - * o A queue of threads waiting for a condition variable - * o A queue of threads waiting for a file descriptor lock - * o A queue of threads needing work done by the kernel thread - * (waiting for a spinlock or file I/O) - * - * A thread can also be joining a thread (the joiner field above). - * - * It must not be possible for a thread to belong to any of the - * above queues while it is handling a signal. Signal handlers - * may longjmp back to previous stack frames circumventing normal - * control flow. This could corrupt queue integrity if the thread - * retains membership in the queue. Therefore, if a thread is a - * member of one of these queues when a signal handler is invoked, - * it must remove itself from the queue before calling the signal - * handler and reinsert itself after normal return of the handler. - * - * Use pqe for the scheduling queue link (both ready and waiting), - * sqe for synchronization (mutex and condition variable) queue - * links, and qe for all other links. - */ - - pthread_entry_t pqe; /* priority queue link */ - pthread_entry_t sqe; /* synchronization queue link */ - pthread_entry_t qe; /* all other queues link */ - - /* Wait data. */ - union pthread_wait_data data; - - /* - * Allocated for converting select into poll. - */ - struct pthread_poll_data poll_data; - - /* - * Set to TRUE if a blocking operation was - * interrupted by a signal: - */ - int interrupted; - - /* - * Set to TRUE if a blocking operation was - * interrupted by a closing file descriptor. - */ - int closing_fd; - - /* Signal number when in state PS_SIGWAIT: */ - int signo; - - /* - * Set to non-zero when this thread has deferred signals. - * We allow for recursive deferral. - */ - int sig_defer_count; - - /* - * Set to TRUE if this thread should yield after undeferring - * signals. - */ - int yield_on_sig_undefer; - - /* Miscellaneous flags; only set with signals deferred. */ - int flags; -#define PTHREAD_FLAGS_PRIVATE 0x0001 -#define PTHREAD_EXITING 0x0002 -#define PTHREAD_FLAGS_IN_WAITQ 0x0004 /* in waiting queue using pqe link */ -#define PTHREAD_FLAGS_IN_PRIOQ 0x0008 /* in priority queue using pqe link */ -#define PTHREAD_FLAGS_IN_WORKQ 0x0010 /* in work queue using qe link */ -#define PTHREAD_FLAGS_IN_FILEQ 0x0020 /* in file lock queue using qe link */ -#define PTHREAD_FLAGS_IN_FDQ 0x0040 /* in fd lock queue using qe link */ -#define PTHREAD_FLAGS_IN_CONDQ 0x0080 /* in condition queue using sqe link */ -#define PTHREAD_FLAGS_IN_MUTEXQ 0x0100 /* in mutex queue using sqe link */ -#define PTHREAD_FLAGS_TRACE 0x0200 /* for debugging purposes */ -#define PTHREAD_FLAGS_IN_SYNCQ \ - (PTHREAD_FLAGS_IN_CONDQ | PTHREAD_FLAGS_IN_MUTEXQ) - - /* - * Base priority is the user setable and retrievable priority - * of the thread. It is only affected by explicit calls to - * set thread priority and upon thread creation via a thread - * attribute or default priority. - */ - int base_priority; - - /* - * Inherited priority is the priority a thread inherits by - * taking a priority inheritence or protection mutex. It - * is not affected by base priority changes. Inherited - * priority defaults to and remains 0 until a mutex is taken - * that is being waited on by any other thread whose priority - * is non-zero. - */ - int inherited_priority; - - /* - * Active priority is always the maximum of the threads base - * priority and inherited priority. When there is a change - * in either the base or inherited priority, the active - * priority must be recalculated. - */ - int active_priority; - - /* Number of priority ceiling or protection mutexes owned. */ - int priority_mutex_count; - - /* Number rwlocks rdlocks held. */ - int rdlock_count; - - /* - * Queue of currently owned mutexes. - */ - V_TAILQ_HEAD(, pthread_mutex volatile) mutexq; - - void *ret; - const void **specific_data; - int specific_data_count; - - /* Cleanup handlers Link List */ - struct pthread_cleanup *cleanup; - const char *fname; /* Ptr to source file name */ - int lineno; /* Source line number. */ -}; - -/* - * Flags and prototypes for the machine dependent layer - */ -void _thread_machdep_switch(struct _machdep_state *newstate, - struct _machdep_state *savestate); -void _thread_machdep_init(struct _machdep_state *state, void *stackbase, - int stacksize, void (*entry)(void)); -void _thread_machdep_save_float_state(struct _machdep_state* statep); -void _thread_machdep_restore_float_state(struct _machdep_state* statep); - -/* - * Global variables for the uthread kernel. - */ - -/* Kernel thread structure used when there are no running threads: */ -SCLASS struct pthread _thread_kern_thread; - -/* Ptr to the thread structure for the running thread: */ -SCLASS struct pthread * volatile _thread_run -#ifdef GLOBAL_PTHREAD_PRIVATE -= &_thread_kern_thread; -#else -; -#endif - -/* Ptr to the thread structure for the last user thread to run: */ -SCLASS struct pthread * volatile _last_user_thread -#ifdef GLOBAL_PTHREAD_PRIVATE -= &_thread_kern_thread; -#else -; -#endif - -/* - * Ptr to the thread running in single-threaded mode or NULL if - * running multi-threaded (default POSIX behaviour). - */ -SCLASS struct pthread * volatile _thread_single -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -SCLASS _thread_list_t _thread_list -#ifdef GLOBAL_PTHREAD_PRIVATE -= TAILQ_HEAD_INITIALIZER(_thread_list); -#else -; -#endif - -/* - * Array of kernel pipe file descriptors that are used to ensure that - * no signals are missed in calls to _select. - */ -SCLASS int _thread_kern_pipe[2] -#ifdef GLOBAL_PTHREAD_PRIVATE -= { - -1, - -1 -}; -#else -; -#endif -SCLASS int volatile _queue_signals -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif -SCLASS int volatile _thread_kern_in_sched -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -SCLASS int _sig_in_handler -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -/* Time of day at last scheduling timer signal: */ -SCLASS struct timeval volatile _sched_tod -#ifdef GLOBAL_PTHREAD_PRIVATE -= { 0, 0 }; -#else -; -#endif - -/* - * Current scheduling timer ticks; used as resource usage. - */ -SCLASS unsigned int volatile _sched_ticks -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -/* Dead threads: */ -SCLASS _thread_list_t _dead_list -#ifdef GLOBAL_PTHREAD_PRIVATE -= TAILQ_HEAD_INITIALIZER(_dead_list); -#else -; -#endif - -/* Initial thread: */ -SCLASS struct pthread *_thread_initial -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -SCLASS TAILQ_HEAD(atfork_head, pthread_atfork) _atfork_list; -SCLASS pthread_mutex_t _atfork_mutex; - -/* Default thread attributes: */ -SCLASS struct pthread_attr pthread_attr_default -#ifdef GLOBAL_PTHREAD_PRIVATE -= { SCHED_RR, 0, TIMESLICE_USEC, PTHREAD_DEFAULT_PRIORITY, - PTHREAD_CREATE_RUNNING, PTHREAD_CREATE_JOINABLE, NULL, NULL, NULL, - PTHREAD_STACK_DEFAULT, 0 /* set in _thread_init() */ }; -#else -; -#endif - -/* Default mutex attributes: */ -SCLASS struct pthread_mutex_attr pthread_mutexattr_default -#ifdef GLOBAL_PTHREAD_PRIVATE -= { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, 0 }; -#else -; -#endif - -/* Default condition variable attributes: */ -SCLASS struct pthread_cond_attr pthread_condattr_default -#ifdef GLOBAL_PTHREAD_PRIVATE -= { COND_TYPE_FAST, 0 }; -#else -; -#endif - -/* File table information: */ -SCLASS struct fd_table_entry **_thread_fd_table -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -/* Table for polling file descriptors: */ -SCLASS struct pollfd *_thread_pfd_table -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL; -#else -; -#endif - -SCLASS int _thread_init_fdtsize /* Initial fd/pfd table size. */ -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -SCLASS int _thread_max_fdtsize /* Max fd table size. */ -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -SCLASS nfds_t _thread_max_pfdtsize /* Max pfd table size. */ -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -SCLASS int _clock_res_usec /* Clock resolution in usec. */ -#ifdef GLOBAL_PTHREAD_PRIVATE -= CLOCK_RES_USEC; -#else -; -#endif - -/* Garbage collector mutex and condition variable. */ -SCLASS pthread_mutex_t _gc_mutex -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; -SCLASS pthread_cond_t _gc_cond -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; - -/* - * Array of signal actions for this process. - */ -SCLASS struct sigaction _thread_sigact[NSIG]; - -/* - * Array of counts of dummy handlers for SIG_DFL signals. This is used to - * assure that there is always a dummy signal handler installed while there is a - * thread sigwait()ing on the corresponding signal. - */ -SCLASS int _thread_dfl_count[NSIG]; - -/* - * Pending signals and mask for this process: - */ -SCLASS sigset_t _process_sigpending; -SCLASS sigset_t _process_sigmask -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0 -#endif -; - -/* - * Scheduling queues: - */ -SCLASS pq_queue_t _readyq; -SCLASS _thread_list_t _waitingq; - -/* - * Work queue: - */ -SCLASS _thread_list_t _workq; - -/* Tracks the number of threads blocked while waiting for a spinlock. */ -SCLASS volatile int _spinblock_count -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0 -#endif -; - -/* Used to maintain pending and active signals: */ -struct sigstatus { - spinlock_t lock; /* structure access lock */ - int pending; /* Is this a pending signal? */ - siginfo_t siginfo; /* arg 2 to signal handler */ -}; - -SCLASS struct sigstatus _thread_sigq[NSIG]; - -/* Indicates that the signal queue needs to be checked. */ -SCLASS volatile int _sigq_check_reqd -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0 -#endif -; - -/* The signal stack. */ -SCLASS struct sigaltstack _thread_sigstack; - -/* Thread switch hook. */ -SCLASS pthread_switch_routine_t _sched_switch_hook -#ifdef GLOBAL_PTHREAD_PRIVATE -= NULL -#endif -; - -/* - * Spare stack queue. Stacks of default size are cached in order to reduce - * thread creation time. Spare stacks are used in LIFO order to increase cache - * locality. - */ -typedef SLIST_HEAD(, stack) _stack_list_t; -extern _stack_list_t _stackq; - -/* Used for _PTHREADS_INVARIANTS checking. */ -SCLASS int _thread_kern_new_state -#ifdef GLOBAL_PTHREAD_PRIVATE -= 0; -#else -; -#endif - -/* Undefine the storage class specifier: */ -#undef SCLASS - -/* - * Function prototype definitions. - */ -__BEGIN_DECLS -int *__error(void); -int _find_thread(pthread_t); -struct pthread *_get_curthread(void); -void _set_curthread(struct pthread *); -int _thread_create(pthread_t *, const pthread_attr_t *, - void *(*start_routine)(void *), void *,pthread_t); -void _dispatch_signal(int, struct sigcontext *); -void _dispatch_signals(struct sigcontext *); -void _thread_signal(pthread_t, int); -void _thread_nonblock_fds(void); -int _mutex_cv_lock(pthread_mutex_t *); -int _mutex_cv_unlock(pthread_mutex_t *); -int _mutex_reinit(pthread_mutex_t *); -void _mutex_notify_priochange(struct pthread *); -int _cond_reinit(pthread_cond_t *); -int _pq_alloc(struct pq_queue *, int, int); -int _pq_init(struct pq_queue *); -void _pq_remove(struct pq_queue *pq, struct pthread *); -void _pq_insert_head(struct pq_queue *pq, struct pthread *); -void _pq_insert_tail(struct pq_queue *pq, struct pthread *); -struct pthread *_pq_first(struct pq_queue *pq); -void _waitq_insert(pthread_t pthread); -void _waitq_remove(pthread_t pthread); -#if defined(_PTHREADS_INVARIANTS) -void _waitq_setactive(void); -void _waitq_clearactive(void); -#endif -__dead void _thread_exit(const char *, int, const char *) __attribute__((__noreturn__)); -void *_thread_cleanup(pthread_t); -void _thread_cleanupspecific(void); -void _thread_clear_pending(int, pthread_t); -void _thread_dump_data(const void *, int); -void _thread_dump_info(void); -int _thread_fd_lock(int, int, struct timespec *); -void _thread_fd_unlock(int, int); -struct timespec *_thread_fd_timeout(int, int); -void _thread_init(void); -void _thread_kern_lock(int); -void _thread_kern_sched(struct sigcontext *); -void _thread_kern_sched_state(enum pthread_state, const char *, int); -void _thread_kern_sched_state_unlock(enum pthread_state, spinlock_t *, - const char *, int); -void _thread_kern_set_timeout(const struct timespec *); -void _thread_kern_sig_defer(void); -void _thread_kern_sig_undefer(void); -void _thread_key_init(void); -void _thread_kill_siginfo(int); -void _thread_sig_handler(int, siginfo_t *, struct sigcontext *); -int _thread_sig_handle(int, struct sigcontext *); -void _thread_sig_init(void); -void _thread_start(void); -void _thread_start_sig_handler(void); -void _thread_seterrno(pthread_t,int); -void _thread_fs_flags_replace(int, struct fs_flags *); -int _thread_fd_init_mem(void); -void _thread_fd_init(void); -int _thread_fd_table_init(int, enum fd_entry_mode, struct fs_flags *); -void _thread_fd_entry_close(int); -pthread_addr_t _thread_gc(pthread_addr_t); -void _thread_enter_cancellation_point(void); -void _thread_leave_cancellation_point(void); -void _thread_cancellation_point(void); -int _thread_slow_atomic_lock(volatile _spinlock_lock_t *); -int _thread_slow_atomic_is_locked(volatile _spinlock_lock_t *); -struct stack * _thread_stack_alloc(void *, size_t, size_t); -void _thread_stack_free(struct stack *); - - -/* #include <signal.h> */ -#ifdef _USER_SIGNAL_H -int _thread_sys_kill(pid_t, int); -int _thread_sys_sigaction(int, const struct sigaction *, struct sigaction *); -int _thread_sys_sigblock(int); -int _thread_sys_sigsetmask(int); -int _thread_sys_sigpending(sigset_t *); -int _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *); -int _thread_sys_sigsuspend(const sigset_t *); -int _thread_sys_siginterrupt(int, int); -int _thread_sys_sigpause(int); -int _thread_sys_sigreturn(struct sigcontext *); -int _thread_sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *); -int _thread_sys_sigvec(int, struct sigvec *, struct sigvec *); -void _thread_sys_psignal(unsigned int, const char *); -void (*_thread_sys_signal(int, void (*)(int)))(int); -#endif - -/* #include <sys/stat.h> */ -#ifdef _SYS_STAT_H_ -int _thread_sys_fchmod(int, mode_t); -int _thread_sys_fstat(int, struct stat *); -int _thread_sys_fchflags(int, unsigned int); -#endif - -/* #include <sys/mount.h> */ -#ifdef _SYS_MOUNT_H_ -int _thread_sys_fstatfs(int, struct statfs *); -#endif -int _thread_sys_pipe(int *); - -/* #include <sys/socket.h> */ -#ifdef _SYS_SOCKET_H_ -int _thread_sys_accept(int, struct sockaddr *, socklen_t *); -int _thread_sys_bind(int, const struct sockaddr *, socklen_t); -int _thread_sys_connect(int, const struct sockaddr *, socklen_t); -int _thread_sys_getpeername(int, struct sockaddr *, socklen_t *); -int _thread_sys_getsockname(int, struct sockaddr *, socklen_t *); -int _thread_sys_getsockopt(int, int, int, void *, socklen_t *); -int _thread_sys_listen(int, int); -int _thread_sys_setsockopt(int, int, int, const void *, socklen_t); -int _thread_sys_shutdown(int, int); -int _thread_sys_socket(int, int, int); -int _thread_sys_socketpair(int, int, int, int *); -ssize_t _thread_sys_recv(int, void *, size_t, int); -ssize_t _thread_sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); -ssize_t _thread_sys_recvmsg(int, struct msghdr *, int); -ssize_t _thread_sys_send(int, const void *, size_t, int); -ssize_t _thread_sys_sendmsg(int, const struct msghdr *, int); -ssize_t _thread_sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t); -#endif - -/* #include <stdio.h> */ -#ifdef _STDIO_H_ -FILE *_thread_sys_fdopen(int, const char *); -FILE *_thread_sys_fopen(const char *, const char *); -FILE *_thread_sys_freopen(const char *, const char *, FILE *); -FILE *_thread_sys_popen(const char *, const char *); -FILE *_thread_sys_tmpfile(void); -char *_thread_sys_ctermid(char *); -char *_thread_sys_cuserid(char *); -char *_thread_sys_fgetln(FILE *, size_t *); -char *_thread_sys_fgets(char *, int, FILE *); -char *_thread_sys_gets(char *); -char *_thread_sys_tempnam(const char *, const char *); -char *_thread_sys_tmpnam(char *); -int _thread_sys_fclose(FILE *); -int _thread_sys_feof(FILE *); -int _thread_sys_ferror(FILE *); -int _thread_sys_fflush(FILE *); -int _thread_sys_fgetc(FILE *); -int _thread_sys_fgetpos(FILE *, fpos_t *); -int _thread_sys_fileno(FILE *); -int _thread_sys_fprintf(FILE *, const char *, ...); -int _thread_sys_fpurge(FILE *); -int _thread_sys_fputc(int, FILE *); -int _thread_sys_fputs(const char *, FILE *); -int _thread_sys_fscanf(FILE *, const char *, ...); -int _thread_sys_fseek(FILE *, long, int); -int _thread_sys_fsetpos(FILE *, const fpos_t *); -int _thread_sys_getc(FILE *); -int _thread_sys_getchar(void); -int _thread_sys_getw(FILE *); -int _thread_sys_pclose(FILE *); -int _thread_sys_printf(const char *, ...); -int _thread_sys_putc(int, FILE *); -int _thread_sys_putchar(int); -int _thread_sys_puts(const char *); -int _thread_sys_putw(int, FILE *); -int _thread_sys_remove(const char *); -int _thread_sys_rename (const char *, const char *); -int _thread_sys_scanf(const char *, ...); -int _thread_sys_setlinebuf(FILE *); -int _thread_sys_setvbuf(FILE *, char *, int, size_t); -int _thread_sys_snprintf(char *, size_t, const char *, ...); -int _thread_sys_sprintf(char *, const char *, ...); -int _thread_sys_sscanf(const char *, const char *, ...); -int _thread_sys_ungetc(int, FILE *); -int _thread_sys_vfprintf(FILE *, const char *, __va_list); -int _thread_sys_vprintf(const char *, __va_list); -int _thread_sys_vscanf(const char *, __va_list); -int _thread_sys_vsnprintf(char *, size_t, const char *, __va_list); -int _thread_sys_vsprintf(char *, const char *, __va_list); -int _thread_sys_vsscanf(const char *, const char *, __va_list); -long _thread_sys_ftell(FILE *); -size_t _thread_sys_fread(void *, size_t, size_t, FILE *); -size_t _thread_sys_fwrite(const void *, size_t, size_t, FILE *); -void _thread_sys_clearerr(FILE *); -void _thread_sys_perror(const char *); -void _thread_sys_rewind(FILE *); -void _thread_sys_setbuf(FILE *, char *); -void _thread_sys_setbuffer(FILE *, char *, int); -#endif - -/* #include <unistd.h> */ -#ifdef _UNISTD_H_ -char *_thread_sys_ttyname(int); -int _thread_sys_close(int); -int _thread_sys_closefrom(int); -int _thread_sys_dup(int); -int _thread_sys_dup2(int, int); -int _thread_sys_exect(const char *, char * const *, char * const *); -int _thread_sys_execve(const char *, char * const *, char * const *); -int _thread_sys_fchdir(int); -int _thread_sys_fchown(int, uid_t, gid_t); -int _thread_sys_fsync(int); -int _thread_sys_ftruncate(int, off_t); -long _thread_sys_fpathconf(int, int); -pid_t _thread_sys_getpid(void); -int _thread_sys_pipe(int *); -ssize_t _thread_sys_pread(int, void *, size_t, off_t); -ssize_t _thread_sys_pwrite(int, const void *, size_t, off_t); -int _thread_sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); -off_t _thread_sys_lseek(int, off_t, int); -pid_t _thread_sys_fork(void); -pid_t _thread_sys_vfork(void); -pid_t _thread_sys_tcgetpgrp(int); -ssize_t _thread_sys_read(int, void *, size_t); -ssize_t _thread_sys_write(int, const void *, size_t); -__dead void _thread_sys__exit(int) __attribute__((__noreturn__)); -#endif - -/* #include <fcntl.h> */ -#ifdef _SYS_FCNTL_H_ -int _thread_sys_creat(const char *, mode_t); -int _thread_sys_fcntl(int, int, ...); -int _thread_sys_flock(int, int); -int _thread_sys_open(const char *, int, ...); -int _thread_sys_openat(int, const char *, int, ...); -#endif - -/* #include <sys/ioctl.h> */ -#ifdef _SYS_IOCTL_H_ -int _thread_sys_ioctl(int, unsigned long, ...); -#endif - -/* #include <dirent.h> */ -#ifdef _DIRENT_H_ -DIR *___thread_sys_opendir2(const char *, int); -DIR *_thread_sys_opendir(const char *); -int _thread_sys_alphasort(const void *, const void *); -int _thread_sys_scandir(const char *, struct dirent ***, - int (*)(struct dirent *), int (*)(const void *, const void *)); -int _thread_sys_closedir(DIR *); -int _thread_sys_getdirentries(int, char *, int, off_t *); -long _thread_sys_telldir(const DIR *); -struct dirent *_thread_sys_readdir(DIR *); -void _thread_sys_rewinddir(DIR *); -void _thread_sys_seekdir(DIR *, long); -#endif - -/* #include <sys/uio.h> */ -#ifdef _SYS_UIO_H_ -ssize_t _thread_sys_preadv(int, const struct iovec *, int, off_t); -ssize_t _thread_sys_pwritev(int, const struct iovec *, int, off_t); -ssize_t _thread_sys_readv(int, const struct iovec *, int); -ssize_t _thread_sys_writev(int, const struct iovec *, int); -#endif - -/* #include <sys/wait.h> */ -#ifdef _SYS_WAIT_H_ -pid_t _thread_sys_wait(int *); -pid_t _thread_sys_waitpid(pid_t, int *, int); -pid_t _thread_sys_wait3(int *, int, struct rusage *); -pid_t _thread_sys_wait4(pid_t, int *, int, struct rusage *); -#endif - -/* #include <poll.h> */ -#ifdef _SYS_POLL_H_ -int _thread_sys_poll(struct pollfd *, unsigned, int); -#endif - -/* #include <sys/event.h> */ -#ifdef _SYS_EVENT_H_ -int _thread_sys_kqueue(void); -int _thread_sys_kevent(int, const struct kevent *, int, struct kevent *, - int, const struct timespec *); -#endif - -/* #include <sys/mman.h> */ -int _thread_sys_msync(void *, size_t, int); - -__END_DECLS - -#endif /* !_PTHREAD_PRIVATE_H */ diff --git a/lib/libpthread/uthread/sched_prio.c b/lib/libpthread/uthread/sched_prio.c deleted file mode 100644 index 1e48a747554..00000000000 --- a/lib/libpthread/uthread/sched_prio.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $OpenBSD: sched_prio.c,v 1.1 2010/11/07 13:29:21 fgsch Exp $ */ - -/* - * Copyright (c) 2010 Federico G. Schwindt <fgsch@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for - * any purpose with or without fee is hereby granted, provided that - * the above copyright notice and this permission notice appear in all - * copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE - * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA - * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sched_get_priority_max(int policy) -{ - if (policy < SCHED_FIFO || policy > SCHED_RR) { - errno = EINVAL; - return (-1); - } - return (PTHREAD_MAX_PRIORITY); -} - -int -sched_get_priority_min(int policy) -{ - if (policy < SCHED_FIFO || policy > SCHED_RR) { - errno = EINVAL; - return (-1); - } - return (PTHREAD_MIN_PRIORITY); -} -#endif diff --git a/lib/libpthread/uthread/uthread_accept.c b/lib/libpthread/uthread/uthread_accept.c deleted file mode 100644 index 6fe193aa986..00000000000 --- a/lib/libpthread/uthread/uthread_accept.c +++ /dev/null @@ -1,128 +0,0 @@ -/* $OpenBSD: uthread_accept.c,v 1.11 2006/10/03 02:59:36 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_accept.c,v 1.9 1999/08/28 00:03:20 peter Exp $ - */ -#include <errno.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -accept(int fd, struct sockaddr * name, socklen_t *namelen) -{ - struct pthread *curthread = _get_curthread(); - int ret; - int newfd; - enum fd_entry_mode init_mode; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Lock the file descriptor: */ - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - /* Enter a loop to wait for a connection request: */ - while ((ret = _thread_sys_accept(fd, name, namelen)) < 0) { - /* Check if the socket is to block: */ - if ((_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) == 0 && - (errno == EWOULDBLOCK || errno == EAGAIN)) { - /* Save the socket file descriptor: */ - curthread->data.fd.fd = fd; - curthread->data.fd.fname = __FILE__; - curthread->data.fd.branch = __LINE__; - - /* Set the timeout: */ - _thread_kern_set_timeout(NULL); - curthread->interrupted = 0; - curthread->closing_fd = 0; - - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_FDR_WAIT, __FILE__, - __LINE__); - - /* Check if the wait was interrupted: */ - if (curthread->interrupted) { - /* Return an error status: */ - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - /* Return an error status: */ - errno = EBADF; - ret = -1; - break; - } - } else { - /* - * Another error has occurred, so exit the - * loop here: - */ - break; - } - } - - /* - * If no errors initialize the file descriptor table - * for the new socket. If the client's view of the - * status_flags for fd is blocking, then force newfd - * to be viewed as blocking too. - */ - if (ret != -1) { - newfd = ret; - - if ((_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) == 0) - init_mode = FD_INIT_BLOCKING; - else - init_mode = FD_INIT_NEW; - if((ret = _thread_fd_table_init(newfd, init_mode, NULL)) != -1) - ret = newfd; - else { - /* quitely close the fd */ - _thread_sys_close(ret); - } - } - - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_RDWR); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - /* Return the socket file descriptor or -1 on error: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_atfork.c b/lib/libpthread/uthread/uthread_atfork.c deleted file mode 100644 index 10e6f6be25b..00000000000 --- a/lib/libpthread/uthread/uthread_atfork.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: uthread_atfork.c,v 1.3 2005/10/30 03:37:34 brad Exp $ */ - -/* - * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $ - */ - -#include <errno.h> -#include <stdlib.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include <sys/queue.h> -#include "pthread_private.h" - -int -pthread_atfork(void (*prepare)(void), void (*parent)(void), - void (*child)(void)) -{ - struct pthread_atfork *af; - - if (_thread_initial == NULL) - _thread_init(); - - if ((af = malloc(sizeof(struct pthread_atfork))) == NULL) - return (ENOMEM); - - af->prepare = prepare; - af->parent = parent; - af->child = child; - pthread_mutex_lock(&_atfork_mutex); - TAILQ_INSERT_TAIL(&_atfork_list, af, qe); - pthread_mutex_unlock(&_atfork_mutex); - return (0); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_destroy.c b/lib/libpthread/uthread/uthread_attr_destroy.c deleted file mode 100644 index a71b00eea6e..00000000000 --- a/lib/libpthread/uthread/uthread_attr_destroy.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD: uthread_attr_destroy.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_destroy.c,v 1.4 1999/08/28 00:03:20 peter Exp $ - */ -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_destroy(pthread_attr_t *attr) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL) - /* Invalid argument: */ - ret = EINVAL; - else { - /* Free the memory allocated to the attribute object: */ - free(*attr); - - /* - * Leave the attribute pointer NULL now that the memory - * has been freed: - */ - *attr = NULL; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getdetachstate.c b/lib/libpthread/uthread/uthread_attr_getdetachstate.c deleted file mode 100644 index 915caddf33e..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getdetachstate.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: uthread_attr_getdetachstate.c,v 1.4 2002/01/10 00:45:30 fgsch Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getdetachstate.c,v 1.3 1999/08/28 00:03:20 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || detachstate == NULL) - ret = EINVAL; - else { - /* Check if the detached flag is set: */ - if ((*attr)->flags & PTHREAD_DETACHED) - /* Return detached: */ - *detachstate = PTHREAD_CREATE_DETACHED; - else - /* Return joinable: */ - *detachstate = PTHREAD_CREATE_JOINABLE; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getguardsize.c b/lib/libpthread/uthread/uthread_attr_getguardsize.c deleted file mode 100644 index b956ed6ecc2..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getguardsize.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_getguardsize.c,v 1.1 2008/12/18 09:30:32 guenther Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getstacksize.c,v 1.3 1999/08/28 00:03:22 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || guardsize == NULL) - ret = EINVAL; - else { - /* Return the guard size: */ - *guardsize = (*attr)->guardsize_attr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getinheritsched.c b/lib/libpthread/uthread/uthread_attr_getinheritsched.c deleted file mode 100644 index da160586615..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getinheritsched.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_attr_getinheritsched.c,v 1.2 1999/11/25 07:01:30 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getinheritsched.c,v 1.3 1999/08/28 00:03:21 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getinheritsched(const pthread_attr_t *attr, int *sched_inherit) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL)) - ret = EINVAL; - else - *sched_inherit = (*attr)->sched_inherit; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getschedparam.c b/lib/libpthread/uthread/uthread_attr_getschedparam.c deleted file mode 100644 index 321d2b646b1..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getschedparam.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_attr_getschedparam.c,v 1.2 1999/11/25 07:01:31 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getschedparam.c,v 1.3 1999/08/28 00:03:21 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL) || (param == NULL)) - ret = EINVAL; - else - param->sched_priority = (*attr)->prio; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getschedpolicy.c b/lib/libpthread/uthread/uthread_attr_getschedpolicy.c deleted file mode 100644 index 5be8dcba3bf..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getschedpolicy.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_attr_getschedpolicy.c,v 1.2 1999/11/25 07:01:31 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getschedpolicy.c,v 1.3 1999/08/28 00:03:21 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL) || (policy == NULL)) - ret = EINVAL; - else - *policy = (*attr)->sched_policy; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getscope.c b/lib/libpthread/uthread/uthread_attr_getscope.c deleted file mode 100644 index 68bfb0d6654..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getscope.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_getscope.c,v 1.2 1999/11/25 07:01:31 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getscope.c,v 1.3 1999/08/28 00:03:22 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL) || (contentionscope == NULL)) - /* Return an invalid argument: */ - ret = EINVAL; - - else - *contentionscope = (*attr)->flags & PTHREAD_SCOPE_SYSTEM ? - PTHREAD_SCOPE_SYSTEM : PTHREAD_SCOPE_PROCESS; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getstack.c b/lib/libpthread/uthread/uthread_attr_getstack.c deleted file mode 100644 index 83e24bb3fd4..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getstack.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $OpenBSD: uthread_attr_getstack.c,v 1.1 2004/02/22 23:59:26 brad Exp $ */ - -/* - * Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Craig Rodrigues. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc_r/uthread/uthread_attr_getstack.c,v 1.1 2003/02/10 08:48:03 alfred Exp $ - */ - -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getstack(const pthread_attr_t *attr, - void **stackaddr, - size_t *stacksize) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || stackaddr == NULL - || stacksize == NULL ) - ret = EINVAL; - else { - /* Return the stack address and size */ - *stackaddr = (*attr)->stackaddr_attr; - *stacksize = (*attr)->stacksize_attr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getstackaddr.c b/lib/libpthread/uthread/uthread_attr_getstackaddr.c deleted file mode 100644 index 295a6ee68fa..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getstackaddr.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_getstackaddr.c,v 1.5 2004/02/16 22:48:40 brad Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getstackaddr.c,v 1.3 1999/08/28 00:03:22 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || stackaddr == NULL) - ret = EINVAL; - else { - /* Return the stack address: */ - *stackaddr = (*attr)->stackaddr_attr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_getstacksize.c b/lib/libpthread/uthread/uthread_attr_getstacksize.c deleted file mode 100644 index ea9a3b64385..00000000000 --- a/lib/libpthread/uthread/uthread_attr_getstacksize.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_getstacksize.c,v 1.5 2004/02/16 22:48:40 brad Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_getstacksize.c,v 1.3 1999/08/28 00:03:22 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || stacksize == NULL) - ret = EINVAL; - else { - /* Return the stack size: */ - *stacksize = (*attr)->stacksize_attr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_init.c b/lib/libpthread/uthread/uthread_attr_init.c deleted file mode 100644 index c7b811e3505..00000000000 --- a/lib/libpthread/uthread/uthread_attr_init.c +++ /dev/null @@ -1,62 +0,0 @@ -/* $OpenBSD: uthread_attr_init.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_init.c,v 1.4 1999/08/28 00:03:23 peter Exp $ - */ -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_init(pthread_attr_t *attr) -{ - int ret; - pthread_attr_t pattr; - - /* Allocate memory for the attribute object: */ - if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL) - /* Insufficient memory: */ - ret = ENOMEM; - else { - /* Initialise the attribute object with the defaults: */ - memcpy(pattr, &pthread_attr_default, sizeof(struct pthread_attr)); - - /* Return a pointer to the attribute object: */ - *attr = pattr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setcreatesuspend_np.c b/lib/libpthread/uthread/uthread_attr_setcreatesuspend_np.c deleted file mode 100644 index e1d7d51bfaa..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setcreatesuspend_np.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_attr_setcreatesuspend_np.c,v 1.4 2001/08/10 14:37:20 fgsch Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setcreatesuspend_np.c,v 1.3 1999/08/28 00:03:24 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setcreatesuspend_np(pthread_attr_t *attr) -{ - int ret; - if (attr == NULL || *attr == NULL) { - ret = EINVAL; - } else { - (*attr)->suspend = PTHREAD_CREATE_SUSPENDED; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setdetachstate.c b/lib/libpthread/uthread/uthread_attr_setdetachstate.c deleted file mode 100644 index f0801e5823d..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setdetachstate.c +++ /dev/null @@ -1,62 +0,0 @@ -/* $OpenBSD: uthread_attr_setdetachstate.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setdetachstate.c,v 1.3 1999/08/28 00:03:24 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || - (detachstate != PTHREAD_CREATE_DETACHED && - detachstate != PTHREAD_CREATE_JOINABLE)) - ret = EINVAL; - else { - /* Check if detached state: */ - if (detachstate == PTHREAD_CREATE_DETACHED) - /* Set the detached flag: */ - (*attr)->flags |= PTHREAD_DETACHED; - else - /* Reset the detached flag: */ - (*attr)->flags &= ~PTHREAD_DETACHED; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setguardsize.c b/lib/libpthread/uthread/uthread_attr_setguardsize.c deleted file mode 100644 index db9acad2fd7..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setguardsize.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_setguardsize.c,v 1.1 2008/12/18 09:30:32 guenther Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setstacksize.c,v 1.4 1999/08/28 00:03:26 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL) - ret = EINVAL; - else { - /* Save the guard size: */ - (*attr)->guardsize_attr = guardsize; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setinheritsched.c b/lib/libpthread/uthread/uthread_attr_setinheritsched.c deleted file mode 100644 index 61e0f2f6144..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setinheritsched.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_attr_setinheritsched.c,v 1.2 1999/11/25 07:01:31 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setinheritsched.c,v 1.3 1999/08/28 00:03:24 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL)) - ret = EINVAL; - else - (*attr)->sched_inherit = sched_inherit; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setprio.c b/lib/libpthread/uthread/uthread_attr_setprio.c deleted file mode 100644 index ffe74d8a102..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setprio.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_attr_setprio.c,v 1.5 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setprio.c,v 1.3 1999/08/28 00:03:24 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setprio(pthread_attr_t *attr, int priority) -{ - int ret; - if (attr == NULL || *attr == NULL) { - ret = EINVAL; - } else { - (*attr)->prio = priority; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setschedparam.c b/lib/libpthread/uthread/uthread_attr_setschedparam.c deleted file mode 100644 index d1071fa4314..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setschedparam.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: uthread_attr_setschedparam.c,v 1.4 2002/01/19 23:49:32 fgsch Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setschedparam.c,v 1.3 1999/08/28 00:03:25 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL)) - ret = EINVAL; - else if (param == NULL) { - ret = ENOTSUP; - } else if ((param->sched_priority < PTHREAD_MIN_PRIORITY) || - (param->sched_priority > PTHREAD_MAX_PRIORITY)) { - /* Return an unsupported value error. */ - ret = ENOTSUP; - } else - (*attr)->prio = param->sched_priority; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setschedpolicy.c b/lib/libpthread/uthread/uthread_attr_setschedpolicy.c deleted file mode 100644 index 9070b010244..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setschedpolicy.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: uthread_attr_setschedpolicy.c,v 1.5 2004/04/10 06:41:42 brad Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setschedpolicy.c,v 1.3 1999/08/28 00:03:25 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL)) - ret = EINVAL; - else if ((policy < SCHED_FIFO) || (policy > SCHED_RR)) { - ret = ENOTSUP; - } else - (*attr)->sched_policy = policy; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setscope.c b/lib/libpthread/uthread/uthread_attr_setscope.c deleted file mode 100644 index 2b8f4122034..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setscope.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD: uthread_attr_setscope.c,v 1.4 2002/02/19 01:13:08 fgsch Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setscope.c,v 1.3 1999/08/28 00:03:25 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setscope(pthread_attr_t *attr, int contentionscope) -{ - int ret = 0; - - if ((attr == NULL) || (*attr == NULL)) { - /* Return an invalid argument: */ - ret = EINVAL; - } else if ((contentionscope != PTHREAD_SCOPE_PROCESS) || - (contentionscope == PTHREAD_SCOPE_SYSTEM)) { - /* We don't support PTHREAD_SCOPE_SYSTEM. */ - ret = ENOTSUP; - } else - (*attr)->flags |= contentionscope; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setstack.c b/lib/libpthread/uthread/uthread_attr_setstack.c deleted file mode 100644 index 9b7b2d254b2..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setstack.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: uthread_attr_setstack.c,v 1.1 2004/02/22 23:59:26 brad Exp $ */ - -/* - * Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Craig Rodrigues. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY CRAIG RODRIGUES AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc_r/uthread/uthread_attr_setstack.c,v 1.1 2003/02/10 08:48:03 alfred Exp $ - */ - -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, - size_t stacksize) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || stackaddr == NULL - || stacksize < PTHREAD_STACK_MIN ) - ret = EINVAL; - else { - /* Save the stack address and stack size */ - (*attr)->stackaddr_attr = stackaddr; - (*attr)->stacksize_attr = stacksize; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setstackaddr.c b/lib/libpthread/uthread/uthread_attr_setstackaddr.c deleted file mode 100644 index a2f07bab9a3..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setstackaddr.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_setstackaddr.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setstackaddr.c,v 1.3 1999/08/28 00:03:25 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || stackaddr == NULL) - ret = EINVAL; - else { - /* Save the stack address: */ - (*attr)->stackaddr_attr = stackaddr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_attr_setstacksize.c b/lib/libpthread/uthread/uthread_attr_setstacksize.c deleted file mode 100644 index 5c1e489cf97..00000000000 --- a/lib/libpthread/uthread/uthread_attr_setstacksize.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_attr_setstacksize.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_attr_setstacksize.c,v 1.4 1999/08/28 00:03:26 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) -{ - int ret; - - /* Check for invalid arguments: */ - if (attr == NULL || *attr == NULL || stacksize < PTHREAD_STACK_MIN) - ret = EINVAL; - else { - /* Save the stack size: */ - (*attr)->stacksize_attr = stacksize; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_autoinit.c b/lib/libpthread/uthread/uthread_autoinit.c deleted file mode 100644 index 37501b45932..00000000000 --- a/lib/libpthread/uthread/uthread_autoinit.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * David Leonard, 1998. Public Domain. <david.leonard@csee.uq.edu.au> - * - * $OpenBSD: uthread_autoinit.c,v 1.12 2003/01/31 18:48:03 marc Exp $ - */ - - -#include <stdio.h> -#include <pthread.h> -#include "pthread_private.h" - -/* - * Use C++'s static instance constructor to initialise threads. - */ -#ifdef __cplusplus -class Init { -public: - Init() { - _thread_init(); - } -}; -Init _thread_initialiser; -#endif /* C++ */ - -/* - * This construct places the function in the __CTOR_LIST__ entry in the - * object, and later the collect2 stage of linkage will inform __main (from - * libgcc.a) to call it. - */ -#if defined(__GNUC__) -extern void _thread_init_constructor(void) __attribute__((constructor)); - -void -_thread_init_constructor() -{ - _thread_init(); -} -#endif /* GNU C */ - -/* - * Dummy symbol referenced by uthread_init.o so this compilation unit - * is always loaded from archives. - */ -int _thread_autoinit_dummy_decl = 0; - diff --git a/lib/libpthread/uthread/uthread_bind.c b/lib/libpthread/uthread/uthread_bind.c deleted file mode 100644 index fca26b55558..00000000000 --- a/lib/libpthread/uthread/uthread_bind.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_bind.c,v 1.4 1999/11/25 07:01:32 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_bind.c,v 1.5 1999/08/28 00:03:26 peter Exp $ - */ -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -bind(int fd, const struct sockaddr * name, socklen_t namelen) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = _thread_sys_bind(fd, name, namelen); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_cancel.c b/lib/libpthread/uthread/uthread_cancel.c deleted file mode 100644 index b133dd4ca57..00000000000 --- a/lib/libpthread/uthread/uthread_cancel.c +++ /dev/null @@ -1,245 +0,0 @@ -/* $OpenBSD: uthread_cancel.c,v 1.18 2011/10/07 08:59:43 fgsch Exp $ */ -/* - * David Leonard <d@openbsd.org>, 1999. Public domain. - */ -#include <errno.h> -#include <pthread.h> -#include "pthread_private.h" - -static void finish_cancellation(struct pthread *); - -int -pthread_cancel(pthread_t pthread) -{ - int ret; - - if ((ret = _find_thread(pthread)) != 0) { - /* NOTHING */ - } else if (pthread->state == PS_DEAD || pthread->state == PS_DEADLOCK - || (pthread->flags & PTHREAD_EXITING) != 0) { - ret = 0; - } else { - /* Protect the scheduling queues: */ - _thread_kern_sig_defer(); - - if (((pthread->cancelflags & PTHREAD_CANCEL_DISABLE) != 0) || - (((pthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) == 0) && - ((pthread->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0))) - /* Just mark it for cancellation: */ - pthread->cancelflags |= PTHREAD_CANCELLING; - else { - /* - * Check if we need to kick it back into the - * run queue: - */ - switch (pthread->state) { - case PS_RUNNING: - /* No need to resume: */ - pthread->cancelflags |= PTHREAD_CANCELLING; - break; - - case PS_SPINBLOCK: - case PS_CONNECT_WAIT: - case PS_FDR_WAIT: - case PS_FDW_WAIT: - case PS_KEVENT_WAIT: - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Remove these threads from the work queue: */ - if ((pthread->flags & PTHREAD_FLAGS_IN_WORKQ) - != 0) - PTHREAD_WORKQ_REMOVE(pthread); - /* Fall through: */ - case PS_SIGTHREAD: - case PS_SLEEP_WAIT: - case PS_WAIT_WAIT: - case PS_SIGSUSPEND: - case PS_SIGWAIT: - /* Interrupt and resume: */ - pthread->interrupted = 1; - pthread->cancelflags |= PTHREAD_CANCELLING; - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - break; - - case PS_JOIN: - /* - * Disconnect the thread from the joinee: - */ - if (pthread->join_status.thread != NULL) { - pthread->join_status.thread->joiner - = NULL; - pthread->join_status.thread = NULL; - } - pthread->cancelflags |= PTHREAD_CANCELLING; - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - break; - - case PS_SUSPENDED: - if (pthread->suspended == SUSP_NO || - pthread->suspended == SUSP_YES || - pthread->suspended == SUSP_JOIN || - pthread->suspended == SUSP_NOWAIT) { - /* - * This thread isn't in any scheduling - * queues; just change it's state: - */ - pthread->cancelflags |= - PTHREAD_CANCELLING; - PTHREAD_SET_STATE(pthread, PS_RUNNING); - break; - } - /* FALLTHROUGH */ - case PS_MUTEX_WAIT: - case PS_COND_WAIT: - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FILE_WAIT: - /* - * Threads in these states may be in queues. - * In order to preserve queue integrity, the - * cancelled thread must remove itself from the - * queue. Mark the thread as interrupted and - * needing cancellation, and set the state to - * running. When the thread resumes, it will - * remove itself from the queue and call the - * cancellation completion routine. - */ - pthread->interrupted = 1; - pthread->cancelflags |= PTHREAD_CANCEL_NEEDED; - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - pthread->continuation = finish_cancellation; - break; - - case PS_DEAD: - case PS_DEADLOCK: - case PS_STATE_MAX: - /* Ignore - only here to silence -Wall: */ - break; - } - } - - /* Unprotect the scheduling queues: */ - _thread_kern_sig_undefer(); - - ret = 0; - } - return (ret); -} - -int -pthread_setcancelstate(int state, int *oldstate) -{ - struct pthread *curthread = _get_curthread(); - int ostate; - int ret; - - ostate = curthread->cancelflags & PTHREAD_CANCEL_DISABLE; - - switch (state) { - case PTHREAD_CANCEL_ENABLE: - if (oldstate != NULL) - *oldstate = ostate; - curthread->cancelflags &= ~PTHREAD_CANCEL_DISABLE; - if ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0) - pthread_testcancel(); - ret = 0; - break; - case PTHREAD_CANCEL_DISABLE: - if (oldstate != NULL) - *oldstate = ostate; - curthread->cancelflags |= PTHREAD_CANCEL_DISABLE; - ret = 0; - break; - default: - ret = EINVAL; - } - - return (ret); -} - - -int -pthread_setcanceltype(int type, int *oldtype) -{ - struct pthread *curthread = _get_curthread(); - int otype; - int ret; - - otype = curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS; - switch (type) { - case PTHREAD_CANCEL_ASYNCHRONOUS: - if (oldtype != NULL) - *oldtype = otype; - curthread->cancelflags |= PTHREAD_CANCEL_ASYNCHRONOUS; - pthread_testcancel(); - ret = 0; - break; - case PTHREAD_CANCEL_DEFERRED: - if (oldtype != NULL) - *oldtype = otype; - curthread->cancelflags &= ~PTHREAD_CANCEL_ASYNCHRONOUS; - ret = 0; - break; - default: - ret = EINVAL; - } - - return (ret); -} - -void -pthread_testcancel(void) -{ - struct pthread *curthread = _get_curthread(); - - if (((curthread->cancelflags & PTHREAD_CANCEL_DISABLE) == 0) && - ((curthread->cancelflags & PTHREAD_CANCELLING) != 0) && - ((curthread->flags & PTHREAD_EXITING) == 0)) { - /* - * It is possible for this thread to be swapped out - * while performing cancellation; do not allow it - * to be cancelled again. - */ - curthread->cancelflags &= ~PTHREAD_CANCELLING; -#ifdef notyet - _thread_exit_cleanup(); -#endif - pthread_exit(PTHREAD_CANCELED); - PANIC("cancel"); - } -} - -void -_thread_enter_cancellation_point(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Look for a cancellation before we block: */ - pthread_testcancel(); - curthread->cancelflags |= PTHREAD_AT_CANCEL_POINT; -} - -void -_thread_leave_cancellation_point(void) -{ - struct pthread *curthread = _get_curthread(); - - curthread->cancelflags &= ~PTHREAD_AT_CANCEL_POINT; - /* Look for a cancellation after we unblock: */ - pthread_testcancel(); -} - -static void -finish_cancellation(struct pthread *curthread) -{ - curthread->continuation = NULL; - curthread->interrupted = 0; - - if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) { - curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED; -#ifdef notyet - _thread_exit_cleanup(); -#endif - pthread_exit(PTHREAD_CANCELED); - } -} diff --git a/lib/libpthread/uthread/uthread_clean.c b/lib/libpthread/uthread/uthread_clean.c deleted file mode 100644 index ed6df7d70b6..00000000000 --- a/lib/libpthread/uthread/uthread_clean.c +++ /dev/null @@ -1,72 +0,0 @@ -/* $OpenBSD: uthread_clean.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_clean.c,v 1.4 1999/08/28 00:03:26 peter Exp $ - */ -#include <signal.h> -#include <errno.h> -#include <stdlib.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -void -pthread_cleanup_push(void (*routine) (void *), void *routine_arg) -{ - struct pthread *curthread = _get_curthread(); - struct pthread_cleanup *new; - - if ((new = (struct pthread_cleanup *) malloc(sizeof(struct pthread_cleanup))) != NULL) { - new->routine = routine; - new->routine_arg = routine_arg; - new->next = curthread->cleanup; - - curthread->cleanup = new; - } -} - -void -pthread_cleanup_pop(int execute) -{ - struct pthread *curthread = _get_curthread(); - struct pthread_cleanup *old; - - if ((old = curthread->cleanup) != NULL) { - curthread->cleanup = old->next; - if (execute) { - old->routine(old->routine_arg); - } - free(old); - } -} - -#endif diff --git a/lib/libpthread/uthread/uthread_close.c b/lib/libpthread/uthread/uthread_close.c deleted file mode 100644 index fece136c9eb..00000000000 --- a/lib/libpthread/uthread/uthread_close.c +++ /dev/null @@ -1,77 +0,0 @@ -/* $OpenBSD: uthread_close.c,v 1.15 2009/12/06 17:54:59 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_close.c,v 1.7 1999/08/28 00:03:26 peter Exp $ - */ -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -close(int fd) -{ - int ret; - - /* This is a cancelation point: */ - _thread_enter_cancellation_point(); - - if ((fd < 0) || (fd >= _thread_max_fdtsize) || - (fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1])) { - errno = EBADF; - ret = -1; - } else if ((ret = _FD_LOCK(fd, FD_RDWR_CLOSE, NULL)) != -1) { - /* - * We need to hold the entry spinlock till after - * _thread_sys_close() to stop races caused by the - * fd state transition. - */ - _thread_kern_sig_defer(); - - _thread_fd_entry_close(fd); - - /* Close the file descriptor: */ - ret = _thread_sys_close(fd); - - _thread_kern_sig_undefer(); - - _FD_UNLOCK(fd, FD_RDWR_CLOSE); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_closefrom.c b/lib/libpthread/uthread/uthread_closefrom.c deleted file mode 100644 index 4747aa20db8..00000000000 --- a/lib/libpthread/uthread/uthread_closefrom.c +++ /dev/null @@ -1,90 +0,0 @@ -/* $OpenBSD: uthread_closefrom.c,v 1.5 2011/04/09 14:48:09 miod Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ - -#include <sys/stat.h> - -#include <errno.h> -#include <stdlib.h> -#include <pthread.h> -#include <unistd.h> - -#include "pthread_private.h" - -int -closefrom(int fd) -{ - int ret = 0; - int safe_fd; - int lock_fd; - int *flags; - - _thread_enter_cancellation_point(); - - if (fd < 0 || fd >= _thread_max_fdtsize) { - errno = EBADF; - ret = -1; - } else { - safe_fd = _thread_kern_pipe[0] > _thread_kern_pipe[1] ? - _thread_kern_pipe[0] : _thread_kern_pipe[1]; - - /* - * close individual files until we get past the pipe - * fds. Attempting to close a pipe fd is a no-op. - */ - for (safe_fd++; fd < safe_fd; fd++) - close(fd); - - flags = calloc((size_t)_thread_max_fdtsize, sizeof *flags); - if (flags == NULL) { - /* use calloc errno */ - ret = -1; - } else { - /* Lock and record all fd entries */ - for (lock_fd = fd; lock_fd < _thread_max_fdtsize; lock_fd++) { - if (_thread_fd_table[lock_fd] != NULL && - _thread_fd_table[lock_fd]->state != FD_ENTRY_CLOSED) { - ret = _FD_LOCK(lock_fd, FD_RDWR_CLOSE, NULL); - if (ret != -1) - flags[lock_fd] = 1; - else - break; - } - } - - if (ret != -1) { - /* - * Close the entries and reset the non-bocking - * flag when needed. - */ - for (lock_fd = fd; lock_fd < _thread_max_fdtsize; lock_fd++) { - if (flags[lock_fd] != 0) { - _thread_fd_entry_close(lock_fd); - } - } - /* - * Now let the system do its thing. It is not practical - * to try to prevent races with other threads that can - * create new file descriptors. We just have to assume - * the application is well behaved when using closefrom. - */ - ret = _thread_sys_closefrom(fd); - } - - /* - * Unlock any locked entries. - */ - for (lock_fd = fd; lock_fd < _thread_max_fdtsize; lock_fd++) { - if (flags[lock_fd] != 0) { - _FD_UNLOCK(lock_fd, FD_RDWR_CLOSE); - } - } - free(flags); - } - } - - _thread_leave_cancellation_point(); - - return (ret); - -} diff --git a/lib/libpthread/uthread/uthread_concurrency.c b/lib/libpthread/uthread/uthread_concurrency.c deleted file mode 100644 index a82e976ab4a..00000000000 --- a/lib/libpthread/uthread/uthread_concurrency.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD: uthread_concurrency.c,v 1.1 2003/12/23 22:37:03 brad Exp $ */ - -/* - * Copyright (c) 2003 Sergey Osokin <osa@FreeBSD.org.ru>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Sergey Osokin. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY SERGEY OSOKIN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc_r/uthread/uthread_concurrency.c,v 1.1 2003/04/20 01:53:12 jdp Exp $ - */ - -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -static int current_concurrency = 0; - -int -pthread_getconcurrency(void) -{ - return current_concurrency; -} - -int -pthread_setconcurrency(int new_level) -{ - int ret; - - if (new_level < 0) { - ret = EINVAL; - } else { - current_concurrency = new_level; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_cond.c b/lib/libpthread/uthread/uthread_cond.c deleted file mode 100644 index 8e21247d5fc..00000000000 --- a/lib/libpthread/uthread/uthread_cond.c +++ /dev/null @@ -1,717 +0,0 @@ -/* $OpenBSD: uthread_cond.c,v 1.15 2007/04/27 19:40:08 kurt Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_cond.c,v 1.18 1999/08/30 00:02:07 deischen Exp $ - */ -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * Prototypes - */ -static inline pthread_t cond_queue_deq(pthread_cond_t); -static inline void cond_queue_remove(pthread_cond_t, pthread_t); -static inline void cond_queue_enq(pthread_cond_t, pthread_t); - -/* Reinitialize a condition variable to defaults. */ -int -_cond_reinit(pthread_cond_t *cond) -{ - int ret = 0; - - if (cond == NULL) - ret = EINVAL; - else if (*cond == NULL) - ret = pthread_cond_init(cond, NULL); - else { - /* - * Initialize the condition variable structure: - */ - TAILQ_INIT(&(*cond)->c_queue); - (*cond)->c_flags = COND_FLAGS_INITED; - (*cond)->c_type = COND_TYPE_FAST; - (*cond)->c_mutex = NULL; - (*cond)->c_seqno = 0; - _SPINLOCK_INIT(&(*cond)->lock); - } - return (ret); -} - -int -pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr) -{ - enum pthread_cond_type type; - pthread_cond_t pcond; - int rval = 0; - - if (cond == NULL) - rval = EINVAL; - else { - /* - * Check if a pointer to a condition variable attribute - * structure was passed by the caller: - */ - if (cond_attr != NULL && *cond_attr != NULL) { - /* Default to a fast condition variable: */ - type = (*cond_attr)->c_type; - } else { - /* Default to a fast condition variable: */ - type = COND_TYPE_FAST; - } - - /* Process according to condition variable type: */ - switch (type) { - /* Fast condition variable: */ - case COND_TYPE_FAST: - /* Nothing to do here. */ - break; - - /* Trap invalid condition variable types: */ - default: - /* Return an invalid argument error: */ - rval = EINVAL; - break; - } - - /* Check for no errors: */ - if (rval == 0) { - if ((pcond = (pthread_cond_t) - malloc(sizeof(struct pthread_cond))) == NULL) { - rval = ENOMEM; - } else { - /* - * Initialise the condition variable - * structure: - */ - TAILQ_INIT(&pcond->c_queue); - pcond->c_flags |= COND_FLAGS_INITED; - pcond->c_type = type; - pcond->c_mutex = NULL; - pcond->c_seqno = 0; - _SPINLOCK_INIT(&pcond->lock); - *cond = pcond; - } - } - } - /* Return the completion status: */ - return (rval); -} - -int -pthread_cond_destroy(pthread_cond_t * cond) -{ - int rval = 0; - - if (cond == NULL || *cond == NULL) - rval = EINVAL; - else { - /* Lock the condition variable structure: */ - _SPINLOCK(&(*cond)->lock); - - /* - * Free the memory allocated for the condition - * variable structure: - */ - free(*cond); - - /* - * NULL the caller's pointer now that the condition - * variable has been destroyed: - */ - *cond = NULL; - } - /* Return the completion status: */ - return (rval); -} - -int -pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) -{ - struct pthread *curthread = _get_curthread(); - int rval = 0; - int done = 0; - int interrupted = 0; - int seqno; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if (cond == NULL) { - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - return (EINVAL); - } - - /* - * If the condition variable is statically initialized, - * perform the dynamic initialization: - */ - if (*cond == NULL && - (rval = pthread_cond_init(cond, NULL)) != 0) { - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - return (rval); - } - - /* - * Enter a loop waiting for a condition signal or broadcast - * to wake up this thread. A loop is needed in case the waiting - * thread is interrupted by a signal to execute a signal handler. - * It is not (currently) possible to remain in the waiting queue - * while running a handler. Instead, the thread is interrupted - * and backed out of the waiting queue prior to executing the - * signal handler. - */ - do { - /* Lock the condition variable structure: */ - _SPINLOCK(&(*cond)->lock); - - /* - * If the condvar was statically allocated, properly - * initialize the tail queue. - */ - if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) { - TAILQ_INIT(&(*cond)->c_queue); - (*cond)->c_flags |= COND_FLAGS_INITED; - } - - /* Process according to condition variable type: */ - switch ((*cond)->c_type) { - /* Fast condition variable: */ - case COND_TYPE_FAST: - if ((mutex == NULL) || (((*cond)->c_mutex != NULL) && - ((*cond)->c_mutex != *mutex))) { - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - - /* Return invalid argument error: */ - rval = EINVAL; - } else { - /* Reset the timeout and interrupted flags: */ - curthread->timeout = 0; - curthread->interrupted = 0; - - /* - * Queue the running thread for the condition - * variable: - */ - cond_queue_enq(*cond, curthread); - - /* Remember the mutex and sequence number: */ - (*cond)->c_mutex = *mutex; - seqno = (*cond)->c_seqno; - - /* Wait forever: */ - curthread->wakeup_time.tv_sec = -1; - - /* Unlock the mutex: */ - if ((rval = _mutex_cv_unlock(mutex)) != 0) { - /* - * Cannot unlock the mutex, so remove - * the running thread from the condition - * variable queue: - */ - cond_queue_remove(*cond, curthread); - - /* Check for no more waiters: */ - if (TAILQ_FIRST(&(*cond)->c_queue) == - NULL) - (*cond)->c_mutex = NULL; - - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - } else { - /* - * Schedule the next thread and unlock - * the condition variable structure: - */ - _thread_kern_sched_state_unlock(PS_COND_WAIT, - &(*cond)->lock, __FILE__, __LINE__); - - done = (seqno != (*cond)->c_seqno); - - interrupted = curthread->interrupted; - - /* - * Check if the wait was interrupted - * (canceled) or needs to be resumed - * after handling a signal. - */ - if (interrupted != 0) { - /* - * Lock the mutex and ignore any - * errors. Note that even - * though this thread may have - * been canceled, POSIX requires - * that the mutex be reacquired - * prior to cancellation. - */ - (void)_mutex_cv_lock(mutex); - } else { - /* - * Lock the condition variable - * while removing the thread. - */ - _SPINLOCK(&(*cond)->lock); - - cond_queue_remove(*cond, - curthread); - - /* Check for no more waiters: */ - if (TAILQ_FIRST(&(*cond)->c_queue) == NULL) - (*cond)->c_mutex = NULL; - - _SPINUNLOCK(&(*cond)->lock); - - /* Lock the mutex: */ - rval = _mutex_cv_lock(mutex); - } - } - } - break; - - /* Trap invalid condition variable types: */ - default: - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - - /* Return an invalid argument error: */ - rval = EINVAL; - break; - } - - if ((interrupted != 0) && (curthread->continuation != NULL)) - curthread->continuation(curthread); - } while ((done == 0) && (rval == 0)); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (rval); -} - -int -pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, - const struct timespec * abstime) -{ - struct pthread *curthread = _get_curthread(); - int rval = 0; - int done = 0; - int interrupted = 0; - int seqno; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if (cond == NULL || - abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 || - abstime->tv_nsec >= 1000000000) { - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - return (EINVAL); - } - /* - * If the condition variable is statically initialized, perform dynamic - * initialization. - */ - if (*cond == NULL && (rval = pthread_cond_init(cond, NULL)) != 0) { - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - return (rval); - } - - /* - * Enter a loop waiting for a condition signal or broadcast - * to wake up this thread. A loop is needed in case the waiting - * thread is interrupted by a signal to execute a signal handler. - * It is not (currently) possible to remain in the waiting queue - * while running a handler. Instead, the thread is interrupted - * and backed out of the waiting queue prior to executing the - * signal handler. - */ - do { - /* Lock the condition variable structure: */ - _SPINLOCK(&(*cond)->lock); - - /* - * If the condvar was statically allocated, properly - * initialize the tail queue. - */ - if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) { - TAILQ_INIT(&(*cond)->c_queue); - (*cond)->c_flags |= COND_FLAGS_INITED; - } - - /* Process according to condition variable type: */ - switch ((*cond)->c_type) { - /* Fast condition variable: */ - case COND_TYPE_FAST: - if ((mutex == NULL) || (((*cond)->c_mutex != NULL) && - ((*cond)->c_mutex != *mutex))) { - /* Return invalid argument error: */ - rval = EINVAL; - - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - } else { - /* Set the wakeup time: */ - curthread->wakeup_time.tv_sec = - abstime->tv_sec; - curthread->wakeup_time.tv_nsec = - abstime->tv_nsec; - - /* Reset the timeout and interrupted flags: */ - curthread->timeout = 0; - curthread->interrupted = 0; - - /* - * Queue the running thread for the condition - * variable: - */ - cond_queue_enq(*cond, curthread); - - /* Remember the mutex and sequence number: */ - (*cond)->c_mutex = *mutex; - seqno = (*cond)->c_seqno; - - /* Unlock the mutex: */ - if ((rval = _mutex_cv_unlock(mutex)) != 0) { - /* - * Cannot unlock the mutex, so remove - * the running thread from the condition - * variable queue: - */ - cond_queue_remove(*cond, curthread); - - /* Check for no more waiters: */ - if (TAILQ_FIRST(&(*cond)->c_queue) == NULL) - (*cond)->c_mutex = NULL; - - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - } else { - /* - * Schedule the next thread and unlock - * the condition variable structure: - */ - _thread_kern_sched_state_unlock(PS_COND_WAIT, - &(*cond)->lock, __FILE__, __LINE__); - - done = (seqno != (*cond)->c_seqno); - - interrupted = curthread->interrupted; - - /* - * Check if the wait was interrupted - * (canceled) or needs to be resumed - * after handling a signal. - */ - if (interrupted != 0) { - /* - * Lock the mutex and ignore any - * errors. Note that even - * though this thread may have - * been canceled, POSIX requires - * that the mutex be reacquired - * prior to cancellation. - */ - (void)_mutex_cv_lock(mutex); - } else { - /* - * Lock the condition variable - * while removing the thread. - */ - _SPINLOCK(&(*cond)->lock); - - cond_queue_remove(*cond, - curthread); - - /* Check for no more waiters: */ - if (TAILQ_FIRST(&(*cond)->c_queue) == NULL) - (*cond)->c_mutex = NULL; - - _SPINUNLOCK(&(*cond)->lock); - - /* Lock the mutex: */ - rval = _mutex_cv_lock(mutex); - - /* - * Return ETIMEDOUT if the wait - * timed out and there wasn't an - * error locking the mutex: - */ - if ((curthread->timeout != 0) - && rval == 0) - rval = ETIMEDOUT; - - } - } - } - break; - - /* Trap invalid condition variable types: */ - default: - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - - /* Return an invalid argument error: */ - rval = EINVAL; - break; - } - - if ((interrupted != 0) && (curthread->continuation != NULL)) - curthread->continuation(curthread); - } while ((done == 0) && (rval == 0)); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (rval); -} - -int -pthread_cond_signal(pthread_cond_t * cond) -{ - int rval = 0; - pthread_t pthread; - - if (cond == NULL) - rval = EINVAL; - /* - * If the condition variable is statically initialized, perform dynamic - * initialization. - */ - else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL)) == 0) { - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the condition variable structure: */ - _SPINLOCK(&(*cond)->lock); - - /* Process according to condition variable type: */ - switch ((*cond)->c_type) { - /* Fast condition variable: */ - case COND_TYPE_FAST: - /* Increment the sequence number: */ - (*cond)->c_seqno++; - - if ((pthread = cond_queue_deq(*cond)) != NULL) { - /* - * Unless the thread is currently suspended, - * allow it to run. If the thread is suspended, - * make a note that the thread isn't in a wait - * queue any more. - */ - if (pthread->state != PS_SUSPENDED) - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - else - pthread->suspended = SUSP_NOWAIT; - } - - /* Check for no more waiters: */ - if (TAILQ_FIRST(&(*cond)->c_queue) == NULL) - (*cond)->c_mutex = NULL; - break; - - /* Trap invalid condition variable types: */ - default: - /* Return an invalid argument error: */ - rval = EINVAL; - break; - } - - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (rval); -} - -int -pthread_cond_broadcast(pthread_cond_t * cond) -{ - int rval = 0; - pthread_t pthread; - - if (cond == NULL) - rval = EINVAL; - /* - * If the condition variable is statically initialized, perform dynamic - * initialization. - */ - else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL)) == 0) { - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the condition variable structure: */ - _SPINLOCK(&(*cond)->lock); - - /* Process according to condition variable type: */ - switch ((*cond)->c_type) { - /* Fast condition variable: */ - case COND_TYPE_FAST: - /* Increment the sequence number: */ - (*cond)->c_seqno++; - - /* - * Enter a loop to bring all threads off the - * condition queue: - */ - while ((pthread = cond_queue_deq(*cond)) != NULL) { - /* - * Unless the thread is currently suspended, - * allow it to run. If the thread is suspended, - * make a note that the thread isn't in a wait - * queue any more. - */ - if (pthread->state != PS_SUSPENDED) - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - else - pthread->suspended = SUSP_NOWAIT; - } - - /* There are no more waiting threads: */ - (*cond)->c_mutex = NULL; - break; - - /* Trap invalid condition variable types: */ - default: - /* Return an invalid argument error: */ - rval = EINVAL; - break; - } - - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (rval); -} - -/* - * Dequeue a waiting thread from the head of a condition queue in - * descending priority order. - */ -static inline pthread_t -cond_queue_deq(pthread_cond_t cond) -{ - pthread_t pthread; - - while ((pthread = TAILQ_FIRST(&cond->c_queue)) != NULL) { - TAILQ_REMOVE(&cond->c_queue, pthread, sqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_CONDQ; - if ((pthread->timeout == 0) && (pthread->interrupted == 0)) - /* - * Only exit the loop when we find a thread - * that hasn't timed out or been canceled; - * those threads are already running and don't - * need their run state changed. - */ - break; - } - - return(pthread); -} - -/* - * Remove a waiting thread from a condition queue in descending priority - * order. - */ -static inline void -cond_queue_remove(pthread_cond_t cond, pthread_t pthread) -{ - /* - * Because pthread_cond_timedwait() can timeout as well - * as be signaled by another thread, it is necessary to - * guard against removing the thread from the queue if - * it isn't in the queue. - */ - if (pthread->flags & PTHREAD_FLAGS_IN_CONDQ) { - TAILQ_REMOVE(&cond->c_queue, pthread, sqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_CONDQ; - } -} - -/* - * Enqueue a waiting thread to a condition queue in descending priority - * order. - */ -static inline void -cond_queue_enq(pthread_cond_t cond, pthread_t pthread) -{ - pthread_t tid = TAILQ_LAST(&cond->c_queue, cond_head); - - PTHREAD_ASSERT_NOT_IN_SYNCQ(pthread); - - /* - * For the common case of all threads having equal priority, - * we perform a quick check against the priority of the thread - * at the tail of the queue. - */ - if ((tid == NULL) || (pthread->active_priority <= tid->active_priority)) - TAILQ_INSERT_TAIL(&cond->c_queue, pthread, sqe); - else { - tid = TAILQ_FIRST(&cond->c_queue); - while (pthread->active_priority <= tid->active_priority) - tid = TAILQ_NEXT(tid, sqe); - TAILQ_INSERT_BEFORE(tid, pthread, sqe); - } - pthread->flags |= PTHREAD_FLAGS_IN_CONDQ; - pthread->data.cond = cond; -} -#endif diff --git a/lib/libpthread/uthread/uthread_condattr_destroy.c b/lib/libpthread/uthread/uthread_condattr_destroy.c deleted file mode 100644 index 08769b87dd3..00000000000 --- a/lib/libpthread/uthread/uthread_condattr_destroy.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: uthread_condattr_destroy.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_condattr_destroy.c,v 1.4 1999/08/28 00:03:27 peter Exp $ - */ -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_condattr_destroy(pthread_condattr_t *attr) -{ - int ret; - if (attr == NULL || *attr == NULL) { - ret = EINVAL; - } else { - free(*attr); - *attr = NULL; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_condattr_init.c b/lib/libpthread/uthread/uthread_condattr_init.c deleted file mode 100644 index 298989ccef4..00000000000 --- a/lib/libpthread/uthread/uthread_condattr_init.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_condattr_init.c,v 1.3 1999/11/25 07:01:33 d Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_condattr_init.c,v 1.4 1999/08/28 00:03:27 peter Exp $ - */ -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_condattr_init(pthread_condattr_t *attr) -{ - int ret; - pthread_condattr_t pattr; - - if ((pattr = (pthread_condattr_t) - malloc(sizeof(struct pthread_cond_attr))) == NULL) { - ret = ENOMEM; - } else { - memcpy(pattr, &pthread_condattr_default, - sizeof(struct pthread_cond_attr)); - *attr = pattr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_connect.c b/lib/libpthread/uthread/uthread_connect.c deleted file mode 100644 index b160df91dbc..00000000000 --- a/lib/libpthread/uthread/uthread_connect.c +++ /dev/null @@ -1,107 +0,0 @@ -/* $OpenBSD: uthread_connect.c,v 1.9 2011/10/07 08:59:43 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_connect.c,v 1.6 1999/08/28 00:03:28 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -connect(int fd, const struct sockaddr * name, socklen_t namelen) -{ - struct pthread *curthread = _get_curthread(); - struct sockaddr tmpname; - socklen_t errnolen, tmpnamelen; - int ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - if ((ret = _thread_sys_connect(fd, name, namelen)) < 0) { - if (!(_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) && - ((errno == EWOULDBLOCK) || (errno == EINPROGRESS) || - (errno == EALREADY) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - curthread->closing_fd = 0; - - /* Set the timeout: */ - _thread_kern_set_timeout(NULL); - _thread_kern_sched_state(PS_CONNECT_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal or - * a closing fd. - */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - } else if (curthread->closing_fd) { - errno = EBADF; - ret = -1; - } else { - tmpnamelen = sizeof(tmpname); - /* 0 now lets see if it really worked */ - if (((ret = _thread_sys_getpeername(fd, &tmpname, &tmpnamelen)) < 0) && - (errno == ENOTCONN)) { - - /* - * Get the error, this function - * should not fail - */ - errnolen = sizeof(errno); - _thread_sys_getsockopt(fd, SOL_SOCKET, SO_ERROR, &errno, &errnolen); - } - } - } else { - ret = -1; - } - } - _FD_UNLOCK(fd, FD_RDWR); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_create.c b/lib/libpthread/uthread/uthread_create.c deleted file mode 100644 index e2248a9aef8..00000000000 --- a/lib/libpthread/uthread/uthread_create.c +++ /dev/null @@ -1,247 +0,0 @@ -/* $OpenBSD: uthread_create.c,v 1.25 2010/07/13 04:24:46 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_create.c,v 1.19 1999/08/28 00:03:28 peter Exp $ - */ -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <stddef.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/mman.h> -#ifdef _THREAD_SAFE -#include <machine/reg.h> -#include <pthread.h> -#include "pthread_private.h" - -/* Symbols that help gdb find the information it needs. */ -int _thread_next_offset = offsetof(struct pthread, tle.tqe_next); -int _thread_state_offset = offsetof(struct pthread, state); -int _thread_ctx_offset = offsetof(struct pthread, _machdep); - -int -pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) -{ - struct pthread *curthread = _get_curthread(); - struct itimerval itimer; - int f_gc = 0; - int ret = 0; - pthread_t gc_thread; - pthread_t new_thread; - pthread_attr_t pattr; - struct stack *stack; - - if (thread == NULL) - return(EINVAL); - - /* - * Locking functions in libc are required when there are - * threads other than the initial thread. - */ - __isthreaded = 1; - - /* Allocate memory for the thread structure: */ - if ((new_thread = (pthread_t) malloc(sizeof(struct pthread))) == NULL) { - /* Insufficient memory to create a thread: */ - ret = EAGAIN; - } else { - /* Check if default thread attributes are required: */ - if (attr == NULL || *attr == NULL) { - /* Use the default thread attributes: */ - pattr = &pthread_attr_default; - } else { - pattr = *attr; - } - - /* Allocate a stack: */ - stack = _thread_stack_alloc(pattr->stackaddr_attr, - pattr->stacksize_attr, pattr->guardsize_attr); - if (stack == NULL) { - ret = EAGAIN; - free(new_thread); - } - - /* Check for errors: */ - if (ret != 0) { - } else { - /* Initialise the thread structure: */ - memset(new_thread, 0, sizeof(struct pthread)); - _SPINLOCK_INIT(&new_thread->lock); - new_thread->slice_usec = -1; - new_thread->sig_saved = 0; - new_thread->stack = stack; - new_thread->start_routine = start_routine; - new_thread->arg = arg; - - new_thread->cancelflags = PTHREAD_CANCEL_ENABLE | - PTHREAD_CANCEL_DEFERRED; - - /* - * Write a magic value to the thread structure - * to help identify valid ones: - */ - new_thread->magic = PTHREAD_MAGIC; - - /* Initialise the thread for signals: */ - new_thread->sigmask = curthread->sigmask; - - /* - * Set up new stack frame so that it 'returns' to - * the beginning of _thread_start() after it is - * switched to: - */ - _thread_machdep_init(&new_thread->_machdep, - stack->base, stack->size, _thread_start); - - /* Copy the thread attributes: */ - memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr)); - - /* - * Check if this thread is to inherit the scheduling - * attributes from its parent: - */ - if (new_thread->attr.flags & PTHREAD_INHERIT_SCHED) { - /* Copy the scheduling attributes: */ - new_thread->base_priority = - curthread->base_priority & - ~PTHREAD_SIGNAL_PRIORITY; - new_thread->attr.prio = - curthread->base_priority & - ~PTHREAD_SIGNAL_PRIORITY; - new_thread->attr.sched_policy = - curthread->attr.sched_policy; - } else { - /* - * Use just the thread priority, leaving the - * other scheduling attributes as their - * default values: - */ - new_thread->base_priority = - new_thread->attr.prio; - } - new_thread->active_priority = new_thread->base_priority; - new_thread->inherited_priority = 0; - - /* Initialize joiner to NULL (no joiner): */ - new_thread->joiner = NULL; - - /* Initialize the mutex queue: */ - TAILQ_INIT(&new_thread->mutexq); - - /* Initialise hooks in the thread structure: */ - new_thread->specific_data = NULL; - new_thread->cleanup = NULL; - new_thread->flags = 0; - new_thread->poll_data.nfds = 0; - new_thread->poll_data.fds = NULL; - new_thread->continuation = NULL; - - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* - * Check if the garbage collector thread - * needs to be started. - */ - f_gc = (TAILQ_FIRST(&_thread_list) == _thread_initial - && start_routine != _thread_gc); - - /* Add the thread to the linked list of all threads: */ - TAILQ_INSERT_HEAD(&_thread_list, new_thread, tle); - - if (pattr->suspend == PTHREAD_CREATE_SUSPENDED) - new_thread->state = PS_SUSPENDED; - else { - new_thread->state = PS_RUNNING; - PTHREAD_PRIOQ_INSERT_TAIL(new_thread); - } - - /* - * Undefer and handle pending signals, yielding - * if necessary. - */ - _thread_kern_sig_undefer(); - - /* Return a pointer to the thread structure: */ - if (thread != NULL) - (*thread) = new_thread; - - if (f_gc != 0) { - /* Install the scheduling timer: */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = _clock_res_usec; - itimer.it_value = itimer.it_interval; - if (setitimer(_ITIMER_SCHED_TIMER, &itimer, - NULL) != 0) - PANIC("Cannot set interval timer"); - } - - /* Schedule the new user thread: */ - _thread_kern_sched(NULL); - - /* - * Start a garbage collector thread - * if necessary. - */ - if (f_gc && pthread_create(&gc_thread,NULL, - _thread_gc,NULL) != 0) - PANIC("Can't create gc thread"); - - } - } - - /* Return the status: */ - return (ret); -} - -void -_thread_start(void) -{ - struct pthread *curthread = _get_curthread(); - - /* We just left the scheduler via longjmp: */ - _thread_kern_in_sched = 0; - - /* Run the current thread's start routine with argument: */ - pthread_exit(curthread->start_routine(curthread->arg)); - - /* This point should never be reached. */ - PANIC("Thread has resumed after exit"); -} -#endif diff --git a/lib/libpthread/uthread/uthread_detach.c b/lib/libpthread/uthread/uthread_detach.c deleted file mode 100644 index 92d41efedc4..00000000000 --- a/lib/libpthread/uthread/uthread_detach.c +++ /dev/null @@ -1,91 +0,0 @@ -/* $OpenBSD: uthread_detach.c,v 1.8 2002/03/07 22:36:03 fgsch Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_detach.c,v 1.10 1999/08/28 00:03:28 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_detach(pthread_t pthread) -{ - int rval = 0; - - /* Check for invalid calling parameters: */ - if (pthread == NULL || pthread->magic != PTHREAD_MAGIC) - /* Return an invalid argument error: */ - rval = EINVAL; - - /* Check if the thread has not been detached: */ - else if ((pthread->attr.flags & PTHREAD_DETACHED) == 0) { - /* Flag the thread as detached: */ - pthread->attr.flags |= PTHREAD_DETACHED; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Check if there is a joiner: */ - if (pthread->joiner != NULL) { - struct pthread *joiner = pthread->joiner; - - /* Make the thread runnable: */ - PTHREAD_NEW_STATE(joiner, PS_RUNNING); - - /* Set the return value for the woken thread: */ - joiner->join_status.error = ESRCH; - joiner->join_status.ret = NULL; - joiner->join_status.thread = NULL; - - /* - * Disconnect the joiner from the thread being detached: - */ - pthread->joiner = NULL; - } - - /* - * Undefer and handle pending signals, yielding if a - * scheduling signal occurred while in the critical region. - */ - _thread_kern_sig_undefer(); - } else - /* Return an error: */ - rval = EINVAL; - - /* Return the completion status: */ - return (rval); -} -#endif diff --git a/lib/libpthread/uthread/uthread_dup.c b/lib/libpthread/uthread/uthread_dup.c deleted file mode 100644 index af0fa71da6d..00000000000 --- a/lib/libpthread/uthread/uthread_dup.c +++ /dev/null @@ -1,28 +0,0 @@ -/* $OpenBSD: uthread_dup.c,v 1.7 2006/09/26 14:18:28 kurt Exp $ */ -/* PUBLIC DOMAIN <marc@snafu.org> */ - -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -dup(int fd) -{ - int ret; - - ret = _FD_LOCK(fd, FD_RDWR, NULL); - if (ret == 0) { - ret = _thread_sys_dup(fd); - if (ret != -1) { - if (_thread_fd_table_init(ret, FD_INIT_DUP, - _thread_fd_table[fd]->status_flags) == -1) { - _thread_sys_close(ret); - ret = -1; - } - } - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_dup2.c b/lib/libpthread/uthread/uthread_dup2.c deleted file mode 100644 index e2b57df8c5e..00000000000 --- a/lib/libpthread/uthread/uthread_dup2.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: uthread_dup2.c,v 1.13 2009/12/06 17:54:59 kurt Exp $ */ -/* PUBLIC DOMAIN <marc@snafu.org> */ - -#include <errno.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -dup2(int fd, int newfd) -{ - int ret = 0; - int saved_errno; - int *kern_pipe_fd = NULL; - - if (newfd < 0 || newfd >= _thread_max_fdtsize) { - errno = EBADF; - return(-1); - } - - /* - * Defer signals so another thread is not scheduled - * while we're checking and possibly moving the pipe fd. - */ - _thread_kern_sig_defer(); - - /* Check if newfd will collide with our internal pipe. */ - if (newfd == _thread_kern_pipe[0]) - kern_pipe_fd = &_thread_kern_pipe[0]; - else if (newfd == _thread_kern_pipe[1]) - kern_pipe_fd = &_thread_kern_pipe[1]; - - /* if we have a conflict move the internal pipe fd */ - if (kern_pipe_fd != NULL) { - ret = _thread_sys_dup(*kern_pipe_fd); - if (ret != -1) { - *kern_pipe_fd = ret; - ret = 0; - } - } - - _thread_kern_sig_undefer(); - - if (ret == 0) { - ret = _FD_LOCK(fd, FD_RDWR, NULL); - if (ret == 0) { - if ((ret = _FD_LOCK(newfd, FD_RDWR_CLOSE, NULL)) == 0) { - /* - * If newfd was open then drop reference - * and reset flags if needed. - */ - _thread_fs_flags_replace(newfd, NULL); - ret = _thread_sys_dup2(fd, newfd); - if (ret != -1) - if(_thread_fd_table_init(newfd, FD_INIT_DUP2, - _thread_fd_table[fd]->status_flags) == -1) - ret = -1; - - /* - * If the dup2 or the _thread_fd_table_init - * failed we've already removed the status - * flags, so finish closing newfd. Return - * the current errno in case the sys_close - * fails too. - */ - if (ret == -1) { - saved_errno = errno; - _thread_kern_sig_defer(); - - _thread_fd_entry_close(newfd); - _thread_sys_close(newfd); - - _thread_kern_sig_undefer(); - errno = saved_errno ; - } - _FD_UNLOCK(newfd, FD_RDWR_CLOSE); - } - _FD_UNLOCK(fd, FD_RDWR); - } - } - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_equal.c b/lib/libpthread/uthread/uthread_equal.c deleted file mode 100644 index 54da618366f..00000000000 --- a/lib/libpthread/uthread/uthread_equal.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $OpenBSD: uthread_equal.c,v 1.3 1999/11/25 07:01:33 d Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_equal.c,v 1.3 1999/08/28 00:03:29 peter Exp $ - */ -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_equal(pthread_t t1, pthread_t t2) -{ - /* Compare the two thread pointers: */ - return (t1 == t2); -} -#endif diff --git a/lib/libpthread/uthread/uthread_execve.c b/lib/libpthread/uthread/uthread_execve.c deleted file mode 100644 index ba910646021..00000000000 --- a/lib/libpthread/uthread/uthread_execve.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $OpenBSD: uthread_execve.c,v 1.12 2010/07/13 03:10:29 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_execve.c,v 1.8 1999/08/28 00:03:30 peter Exp $ - */ -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -execve(const char *name, char *const * argv, char *const * envp) -{ - struct pthread *curthread = _get_curthread(); - int flags; - int i; - int ret; - int err; - struct sigaction act; - struct itimerval itimer; - struct itimerval oitimer; - sigset_t oset; - - /* Disable the interval timer: */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = 0; - itimer.it_value.tv_usec = 0; - setitimer(_ITIMER_SCHED_TIMER, &itimer, &oitimer); - - /* - * Enter a loop to set all file descriptors to blocking - * if they were not created as non-blocking: - */ - for (i = 0; i < _thread_max_fdtsize; i++) { - /* Check if this file descriptor is in use: */ - if (_thread_fd_table[i] != NULL && - _thread_fd_table[i]->status_flags != NULL && - !(_thread_fd_table[i]->status_flags->flags & O_NONBLOCK)) { - /* Skip if the close-on-exec flag is set */ - flags = _thread_sys_fcntl(i, F_GETFD, NULL); - if ((flags & FD_CLOEXEC) != 0) - continue; /* don't bother, no point */ - /* Get the current flags: */ - flags = _thread_sys_fcntl(i, F_GETFL, NULL); - /* Clear the nonblocking file descriptor flag: */ - _thread_sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK); - } - } - -#define RESET_SIGNAL(sig) \ - (_thread_sigact[(sig) - 1].sa_handler == SIG_IGN && \ - _thread_sys_sigaction((sig), &_thread_sigact[(sig) - 1], NULL) != 0) - - /* Reset the behavior for the signals that the library uses */ - if (RESET_SIGNAL(_SCHED_SIGNAL) || - RESET_SIGNAL(SIGINFO) || - RESET_SIGNAL(SIGCHLD)) - PANIC("Cannot reset signal handlers"); - - /* Set the signal mask: */ - _thread_sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, &oset); - - /* Execute the process: */ - ret = _thread_sys_execve(name, argv, envp); - err = errno; - - /* execve failed; try to restore the state the thread library needs */ - -#define REINIT_SIGNAL(sig) \ - (_thread_sigact[(sig) - 1].sa_handler == SIG_IGN && \ - _thread_sys_sigaction((sig), &act, NULL) != 0) - - _thread_sys_sigprocmask(SIG_SETMASK, &oset, NULL); - sigfillset(&act.sa_mask); - act.sa_handler = (void (*) (int)) _thread_sig_handler; - act.sa_flags = SA_SIGINFO; - if (REINIT_SIGNAL(_SCHED_SIGNAL) || - REINIT_SIGNAL(SIGINFO) || - REINIT_SIGNAL(SIGCHLD)) - PANIC("Cannot reinitialize signal handlers"); - _thread_nonblock_fds(); - setitimer(_ITIMER_SCHED_TIMER, &oitimer, NULL); - - /* Return the completion status: */ - errno = err; - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_exit.c b/lib/libpthread/uthread/uthread_exit.c deleted file mode 100644 index 659cb9e81f8..00000000000 --- a/lib/libpthread/uthread/uthread_exit.c +++ /dev/null @@ -1,246 +0,0 @@ -/* $OpenBSD: uthread_exit.c,v 1.20 2007/04/27 12:59:24 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_exit.c,v 1.12 1999/08/30 15:45:42 dt Exp $ - */ -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <signal.h> -#include <sys/types.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -void -_exit(int status) -{ - int flags; - int i; - struct itimerval itimer; - - /* Disable the interval timer: */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = 0; - itimer.it_value.tv_usec = 0; - setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL); - - /* Close the pthread kernel pipe: */ - _thread_sys_close(_thread_kern_pipe[0]); - _thread_sys_close(_thread_kern_pipe[1]); - - /* - * Enter a loop to set all file descriptors to blocking - * if they were not created as non-blocking: - */ - for (i = 0; i < _thread_max_fdtsize; i++) { - /* Check if this file descriptor is in use: */ - if (_thread_fd_table[i] != NULL && - _thread_fd_table[i]->status_flags != NULL && - !(_thread_fd_table[i]->status_flags->flags & O_NONBLOCK)) { - /* Get the current flags: */ - flags = _thread_sys_fcntl(i, F_GETFL, NULL); - /* Clear the nonblocking file descriptor flag: */ - _thread_sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK); - } - } - - /* Call the _exit syscall: */ - _thread_sys__exit(status); -} - -static void -numlcat(char *s, int l, size_t sz) -{ - char digit[2]; - - /* Inefficient. */ - if (l < 0) { - l = -l; - strlcat(s, "-", sz); - } - if (l >= 10) - numlcat(s, l / 10, sz); - digit[0] = "0123456789"[l % 10]; - digit[1] = '\0'; - strlcat(s, digit, sz); -} - -void -_thread_exit(const char *fname, int lineno, const char *string) -{ - char s[256]; - - /* Prepare an error message string: */ - s[0] = '\0'; - strlcat(s, "pid ", sizeof s); - numlcat(s, (int)_thread_sys_getpid(), sizeof s); - strlcat(s, ": Fatal error '", sizeof s); - strlcat(s, string, sizeof s); - strlcat(s, "' at line ", sizeof s); - numlcat(s, lineno, sizeof s); - strlcat(s, " in file ", sizeof s); - strlcat(s, fname, sizeof s); - strlcat(s, " (errno = ", sizeof s); - numlcat(s, errno, sizeof s); - strlcat(s, ")\n", sizeof s); - - /* Write the string to the standard error file descriptor: */ - _thread_sys_write(2, s, strlen(s)); - - /* Force this process to exit: */ - /* XXX - Do we want abort to be conditional on _PTHREADS_INVARIANTS? */ -#if defined(_PTHREADS_INVARIANTS) - { - struct sigaction sa; - sigset_t s; - - /* Ignore everything except ABORT */ - sigfillset(&s); - sigdelset(&s, SIGABRT); - _thread_sys_sigprocmask(SIG_SETMASK, &s, NULL); - - /* Set the abort handler to default (dump core) */ - sa.sa_handler = SIG_DFL; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_SIGINFO; - (void)_thread_sys_sigaction(SIGABRT, &sa, NULL); - (void)_thread_sys_kill(_thread_sys_getpid(), SIGABRT); - for (;;) ; - } -#else - _exit(1); -#endif -} - -void -pthread_exit(void *status) -{ - struct pthread *curthread = _get_curthread(); - pthread_t pthread; - - /* Check if this thread is already in the process of exiting: */ - if ((curthread->flags & PTHREAD_EXITING) != 0) { - PANIC("Thread has called pthread_exit() from a destructor. POSIX 1003.1 1996 s16.2.5.2 does not allow this!"); - } - - /* Flag this thread as exiting: */ - curthread->flags |= PTHREAD_EXITING; - - /* Save the return value: */ - curthread->ret = status; - - while (curthread->cleanup != NULL) { - pthread_cleanup_pop(1); - } - if (curthread->attr.cleanup_attr != NULL) { - curthread->attr.cleanup_attr(curthread->attr.arg_attr); - } - /* Check if there is thread specific data: */ - if (curthread->specific_data != NULL) { - /* Run the thread-specific data destructors: */ - _thread_cleanupspecific(); - } - - /* - * Lock the garbage collector mutex to ensure that the garbage - * collector is not using the dead thread list. - */ - if (pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - /* Add this thread to the list of dead threads. */ - TAILQ_INSERT_HEAD(&_dead_list, curthread, dle); - - /* - * Signal the garbage collector thread that there is something - * to clean up. - */ - if (pthread_cond_signal(&_gc_cond) != 0) - PANIC("Cannot signal gc cond"); - - /* - * Avoid a race condition where a scheduling signal can occur - * causing the garbage collector thread to run. If this happens, - * the current thread can be cleaned out from under us. - */ - _thread_kern_sig_defer(); - - /* Unlock the garbage collector mutex: */ - if (pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - - /* Check if there is a thread joining this one: */ - if (curthread->joiner != NULL) { - pthread = curthread->joiner; - curthread->joiner = NULL; - - switch (pthread->suspended) { - case SUSP_JOIN: - /* - * The joining thread is suspended. Change the - * suspension state to make the thread runnable when it - * is resumed: - */ - pthread->suspended = SUSP_NO; - break; - case SUSP_NO: - /* Make the joining thread runnable: */ - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - break; - default: - PANIC("Unreachable code reached"); - } - - /* Set the return value for the joining thread: */ - pthread->join_status.ret = curthread->ret; - pthread->join_status.error = 0; - pthread->join_status.thread = NULL; - - /* Make this thread collectable by the garbage collector. */ - PTHREAD_ASSERT(((curthread->attr.flags & PTHREAD_DETACHED) == - 0), "Cannot join a detached thread"); - curthread->attr.flags |= PTHREAD_DETACHED; - } - - /* Remove this thread from the thread list: */ - TAILQ_REMOVE(&_thread_list, curthread, tle); - - /* This thread will never be re-scheduled. */ - _thread_kern_sched_state(PS_DEAD, __FILE__, __LINE__); - - /* This point should not be reached. */ - PANIC("Dead thread has resumed"); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fchflags.c b/lib/libpthread/uthread/uthread_fchflags.c deleted file mode 100644 index da333f4b14f..00000000000 --- a/lib/libpthread/uthread/uthread_fchflags.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * David Leonard <d@openbsd.org>, 1999. Public Domain. - * - * $OpenBSD: uthread_fchflags.c,v 1.1 1999/01/08 05:42:18 d Exp $ - */ - -#include <sys/stat.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fchflags(int fd, unsigned int flags) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - ret = _thread_sys_fchflags(fd, flags); - _FD_UNLOCK(fd, FD_WRITE); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fchmod.c b/lib/libpthread/uthread/uthread_fchmod.c deleted file mode 100644 index 652f45c0fd7..00000000000 --- a/lib/libpthread/uthread/uthread_fchmod.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_fchmod.c,v 1.3 1999/11/25 07:01:34 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fchmod.c,v 1.5 1999/08/28 00:03:30 peter Exp $ - */ -#include <sys/types.h> -#include <sys/stat.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fchmod(int fd, mode_t mode) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - ret = _thread_sys_fchmod(fd, mode); - _FD_UNLOCK(fd, FD_WRITE); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fchown.c b/lib/libpthread/uthread/uthread_fchown.c deleted file mode 100644 index ed136ad7ac5..00000000000 --- a/lib/libpthread/uthread/uthread_fchown.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: uthread_fchown.c,v 1.3 1999/11/25 07:01:34 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fchown.c,v 1.5 1999/08/28 00:03:31 peter Exp $ - */ -#include <sys/types.h> -#include <unistd.h> -#include <dirent.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fchown(int fd, uid_t owner, gid_t group) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - ret = _thread_sys_fchown(fd, owner, group); - _FD_UNLOCK(fd, FD_WRITE); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fcntl.c b/lib/libpthread/uthread/uthread_fcntl.c deleted file mode 100644 index 6fa1a239cc6..00000000000 --- a/lib/libpthread/uthread/uthread_fcntl.c +++ /dev/null @@ -1,159 +0,0 @@ -/* $OpenBSD: uthread_fcntl.c,v 1.11 2011/07/19 22:37:36 matthew Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fcntl.c,v 1.8 1999/08/28 00:03:31 peter Exp $ - */ -#include <stdarg.h> -#include <unistd.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fcntl(int fd, int cmd,...) -{ - int flags = 0; - int nonblock; - int notsock; - int oldfd; - int ret; - va_list ap; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Lock the file descriptor: */ - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - /* Initialise the variable argument list: */ - va_start(ap, cmd); - - /* Process according to file control command type: */ - switch (cmd) { - /* Duplicate a file descriptor: */ - case F_DUPFD: - case F_DUPFD_CLOEXEC: - /* - * Get the file descriptor that the caller wants to - * use: - */ - oldfd = va_arg(ap, int); - - /* Initialise the file descriptor table entry: */ - if ((ret = _thread_sys_fcntl(fd, cmd, oldfd)) < 0) { - } - /* Initialise the file descriptor table entry: */ - else if (_thread_fd_table_init(ret, FD_INIT_DUP, - _thread_fd_table[fd]->status_flags) == -1) { - /* Quietly close the file: */ - _thread_sys_close(ret); - - /* Reset the file descriptor: */ - ret = -1; - } - break; - case F_SETFD: - flags = va_arg(ap, int); - ret = _thread_sys_fcntl(fd, cmd, flags); - break; - case F_GETFD: - ret = _thread_sys_fcntl(fd, cmd, 0); - break; - case F_GETFL: - ret = _thread_fd_table[fd]->status_flags->flags & - ~_FD_NOTSOCK; - break; - case F_SETFL: - /* - * Get the file descriptor flags passed by the - * caller: - */ - flags = va_arg(ap, int); - - /* - * Check if the user wants a non-blocking file - * descriptor: - */ - nonblock = flags & O_NONBLOCK; - - /* Remember the non-socket flag: */ - notsock = _thread_fd_table[fd]->status_flags->flags & - _FD_NOTSOCK; - - /* Set the file descriptor flags: */ - if ((ret = _thread_sys_fcntl(fd, cmd, - flags | O_NONBLOCK)) != 0) { - - /* Get the flags so that we behave like the kernel: */ - } else if ((flags = _thread_sys_fcntl(fd, - F_GETFL, 0)) == -1) { - /* Error getting flags: */ - ret = -1; - - /* - * Check if the file descriptor is non-blocking - * with respect to the user: - */ - } else if (nonblock) - /* A non-blocking descriptor: */ - _thread_fd_table[fd]->status_flags->flags = - flags | O_NONBLOCK; - else - /* Save the flags: */ - _thread_fd_table[fd]->status_flags->flags = - flags & ~O_NONBLOCK; - - /* Restore if previously set: */ - if (ret != -1 && notsock) - _thread_fd_table[fd]->status_flags->flags |= - _FD_NOTSOCK; - break; - default: - /* Might want to make va_arg use a union */ - ret = _thread_sys_fcntl(fd, cmd, va_arg(ap, void *)); - break; - } - - /* Free variable arguments: */ - va_end(ap); - - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_RDWR); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c deleted file mode 100644 index 9816616a900..00000000000 --- a/lib/libpthread/uthread/uthread_fd.c +++ /dev/null @@ -1,870 +0,0 @@ -/* $OpenBSD: uthread_fd.c,v 1.33 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fd.c,v 1.13 1999/08/28 00:03:31 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* Static variables: */ - -static struct fd_table_entry *_thread_fd_entries; -static struct fs_flags *_thread_fd_flags; - -static SLIST_HEAD(, fd_table_entry) _thread_fd_entries_head; -static SLIST_HEAD(, fs_flags) _thread_fd_flags_head; - -int -_thread_fd_init_mem(void) -{ - int fd; - - _thread_fd_entries = calloc((size_t)_thread_max_fdtsize, - sizeof(struct fd_table_entry)); - if (_thread_fd_entries == NULL) - return (-1); - - _thread_fd_flags = calloc((size_t)_thread_max_fdtsize, - sizeof(struct fs_flags)); - if (_thread_fd_flags == NULL) { - free(_thread_fd_entries); - _thread_fd_entries = NULL; - return (-1); - } - - /* add pre-allocated entries to freelists */ - for (fd = 0; fd < _thread_max_fdtsize; fd++) - { - SLIST_INSERT_HEAD(&_thread_fd_entries_head, &_thread_fd_entries[fd], fe); - SLIST_INSERT_HEAD(&_thread_fd_flags_head, &_thread_fd_flags[fd], fe); - } - - return (0); -} - -/* - * Build a new fd entry and return it. - */ -static struct fs_flags * -_thread_fs_flags_entry(void) -{ - struct fs_flags *entry; - - _thread_kern_sig_defer(); - entry = SLIST_FIRST(&_thread_fd_flags_head); - if (entry != NULL) { - SLIST_REMOVE_HEAD(&_thread_fd_flags_head, fe); - memset(entry, 0, sizeof *entry); - } - _thread_kern_sig_undefer(); - return entry; -} - -static void -_thread_fs_flags_free(struct fs_flags *entry) -{ - _thread_kern_sig_defer(); - SLIST_INSERT_HEAD(&_thread_fd_flags_head, entry, fe); - _thread_kern_sig_undefer(); -} - -/* - * Initialize a new status_flags entry and set system - * file descriptor non-blocking. - */ -static int -_thread_fs_flags_init(struct fs_flags *status_flags, int fd) -{ - int ret = 0; - int saved_errno; - - status_flags->flags = _thread_sys_fcntl(fd, F_GETFL, 0); - if (status_flags->flags == -1) - /* use the errno fcntl returned */ - ret = -1; - else { - /* - * Make the file descriptor non-blocking. - * This might fail if the device driver does - * not support non-blocking calls, or if the - * driver is naturally non-blocking. - */ - if ((status_flags->flags & O_NONBLOCK) == 0) { - saved_errno = errno; - _thread_sys_fcntl(fd, F_SETFL, - status_flags->flags | O_NONBLOCK); - errno = saved_errno; - } - } - - return (ret); -} - -/* - * If existing entry's status_flags don't match new one, - * then replace the current status flags with the new one. - * It is assumed the entry is locked with a FD_RDWR_CLOSE - * lock when this function is called. - */ -void -_thread_fs_flags_replace(int fd, struct fs_flags *new_status_flags) -{ - struct fd_table_entry *entry = _thread_fd_table[fd]; - struct fs_flags *old_status_flags; - struct stat sb; - int flags; - int saved_errno; - - _thread_kern_sig_defer(); - if (entry->status_flags != new_status_flags) { - if (entry->status_flags != NULL) { - old_status_flags = entry->status_flags; - old_status_flags->refcnt -= 1; - if (old_status_flags->refcnt <= 0) { - /* - * Check if the file should be left as blocking. - * - * This is so that the file descriptors shared with a parent - * process aren't left set to non-blocking if the child - * closes them prior to exit. An example where this causes - * problems with /bin/sh is when a child closes stdin. - * - * Setting a file as blocking causes problems if a threaded - * parent accesses the file descriptor before the child exits. - * Once the threaded parent receives a SIGCHLD then it resets - * all of its files to non-blocking, and so it is then safe - * to access them. - * - * Pipes are not set to blocking when they are closed, as - * the parent and child will normally close the file - * descriptor of the end of the pipe that they are not - * using, which would then cause any reads to block - * indefinitely. However, stdin/out/err will be reset - * to avoid leaving them as non-blocking indefinitely. - * - * Files that we cannot fstat are probably not regular - * so we don't bother with them. - * - * Also don't reset fd to blocking if we are replacing - * the status flags with a shared version. - */ - saved_errno = errno; - if (new_status_flags == NULL && - (old_status_flags->flags & O_NONBLOCK) == 0 && - (fd < 3 || (_thread_sys_fstat(fd, &sb) == 0 && - (S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode))))) - { - /* Get the current flags: */ - flags = _thread_sys_fcntl(fd, F_GETFL, NULL); - /* Clear the nonblocking file descriptor flag: */ - _thread_sys_fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); - } - _thread_fs_flags_free(old_status_flags); - errno = saved_errno; - } - } - /* replace with new status flags */ - if (new_status_flags != NULL) { - new_status_flags->refcnt += 1; - } - entry->status_flags = new_status_flags; - } - _thread_kern_sig_undefer(); -} - -/* - * Build a new fd entry and return it. - */ -static struct fd_table_entry * -_thread_fd_entry(void) -{ - struct fd_table_entry *entry; - - _thread_kern_sig_defer(); - entry = SLIST_FIRST(&_thread_fd_entries_head); - if (entry != NULL) { - SLIST_REMOVE_HEAD(&_thread_fd_entries_head, fe); - memset(entry, 0, sizeof *entry); - TAILQ_INIT(&entry->r_queue); - TAILQ_INIT(&entry->w_queue); - entry->state = FD_ENTRY_CLOSED; - entry->init_mode = FD_INIT_UNKNOWN; - } - _thread_kern_sig_undefer(); - return entry; -} - -static void -_thread_fs_entry_free(struct fd_table_entry *entry) -{ - _thread_kern_sig_defer(); - SLIST_INSERT_HEAD(&_thread_fd_entries_head, entry, fe); - _thread_kern_sig_undefer(); -} - -/* - * Initialize the thread fd table for dup-ed fds, typically the stdio - * fds. - */ - -void -_thread_fd_init(void) -{ - int saved_errno; - int fd; - int fd2; - int flag; - int *flags; - struct fd_table_entry *entry1, *entry2; - struct fs_flags *status_flags; - - _thread_fd_init_mem(); - - saved_errno = errno; - flags = calloc((size_t)_thread_init_fdtsize, sizeof *flags); - if (flags == NULL) - PANIC("Cannot allocate memory for flags table"); - - /* read the current file flags */ - for (fd = 0; fd < _thread_init_fdtsize; fd += 1) - flags[fd] = _thread_sys_fcntl(fd, F_GETFL, 0); - - /* - * Now toggle the sync flags and see what other fd's - * change. Those are the dup-ed fd's. Dup-ed fd's are - * added to the table, all others are NOT added to the - * table. They MUST NOT be added as the fds may belong - * to dlopen. As dlclose doesn't go through the thread code - * so the entries would never be cleaned. - */ - - _thread_kern_sig_defer(); - for (fd = 0; fd < _thread_init_fdtsize; fd += 1) { - if (flags[fd] == -1) - continue; - entry1 = _thread_fd_entry(); - status_flags = _thread_fs_flags_entry(); - if (entry1 != NULL && status_flags != NULL) { - _thread_sys_fcntl(fd, F_SETFL, - flags[fd] ^ O_SYNC); - for (fd2 = fd + 1; fd2 < _thread_init_fdtsize; fd2 += 1) { - if (flags[fd2] == -1) - continue; - flag = _thread_sys_fcntl(fd2, F_GETFL, 0); - if (flag != flags[fd2]) { - entry2 = _thread_fd_entry(); - if (entry2 != NULL) { - status_flags->refcnt += 1; - entry2->status_flags = status_flags; - entry2->state = FD_ENTRY_OPEN; - entry2->init_mode = FD_INIT_DUP2; - _thread_fd_table[fd2] = entry2; - } else - PANIC("Cannot allocate memory for flags table"); - flags[fd2] = -1; - } - } - if (status_flags->refcnt) { - status_flags->refcnt += 1; - status_flags->flags = flags[fd]; - entry1->status_flags = status_flags; - entry1->state = FD_ENTRY_OPEN; - entry1->init_mode = FD_INIT_DUP2; - _thread_fd_table[fd] = entry1; - flags[fd] |= O_NONBLOCK; - } else { - _thread_fs_entry_free(entry1); - _thread_fs_flags_free(status_flags); - } - } else { - PANIC("Cannot allocate memory for flags table"); - } - } - _thread_kern_sig_undefer(); - - /* lastly, restore the file flags. Flags for files that we - know to be duped have been modified so set the non-blocking' - flag. Other files will be set to non-blocking when the - thread code is forced to take notice of the file. */ - for (fd = 0; fd < _thread_init_fdtsize; fd += 1) - if (flags[fd] != -1) - _thread_sys_fcntl(fd, F_SETFL, flags[fd]); - - free(flags); - errno = saved_errno; -} - -/* - * Initialize the fd_table entry for the given fd. - * - * This function *must* return -1 and set the thread specific errno - * as a system call. This is because the error return from this - * function is propagated directly back from thread-wrapped system - * calls. - */ -int -_thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *status_flags) -{ - int ret = 0; - int saved_errno; - struct fd_table_entry *entry; - struct fs_flags *new_status_flags; - - if (fd < 0 || fd >= _thread_max_fdtsize) { - /* - * file descriptor is out of range, Return a bad file - * descriptor error: - */ - errno = EBADF; - return (-1); - } - - if (_thread_fd_table[fd] == NULL) { - /* First time for this fd, build an entry */ - entry = _thread_fd_entry(); - if (entry == NULL) { - /* use _thread_fd_entry errno */ - ret = -1; - } else { - /* Protect the file descriptor table: */ - _thread_kern_sig_defer(); - - /* - * Check if another thread allocated the - * file descriptor entry while this thread - * was doing the same thing. The table wasn't - * kept locked during this operation because - * it has the potential to recurse. - */ - if (_thread_fd_table[fd] == NULL) { - /* This thread wins: */ - _thread_fd_table[fd] = entry; - entry = NULL; - } - - /* Unprotect the file descriptor table: */ - _thread_kern_sig_undefer(); - - /* - * If another thread initialized the table entry - * throw the new entry away. - */ - if (entry != NULL) - _thread_fs_entry_free(entry); - } - } - - if (ret == 0) { - entry = _thread_fd_table[fd]; - _thread_kern_sig_defer(); - switch (init_mode) { - case FD_INIT_UNKNOWN: - /* - * If the entry is closed, try to open it - * anyway since we may have inherited it or - * it may have been created by an unwrapped - * call such as openpty(3). Since we allow - * FD_RDWR_CLOSE locks on closed entries, - * we ignore EBADF status flags errors and - * return a closed entry. If the entry is - * not closed then there's nothing to do. - */ - if (entry->state == FD_ENTRY_CLOSED) { - new_status_flags = _thread_fs_flags_entry(); - if (new_status_flags == NULL) { - /* use _thread_fs_flags_entry errno */ - ret = -1; - } else { - saved_errno = errno; - ret = _thread_fs_flags_init(new_status_flags, fd); - if (ret == 0) { - errno = saved_errno; - new_status_flags->refcnt = 1; - entry->status_flags = new_status_flags; - new_status_flags = NULL; - entry->state = FD_ENTRY_OPEN; - entry->init_mode = init_mode; - } else if (errno == EBADF) { - errno = saved_errno; - ret = 0; - } - } - /* if flags init failed free new flags */ - if (new_status_flags != NULL) - _thread_fs_flags_free(new_status_flags); - } - break; - case FD_INIT_NEW: - /* - * If the entry was initialized and opened - * by another thread (i.e. FD_INIT_DUP2 or - * FD_INIT_UNKNOWN), the status flags will - * be correct. - */ - if (entry->state == FD_ENTRY_CLOSED) { - new_status_flags = _thread_fs_flags_entry(); - if (new_status_flags == NULL) { - /* use _thread_fs_flags_entry errno */ - ret = -1; - } else { - ret = _thread_fs_flags_init(new_status_flags, fd); - } - if (ret == 0) { - new_status_flags->refcnt = 1; - entry->status_flags = new_status_flags; - new_status_flags = NULL; - entry->state = FD_ENTRY_OPEN; - entry->init_mode = init_mode; - } - /* if flags init failed free new flags */ - if (new_status_flags != NULL) - _thread_fs_flags_free(new_status_flags); - } - break; - case FD_INIT_BLOCKING: - /* - * If the entry was initialized and opened - * by another thread with FD_INIT_DUP2, the - * status flags will be correct. However, - * if FD_INIT_UNKNOWN raced in before us - * it means the app is not well behaved and - * tried to use the fd before it was returned - * to the client. - */ - if (entry->state == FD_ENTRY_CLOSED) { - new_status_flags = _thread_fs_flags_entry(); - if (new_status_flags == NULL) { - /* use _thread_fs_flags_entry errno */ - ret = -1; - } else { - ret = _thread_fs_flags_init(new_status_flags, fd); - } - if (ret == 0) { - /* set user's view of status flags to blocking */ - new_status_flags->flags &= ~O_NONBLOCK; - new_status_flags->refcnt = 1; - entry->status_flags = new_status_flags; - new_status_flags = NULL; - entry->state = FD_ENTRY_OPEN; - entry->init_mode = init_mode; - } - /* if flags init failed free new flags */ - if (new_status_flags != NULL) - _thread_fs_flags_free(new_status_flags); - } else if (entry->state == FD_ENTRY_OPEN && - entry->init_mode == FD_INIT_UNKNOWN) { - entry->status_flags->flags &= ~O_NONBLOCK; - } - break; - case FD_INIT_DUP: - /* - * If the entry was initialized and opened - * by another thread with FD_INIT_DUP2 then - * keep it. However, if FD_INIT_UNKNOWN raced - * in before us it means the app is not well - * behaved and tried to use the fd before it - * was returned to the client. - */ - if (entry->state == FD_ENTRY_CLOSED) { - _thread_fs_flags_replace(fd, status_flags); - entry->state = FD_ENTRY_OPEN; - entry->init_mode = init_mode; - } else if (entry->state == FD_ENTRY_OPEN && - entry->init_mode == FD_INIT_UNKNOWN) { - _thread_fs_flags_replace(fd, status_flags); - } - break; - case FD_INIT_DUP2: - /* - * This is only called when FD_RDWR_CLOSE - * is held and in state FD_ENTRY_CLOSING. - * Just replace flags and open entry. - * FD_INIT_UNKNOWN can't race in since we - * are in state FD_ENTRY_CLOSING before - * the _thread_sys_dup2 happens. - */ - _thread_fs_flags_replace(fd, status_flags); - entry->state = FD_ENTRY_OPEN; - entry->init_mode = init_mode; - break; - } - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (ret); -} - -/* - * Close an fd entry. Replace existing status flags - * with NULL. The entry is assummed to be locked with - * a FD_RDWR_CLOSE lock and in state FD_ENTRY_CLOSING. - */ -void -_thread_fd_entry_close(int fd) -{ - _thread_fs_flags_replace(fd, NULL); - _thread_fd_table[fd]->state = FD_ENTRY_CLOSED; -} - -/* - * Unlock an fd table entry for the given fd and lock type. - */ -void -_thread_fd_unlock(int fd, int lock_type) -{ - struct pthread *thread = _get_curthread(); - struct fd_table_entry *entry; - - /* - * If file descriptor is out of range or uninitialized, - * do nothing. - */ - if (fd >= 0 && fd < _thread_max_fdtsize && _thread_fd_table[fd] != NULL) { - entry = _thread_fd_table[fd]; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Check if the running thread owns the read lock: */ - if (entry->r_owner == thread && - (lock_type & FD_READ)) { - /* - * Decrement the read lock count for the - * running thread: - */ - entry->r_lockcount--; - if (entry->r_lockcount == 0) { - /* - * no read locks, dequeue any threads - * waiting for a read lock - */ - entry->r_owner = TAILQ_FIRST(&entry->r_queue); - if (entry->r_owner != NULL) { - TAILQ_REMOVE(&entry->r_queue, - entry->r_owner, qe); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(entry->r_owner, - PS_RUNNING); - - /* - * Reset the number of read locks. - * This will be incremented by the new - * owner of the lock when it sees that - *it has the lock. - */ - entry->r_lockcount = 0; - } - } - - } - /* Check if the running thread owns the write lock: */ - if (entry->w_owner == thread && - (lock_type & FD_WRITE)) { - /* - * Decrement the write lock count for the - * running thread: - */ - entry->w_lockcount--; - if (entry->w_lockcount == 0) { - /* - * no write locks, dequeue any threads - * waiting on a write lock. - */ - entry->w_owner = TAILQ_FIRST(&entry->w_queue); - if (entry->w_owner != NULL) { - /* Remove this thread from the queue: */ - TAILQ_REMOVE(&entry->w_queue, - entry->w_owner, qe); - - /* - * Set the state of the new owner of - * the thread to running: - */ - PTHREAD_NEW_STATE(entry->w_owner, - PS_RUNNING); - - /* - * Reset the number of write locks. - * This will be incremented by the - * new owner of the lock when it - * sees that it has the lock. - */ - entry->w_lockcount = 0; - } - } - } - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } -} - -/* - * Lock an fd table entry for the given fd and lock type. - */ -int -_thread_fd_lock(int fd, int lock_type, struct timespec * timeout) -{ - struct pthread *curthread = _get_curthread(); - struct fd_table_entry *entry; - int ret; - - /* - * Check that the file descriptor table is initialised for this - * entry: - */ - ret = _thread_fd_table_init(fd, FD_INIT_UNKNOWN, NULL); - if (ret == 0) { - entry = _thread_fd_table[fd]; - - /* - * Protect the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _thread_kern_sig_defer(); - - /* reject all new locks on entries that are closing */ - if (entry->state == FD_ENTRY_CLOSING) { - ret = -1; - errno = EBADF; - } else if (lock_type == FD_RDWR_CLOSE) { - /* allow closing locks on open and closed entries */ - entry->state = FD_ENTRY_CLOSING; - } else if (entry->state == FD_ENTRY_CLOSED) { - ret = -1; - errno = EBADF; - } - - /* Handle read locks */ - if (ret == 0 && (lock_type & FD_READ)) { - /* - * Enter a loop to wait for the file descriptor to be - * locked for read for the current thread: - */ - while (entry->r_owner != curthread) { - /* - * Check if the file descriptor is locked by - * another thread: - */ - if (entry->r_owner != NULL) { - /* - * Another thread has locked the file - * descriptor for read, so join the - * queue of threads waiting for a - * read lock on this file descriptor: - */ - TAILQ_INSERT_TAIL(&entry->r_queue, - curthread, qe); - - /* - * Save the file descriptor details - * in the thread structure for the - * running thread: - */ - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(timeout); - - /* - * Unprotect the file descriptor - * table entry: - */ - _thread_kern_sig_undefer(); - - /* - * Schedule this thread to wait on - * the read lock. It will only be - * woken when it becomes the next in - * the queue and is granted access - * to the lock by the thread that is - * unlocking the file descriptor. - */ - _thread_kern_sched_state(PS_FDLR_WAIT, - __FILE__, - __LINE__); - - /* - * Protect the file descriptor - * table entry again: - */ - _thread_kern_sig_defer(); - - } else { - /* - * The running thread now owns the - * read lock on this file descriptor: - */ - entry->r_owner = curthread; - - /* - * Reset the number of read locks for - * this file descriptor: - */ - entry->r_lockcount = 0; - } - } - - /* Increment the read lock count: */ - entry->r_lockcount++; - } - - /* Handle write locks */ - if (ret == 0 && (lock_type & FD_WRITE)) { - /* - * Enter a loop to wait for the file descriptor to be - * locked for write for the current thread: - */ - while (entry->w_owner != curthread) { - /* - * Check if the file descriptor is locked by - * another thread: - */ - if (entry->w_owner != NULL) { - /* - * Another thread has locked the file - * descriptor for write, so join the - * queue of threads waiting for a - * write lock on this file - * descriptor: - */ - TAILQ_INSERT_TAIL(&entry->w_queue, - curthread, qe); - - /* - * Save the file descriptor details - * in the thread structure for the - * running thread: - */ - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(timeout); - - /* - * Unprotect the file descriptor - * table entry: - */ - _thread_kern_sig_undefer(); - - /* - * Schedule this thread to wait on - * the write lock. It will only be - * woken when it becomes the next in - * the queue and is granted access to - * the lock by the thread that is - * unlocking the file descriptor. - */ - _thread_kern_sched_state(PS_FDLW_WAIT, - __FILE__, - __LINE__); - - /* - * Unprotect the file descriptor - * table entry again: - */ - _thread_kern_sig_defer(); - } else { - /* - * The running thread now owns the - * write lock on this file descriptor: - */ - entry->w_owner = curthread; - - /* - * Reset the number of write locks - * for this file descriptor: - */ - entry->w_lockcount = 0; - } - } - - /* Increment the write lock count: */ - entry->w_lockcount++; - } - - /* Unprotect the file descriptor table entry: */ - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (ret); -} - -struct timespec * -_thread_fd_timeout(int fd, int which) -{ - struct timeval tv; - socklen_t len; - int saved_errno; - - /* Avoid calling getsockopt if fd is not a socket. */ - if (!(_thread_fd_table[fd]->status_flags->flags & _FD_NOTSOCK)) { - len = sizeof(tv); - saved_errno = errno; - if (_thread_sys_getsockopt(fd, SOL_SOCKET, which ? - SO_SNDTIMEO : SO_RCVTIMEO, &tv, &len) == 0) { - if (timerisset(&tv)) { - static struct timespec ts; - TIMEVAL_TO_TIMESPEC(&tv, &ts); - return (&ts); - } - } else if (errno == ENOTSOCK) - _thread_fd_table[fd]->status_flags->flags |= - _FD_NOTSOCK; - errno = saved_errno; - } - return (NULL); -} - -#endif diff --git a/lib/libpthread/uthread/uthread_file.c b/lib/libpthread/uthread/uthread_file.c deleted file mode 100644 index 25c2d0945cc..00000000000 --- a/lib/libpthread/uthread/uthread_file.c +++ /dev/null @@ -1,353 +0,0 @@ -/* $OpenBSD: uthread_file.c,v 1.17 2009/11/09 00:18:27 kurt Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_file.c,v 1.9 1999/08/28 00:03:32 peter Exp $ - * - * POSIX stdio FILE locking functions. These assume that the locking - * is only required at FILE structure level, not at file descriptor - * level too. - * - */ -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/queue.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * The FILE lock structure. The FILE *fp is locked if the owner is - * not NULL. If not locked, the file lock structure can be - * reassigned to a different file by setting fp. - */ -struct file_lock { - LIST_ENTRY(file_lock) entry; /* Entry if file list. */ - V_TAILQ_HEAD(lock_head, pthread) - l_head; /* Head of queue for threads */ - /* waiting on this lock. */ - FILE *fp; /* The target file. */ - pthread_t owner; /* Thread that owns lock. */ - int count; /* Lock count for owner. */ -}; - -/* - * The number of file lock lists into which the file pointer is - * hashed. Ideally, the FILE structure size would have been increased, - * but this causes incompatibility, so separate data structures are - * required. - */ -#define NUM_HEADS 128 - -/* - * This macro casts a file pointer to a long integer and right - * shifts this by the number of bytes in a pointer. The shifted - * value is then remaindered using the maximum number of hash - * entries to produce and index into the array of static lock - * structures. If there is a collision, a linear search of the - * dynamic list of locks linked to each static lock is perfomed. - */ -#define file_idx(_p) ((int)((((uintptr_t) _p) >> sizeof(void *)) % NUM_HEADS)) - -/* - * Global array of file locks. The first lock for each hash bucket is - * allocated statically in the hope that there won't be too many - * collisions that require a malloc and an element added to the list. - */ -struct static_file_lock { - LIST_HEAD(file_list_head, file_lock) head; - struct file_lock fl; -} flh[NUM_HEADS]; - -/* Set to non-zero when initialisation is complete: */ -static int init_done = 0; - -/* Lock for accesses to the hash table: */ -static spinlock_t hash_lock = _SPINLOCK_INITIALIZER; - -/* - * Find a lock structure for a FILE, return NULL if the file is - * not locked: - */ -static -struct file_lock * -find_lock(int idx, FILE *fp) -{ - struct file_lock *p; - - /* Check if the file is locked using the static structure: */ - if (flh[idx].fl.fp == fp && flh[idx].fl.owner != NULL) - /* Return a pointer to the static lock: */ - p = &flh[idx].fl; - else { - /* Point to the first dynamic lock: */ - p = LIST_FIRST(&flh[idx].head); - - /* - * Loop through the dynamic locks looking for the - * target file: - */ - while (p != NULL && (p->fp != fp || p->owner == NULL)) - /* Not this file, try the next: */ - p = LIST_NEXT(p, entry); - } - return(p); -} - -/* - * Lock a file, assuming that there is no lock structure currently - * assigned to it. - */ -static -struct file_lock * -do_lock(int idx, FILE *fp) -{ - struct file_lock *p; - - /* Check if the static structure is not being used: */ - if (flh[idx].fl.owner == NULL) { - /* Return a pointer to the static lock: */ - p = &flh[idx].fl; - } - else { - /* Point to the first dynamic lock: */ - p = LIST_FIRST(&flh[idx].head); - - /* - * Loop through the dynamic locks looking for a - * lock structure that is not being used: - */ - while (p != NULL && p->owner != NULL) - /* This one is used, try the next: */ - p = LIST_NEXT(p, entry); - } - - /* - * If an existing lock structure has not been found, - * allocate memory for a new one: - */ - if (p == NULL && (p = (struct file_lock *) - malloc(sizeof(struct file_lock))) != NULL) { - /* Add the new element to the list: */ - LIST_INSERT_HEAD(&flh[idx].head, p, entry); - } - - /* Check if there is a lock structure to acquire: */ - if (p != NULL) { - /* Acquire the lock for the running thread: */ - p->fp = fp; - p->owner = _thread_run; - p->count = 1; - TAILQ_INIT(&p->l_head); - } - return(p); -} - - -void -flockfile(FILE * fp) -{ - int idx = file_idx(fp); - struct file_lock *p; - - /* Lock the hash table: */ - _SPINLOCK(&hash_lock); - - /* Check if the static array has not been initialised: */ - if (!init_done) { - /* Initialise the global array: */ - memset(flh,0,sizeof(flh)); - - /* Flag the initialisation as complete: */ - init_done = 1; - } - - /* Get a pointer to any existing lock for the file: */ - if ((p = find_lock(idx, fp)) == NULL) { - /* - * The file is not locked, so this thread can - * grab the lock: - */ - p = do_lock(idx, fp); - - /* Unlock the hash table: */ - _SPINUNLOCK(&hash_lock); - - /* - * The file is already locked, so check if the - * running thread is the owner: - */ - } else if (p->owner == _thread_run) { - /* - * The running thread is already the - * owner, so increment the count of - * the number of times it has locked - * the file: - */ - p->count++; - - /* Unlock the hash table: */ - _SPINUNLOCK(&hash_lock); - } else { - /* - * The file is locked for another thread. - * Append this thread to the queue of - * threads waiting on the lock. - */ - TAILQ_INSERT_TAIL(&p->l_head,_thread_run,qe); - - /* Unlock the hash table: */ - _SPINUNLOCK(&hash_lock); - - /* Wait on the FILE lock: */ - _thread_kern_sched_state(PS_FILE_WAIT, "", 0); - } -} - -int -ftrylockfile(FILE * fp) -{ - int ret = -1; - int idx = file_idx(fp); - struct file_lock *p; - - /* Lock the hash table: */ - _SPINLOCK(&hash_lock); - - /* Get a pointer to any existing lock for the file: */ - if ((p = find_lock(idx, fp)) == NULL) { - /* - * The file is not locked, so this thread can - * grab the lock: - */ - p = do_lock(idx, fp); - - /* - * The file is already locked, so check if the - * running thread is the owner: - */ - } else if (p->owner == _thread_run) { - /* - * The running thread is already the - * owner, so increment the count of - * the number of times it has locked - * the file: - */ - p->count++; - } else { - /* - * The file is locked for another thread, - * so this try fails. - */ - p = NULL; - } - - /* Check if the lock was obtained: */ - if (p != NULL) - /* Return success: */ - ret = 0; - - /* Unlock the hash table: */ - _SPINUNLOCK(&hash_lock); - - return (ret); -} - -void -funlockfile(FILE * fp) -{ - int idx = file_idx(fp); - struct file_lock *p; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the hash table: */ - _SPINLOCK(&hash_lock); - - /* - * Get a pointer to the lock for the file and check that - * the running thread is the one with the lock: - */ - if ((p = find_lock(idx, fp)) != NULL && - p->owner == _thread_run) { - /* - * Check if this thread has locked the FILE - * more than once: - */ - if (p->count > 1) - /* - * Decrement the count of the number of - * times the running thread has locked this - * file: - */ - p->count--; - else { - /* - * The running thread will release the - * lock now: - */ - p->count = 0; - - /* Get the new owner of the lock: */ - if ((p->owner = TAILQ_FIRST(&p->l_head)) != NULL) { - /* Pop the thread off the queue: */ - TAILQ_REMOVE(&p->l_head,p->owner,qe); - - /* - * This is the first lock for the new - * owner: - */ - p->count = 1; - - /* Allow the new owner to run: */ - PTHREAD_NEW_STATE(p->owner,PS_RUNNING); - } - } - } - - /* Unlock the hash table: */ - _SPINUNLOCK(&hash_lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); -} - -#endif diff --git a/lib/libpthread/uthread/uthread_find_thread.c b/lib/libpthread/uthread/uthread_find_thread.c deleted file mode 100644 index c531643e325..00000000000 --- a/lib/libpthread/uthread/uthread_find_thread.c +++ /dev/null @@ -1,69 +0,0 @@ -/* $OpenBSD: uthread_find_thread.c,v 1.5 2001/12/11 00:19:47 fgsch Exp $ */ -/* - * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_find_thread.c,v 1.5 1999/08/28 00:03:32 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* Find a thread in the linked list of active threads: */ -int -_find_thread(pthread_t pthread) -{ - pthread_t pthread1; - - /* Check if the caller has specified an invalid thread: */ - if (pthread == NULL || pthread->magic != PTHREAD_MAGIC) - /* Invalid thread: */ - return(EINVAL); - - /* - * Defer signals to protect the thread list from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Search for the specified thread: */ - TAILQ_FOREACH(pthread1, &_thread_list, tle) { - if (pthread == pthread1) - break; - } - - /* Undefer and handle pending signals, yielding if necessary: */ - _thread_kern_sig_undefer(); - - /* Return zero if the thread exists: */ - return ((pthread1 != NULL) ? 0:ESRCH); -} -#endif diff --git a/lib/libpthread/uthread/uthread_flock.c b/lib/libpthread/uthread/uthread_flock.c deleted file mode 100644 index fed679bd80b..00000000000 --- a/lib/libpthread/uthread/uthread_flock.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: uthread_flock.c,v 1.3 1999/11/25 07:01:35 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_flock.c,v 1.5 1999/08/28 00:03:32 peter Exp $ - */ -#include <sys/file.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -flock(int fd, int operation) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = _thread_sys_flock(fd, operation); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fork.c b/lib/libpthread/uthread/uthread_fork.c deleted file mode 100644 index 16e32969e4f..00000000000 --- a/lib/libpthread/uthread/uthread_fork.c +++ /dev/null @@ -1,238 +0,0 @@ -/* $OpenBSD: uthread_fork.c,v 1.22 2010/07/12 03:52:52 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fork.c,v 1.14 1999/09/29 15:18:38 marcel Exp $ - */ -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <stdlib.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -pid_t _dofork(int vfork); - -pid_t -fork(void) -{ - pid_t pid; - struct pthread_atfork *af; - - /* - * Defer signals to protect the scheduling queues from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - pthread_mutex_lock(&_atfork_mutex); - - /* Run down atfork prepare handlers. */ - TAILQ_FOREACH_REVERSE(af, &_atfork_list, atfork_head, qe) { - if (af->prepare != NULL) - af->prepare(); - } - - if ((pid = _dofork(0)) == 0) { - /* Run down atfork child handlers. */ - TAILQ_FOREACH(af, &_atfork_list, qe) { - if (af->child != NULL) - af->child(); - } - _mutex_reinit(&_atfork_mutex); - } else { - /* Run down atfork parent handlers. */ - TAILQ_FOREACH(af, &_atfork_list, qe) { - if (af->parent != NULL) - af->parent(); - } - pthread_mutex_unlock(&_atfork_mutex); - } - - /* - * Undefer and handle pending signals, yielding if necessary: - */ - _thread_kern_sig_undefer(); - - return(pid); -} - -pid_t -_dofork(int vfork) -{ - struct pthread *curthread = _get_curthread(); - int i, flags; - pid_t ret; - pthread_t pthread; - - /* Fork a new process and reset child's state */ - if ((ret = (vfork ? _thread_sys_vfork() : _thread_sys_fork())) == 0) { - /* Close the pthread kernel pipe: */ - _thread_sys_close(_thread_kern_pipe[0]); - _thread_sys_close(_thread_kern_pipe[1]); - - /* Reset signals pending for the running thread: */ - sigemptyset(&curthread->sigpend); - - /* - * Create a pipe that is written to by the signal handler to - * prevent signals being missed in calls to - * _thread_sys_select: - */ - if (_thread_sys_pipe(_thread_kern_pipe) != 0) { - /* Cannot create pipe, so abort: */ - PANIC("Cannot create pthread kernel pipe for forked process"); - } - /* Get the flags for the read pipe: */ - else if ((flags = _thread_sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) { - /* Abort this application: */ - abort(); - } - /* Make the read pipe non-blocking: */ - else if (_thread_sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) { - /* Abort this application: */ - abort(); - } - /* Get the flags for the write pipe: */ - else if ((flags = _thread_sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) { - /* Abort this application: */ - abort(); - } - /* Make the write pipe non-blocking: */ - else if (_thread_sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) { - /* Abort this application: */ - abort(); - } - /* Reinitialize the GC mutex: */ - else if (_mutex_reinit(&_gc_mutex) != 0) { - /* Abort this application: */ - PANIC("Cannot initialize GC mutex for forked process"); - } - /* Reinitialize the GC condition variable: */ - else if (_cond_reinit(&_gc_cond) != 0) { - /* Abort this application: */ - PANIC("Cannot initialize GC condvar for forked process"); - } - /* Initialize the ready queue: */ - else if (_pq_init(&_readyq) != 0) { - /* Abort this application: */ - PANIC("Cannot initialize priority ready queue."); - } else { - /* - * Enter a loop to remove all threads other than - * the running thread from the thread list: - */ - while ((pthread = TAILQ_FIRST(&_thread_list)) != NULL) { - TAILQ_REMOVE(&_thread_list, pthread, tle); - - /* Make sure this isn't the running thread: */ - if (pthread != curthread) { - /* XXX should let gc do all this. */ - if(pthread->stack != NULL) - _thread_stack_free(pthread->stack); - - if (pthread->specific_data != NULL) - free(pthread->specific_data); - - if (pthread->poll_data.fds != NULL) - free(pthread->poll_data.fds); - - free(pthread); - } - } - - /* Restore the running thread */ - TAILQ_INSERT_HEAD(&_thread_list, curthread, tle); - - /* Re-init the dead thread list: */ - TAILQ_INIT(&_dead_list); - - /* Re-init the waiting and work queues. */ - TAILQ_INIT(&_waitingq); - TAILQ_INIT(&_workq); - - /* Re-init the threads mutex queue: */ - TAILQ_INIT(&curthread->mutexq); - - /* no one is joining the remaining thread */ - curthread->joiner = NULL; - - /* single threaded now */ - __isthreaded = 0; - - /* No spinlocks yet: */ - _spinblock_count = 0; - - /* Don't queue signals yet: */ - _queue_signals = 0; - - /* Initialize signal handling: */ - _thread_sig_init(); - - /* Initialize the scheduling switch hook routine: */ - _sched_switch_hook = NULL; - - /* Clear out any locks in the file descriptor table: */ - for (i = 0; i < _thread_max_fdtsize; i++) { - if (_thread_fd_table[i] != NULL) { - /* Initialise the file locks: */ - _thread_fd_table[i]->r_owner = NULL; - _thread_fd_table[i]->w_owner = NULL; - _thread_fd_table[i]->r_fname = NULL; - _thread_fd_table[i]->w_fname = NULL; - _thread_fd_table[i]->r_lineno = 0; - _thread_fd_table[i]->w_lineno = 0; - _thread_fd_table[i]->r_lockcount = 0; - _thread_fd_table[i]->w_lockcount = 0; - - /* - * If a fd was in the process of closing - * then finish closing it. - */ - if (_thread_fd_table[i]->state == FD_ENTRY_CLOSING) { - _thread_fd_entry_close(i); - _thread_sys_close(i); - } - - /* Initialise the read/write queues: */ - TAILQ_INIT(&_thread_fd_table[i]->r_queue); - TAILQ_INIT(&_thread_fd_table[i]->w_queue); - } - } - } - } - - /* Return the process ID: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fpathconf.c b/lib/libpthread/uthread/uthread_fpathconf.c deleted file mode 100644 index 5c49b2b2063..00000000000 --- a/lib/libpthread/uthread/uthread_fpathconf.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * David Leonard <d@openbsd.org>, 1999. Public Domain. - * - * $OpenBSD: uthread_fpathconf.c,v 1.2 2002/01/02 16:19:35 fgsch Exp $ - */ - -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -long -fpathconf(int fd, int name) -{ - long ret; - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - ret = _thread_sys_fpathconf(fd, name); - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fstat.c b/lib/libpthread/uthread/uthread_fstat.c deleted file mode 100644 index 29b65b5aac6..00000000000 --- a/lib/libpthread/uthread/uthread_fstat.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_fstat.c,v 1.3 1999/11/25 07:01:35 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fstat.c,v 1.5 1999/08/28 00:03:33 peter Exp $ - */ -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fstat(int fd, struct stat * buf) -{ - int ret; - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the file status: */ - ret = _thread_sys_fstat(fd, buf); - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fstatfs.c b/lib/libpthread/uthread/uthread_fstatfs.c deleted file mode 100644 index ba809a5bef4..00000000000 --- a/lib/libpthread/uthread/uthread_fstatfs.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_fstatfs.c,v 1.3 1999/11/25 07:01:35 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fstatfs.c,v 1.5 1999/08/28 00:03:33 peter Exp $ - */ -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fstatfs(int fd, struct statfs * buf) -{ - int ret; - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the file system status: */ - ret = _thread_sys_fstatfs(fd, buf); - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_READ); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_fsync.c b/lib/libpthread/uthread/uthread_fsync.c deleted file mode 100644 index cc5cb5046e1..00000000000 --- a/lib/libpthread/uthread/uthread_fsync.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: uthread_fsync.c,v 1.5 1999/11/25 07:01:35 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_fsync.c,v 1.5 1999/08/28 00:03:33 peter Exp $ - */ -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -fsync(int fd) -{ - int ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = _thread_sys_fsync(fd); - _FD_UNLOCK(fd, FD_RDWR); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_ftruncate.c b/lib/libpthread/uthread/uthread_ftruncate.c deleted file mode 100644 index c29e2f090dc..00000000000 --- a/lib/libpthread/uthread/uthread_ftruncate.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD: uthread_ftruncate.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */ -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/syscall.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -register_t __syscall(quad_t, ...); - -/* - * This function provides 64-bit offset padding that - * is not supplied by GCC 1.X but is supplied by GCC 2.X. - */ -int -ftruncate(int fd, off_t length) -{ - int retval; - - if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { - retval = -1; - } else { - retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length); - _FD_UNLOCK(fd, FD_RDWR); - } - return retval; -} -#endif diff --git a/lib/libpthread/uthread/uthread_gc.c b/lib/libpthread/uthread/uthread_gc.c deleted file mode 100644 index 8dd1098654c..00000000000 --- a/lib/libpthread/uthread/uthread_gc.c +++ /dev/null @@ -1,218 +0,0 @@ -/* $OpenBSD: uthread_gc.c,v 1.17 2007/05/01 18:16:37 kurt Exp $ */ -/* - * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_gc.c,v 1.10 1999/08/28 00:03:34 peter Exp $ - * - * Garbage collector thread. Frees memory allocated for dead threads. - * - */ -#include <errno.h> -#include <stdlib.h> -#include <time.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <pthread.h> -#include "pthread_private.h" - -/* ARGSUSED */ -pthread_addr_t -_thread_gc(pthread_addr_t arg) -{ - struct pthread *curthread = _get_curthread(); - int f_debug; - int f_done = 0; - int ret; - sigset_t mask; - pthread_t pthread, next; - pthread_t pthread_cln; - struct timespec abstime; - void *p_stack; - - /* Block all signals */ - sigfillset(&mask); - pthread_sigmask(SIG_BLOCK, &mask, NULL); - - /* Mark this thread as a library thread (not a user thread). */ - curthread->flags |= PTHREAD_FLAGS_PRIVATE; - - /* Set a debug flag based on an environment variable. */ - f_debug = (getenv("LIBPTHREAD_DEBUG") != NULL); - - /* Set the name of this thread. */ - pthread_set_name_np(curthread, "GC"); - - while (!f_done) { - /* Check if debugging this application. */ - if (f_debug) - /* Dump thread info to file. */ - _thread_dump_info(); - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Check if this is the last running thread: */ - if (TAILQ_FIRST(&_thread_list) == curthread && - TAILQ_NEXT(curthread, tle) == NULL) - /* - * This is the last thread, so it can exit - * now. - */ - f_done = 1; - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - - /* No stack of thread structure to free yet: */ - p_stack = NULL; - pthread_cln = NULL; - - /* - * Lock the garbage collector mutex which ensures that - * this thread sees another thread exit: - */ - if (pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - /* - * Enter a loop to search for the first dead thread that - * has memory to free. - */ - for (pthread = TAILQ_FIRST(&_dead_list); - p_stack == NULL && pthread_cln == NULL && pthread != NULL; - pthread = next) { - next = TAILQ_NEXT(pthread, dle); - /* Check if the initial thread: */ - if (pthread == _thread_initial) { - /* Don't destroy the initial thread. */ - } - /* - * Check if this thread has detached: - */ - else if ((pthread->attr.flags & - PTHREAD_DETACHED) != 0) { - /* Remove this thread from the dead list: */ - TAILQ_REMOVE(&_dead_list, pthread, dle); - - /* - * Point to the stack structure that must - * be freed outside the locks: - */ - if (pthread->stack != NULL) { - p_stack = pthread->stack; - pthread->stack = NULL; - } - - /* - * Point to the thread structure that must - * be freed outside the locks: - */ - pthread_cln = pthread; - - } else { - /* - * This thread has not detached, so do - * not destroy it. - * - * But we can destroy its stack. - */ - if (pthread->stack != NULL) { - p_stack = pthread->stack; - pthread->stack = NULL; - } - } - } - - /* - * Check if this is not the last thread and there is no - * memory to free this time around. - */ - if (!f_done && p_stack == NULL && pthread_cln == NULL) { - /* Get the current time. */ - if (clock_gettime(CLOCK_REALTIME,&abstime) != 0) - PANIC("gc cannot get time"); - - /* - * Do a backup poll in 10 seconds if no threads - * die before then. - */ - abstime.tv_sec += 10; - - /* - * Wait for a signal from a dying thread or a - * timeout (for a backup poll). - */ - if ((ret = pthread_cond_timedwait(&_gc_cond, - &_gc_mutex, &abstime)) != 0 && ret != ETIMEDOUT) - PANIC("gc cannot wait for a signal"); - } - - /* Unlock the garbage collector mutex: */ - if (pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - - /* - * If there is memory to free, do it now. The call to - * free() might block, so this must be done outside the - * locks. - */ - if (p_stack != NULL) - /* Free the stack storage. */ - _thread_stack_free(p_stack); - - if (pthread_cln != NULL) { - if (pthread_cln->name != NULL) { - /* Free the thread name string. */ - free(pthread_cln->name); - } - /* - * Free the memory allocated for the thread - * structure. - */ - if (pthread_cln->poll_data.fds != NULL) - free(pthread_cln->poll_data.fds); - - if (pthread_cln->specific_data != NULL) - free(pthread_cln->specific_data); - - free(pthread_cln); - } - } - return (NULL); -} diff --git a/lib/libpthread/uthread/uthread_getdirentries.c b/lib/libpthread/uthread/uthread_getdirentries.c deleted file mode 100644 index 23ae786ad27..00000000000 --- a/lib/libpthread/uthread/uthread_getdirentries.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_getdirentries.c,v 1.4 2010/10/28 15:02:41 millert Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_getdirentries.c,v 1.5 1999/08/28 00:03:34 peter Exp $ - */ -#include <sys/types.h> -#include <dirent.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -getdirentries(int fd, char *buf, int nbytes, off_t *basep) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = _thread_sys_getdirentries(fd, buf, nbytes, basep); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_getpeername.c b/lib/libpthread/uthread/uthread_getpeername.c deleted file mode 100644 index 02ff6c83813..00000000000 --- a/lib/libpthread/uthread/uthread_getpeername.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: uthread_getpeername.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_getpeername.c,v 1.5 1999/08/28 00:03:34 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -getpeername(int fd, struct sockaddr * peer, socklen_t *paddrlen) -{ - int ret; - struct fd_table_entry *entry; - - ret = _thread_fd_table_init(fd, FD_INIT_UNKNOWN, NULL); - if (ret == 0) { - entry = _thread_fd_table[fd]; - - _thread_kern_sig_defer(); - if (entry->state == FD_ENTRY_OPEN) { - ret = _thread_sys_getpeername(fd, peer, paddrlen); - } else { - ret = -1; - errno = EBADF; - } - _thread_kern_sig_undefer(); - } - - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_getprio.c b/lib/libpthread/uthread/uthread_getprio.c deleted file mode 100644 index 725fb0bde54..00000000000 --- a/lib/libpthread/uthread/uthread_getprio.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD: uthread_getprio.c,v 1.4 1999/11/25 07:01:36 d Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_getprio.c,v 1.6 1999/08/28 00:03:35 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_getprio(pthread_t pthread) -{ - int policy, ret; - struct sched_param param; - - if ((ret = pthread_getschedparam(pthread, &policy, ¶m)) == 0) - ret = param.sched_priority; - else { - /* Invalid thread: */ - errno = ret; - ret = -1; - } - - /* Return the thread priority or an error status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_getschedparam.c b/lib/libpthread/uthread/uthread_getschedparam.c deleted file mode 100644 index a7f1bf030c6..00000000000 --- a/lib/libpthread/uthread/uthread_getschedparam.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_getschedparam.c,v 1.3 2002/01/19 23:42:40 fgsch Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_getschedparam.c,v 1.3 1999/08/28 00:03:35 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param) -{ - int ret; - - if ((param == NULL) || (policy == NULL)) - /* Return an invalid argument error: */ - ret = EINVAL; - - /* Find the thread in the list of active threads: */ - else if ((ret = _find_thread(pthread)) == 0) { - /* Return the threads base priority and scheduling policy: */ - param->sched_priority = - PTHREAD_BASE_PRIORITY(pthread->base_priority); - *policy = pthread->attr.sched_policy; - } - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_getsockname.c b/lib/libpthread/uthread/uthread_getsockname.c deleted file mode 100644 index 2c634a69fbf..00000000000 --- a/lib/libpthread/uthread/uthread_getsockname.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: uthread_getsockname.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_getsockname.c,v 1.5 1999/08/28 00:03:36 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -getsockname(int fd, struct sockaddr * name, socklen_t *namelen) -{ - int ret; - struct fd_table_entry *entry; - - ret = _thread_fd_table_init(fd, FD_INIT_UNKNOWN, NULL); - if (ret == 0) { - entry = _thread_fd_table[fd]; - - _thread_kern_sig_defer(); - if (entry->state == FD_ENTRY_OPEN) { - ret = _thread_sys_getsockname(fd, name, namelen); - } else { - ret = -1; - errno = EBADF; - } - _thread_kern_sig_undefer(); - } - - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_getsockopt.c b/lib/libpthread/uthread/uthread_getsockopt.c deleted file mode 100644 index 3687c87958d..00000000000 --- a/lib/libpthread/uthread/uthread_getsockopt.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: uthread_getsockopt.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_getsockopt.c,v 1.5 1999/08/28 00:03:36 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen) -{ - int ret; - struct fd_table_entry *entry; - - ret = _thread_fd_table_init(fd, FD_INIT_UNKNOWN, NULL); - if (ret == 0) { - entry = _thread_fd_table[fd]; - - _thread_kern_sig_defer(); - if (entry->state == FD_ENTRY_OPEN) { - ret = _thread_sys_getsockopt(fd, level, optname, optval, optlen); - } else { - ret = -1; - errno = EBADF; - } - _thread_kern_sig_undefer(); - } - - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_info_openbsd.c b/lib/libpthread/uthread/uthread_info_openbsd.c deleted file mode 100644 index b8a415a5604..00000000000 --- a/lib/libpthread/uthread/uthread_info_openbsd.c +++ /dev/null @@ -1,480 +0,0 @@ -/* $OpenBSD: uthread_info_openbsd.c,v 1.17 2011/10/07 08:59:43 fgsch Exp $ */ - -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#include <stdio.h> -#include <fcntl.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <stddef.h> -#include <paths.h> -#include <sys/poll.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int _thread_dump_verbose = 0; - -struct s_thread_info { - enum pthread_state state; - const char *name; -}; - -/* Static variables: */ -static const struct s_thread_info thread_info[] = { - {PS_RUNNING , "running"}, - {PS_SIGTHREAD , "sigthread"}, - {PS_MUTEX_WAIT , "mutex_wait"}, - {PS_COND_WAIT , "cond_wait"}, - {PS_CONNECT_WAIT, "connect_wait"}, - {PS_FDLR_WAIT , "fdlr_wait"}, - {PS_FDLW_WAIT , "fdlw_wait"}, - {PS_FDR_WAIT , "fdr_wait"}, - {PS_FDW_WAIT , "fdw_wait"}, - {PS_FILE_WAIT , "file_wait"}, - {PS_KEVENT_WAIT , "kevent_wait"}, - {PS_POLL_WAIT , "poll_wait"}, - {PS_SELECT_WAIT , "select_wait"}, - {PS_SLEEP_WAIT , "sleep_wait"}, - {PS_WAIT_WAIT , "wait_wait"}, - {PS_SIGSUSPEND , "sigsuspend"}, - {PS_SIGWAIT , "sigwait"}, - {PS_SPINBLOCK , "spinblock"}, - {PS_JOIN , "join"}, - {PS_SUSPENDED , "suspended"}, - {PS_DEAD , "dead"}, - {PS_DEADLOCK , "deadlock"}, - {(enum pthread_state)0, "<invalid>"}, -}; - -#define writestring(fd, s) _thread_sys_write(fd, s, (sizeof s) - 1) - -const static char info_lead[] = " -"; - -/* Determine a filename for display purposes: */ -static const char * -truncname(const char *name, int maxlen) -{ - int len; - - if (name == NULL) - name = "(null)"; - len = (int)strlen(name); - if (len > maxlen) - return name + len - maxlen; - else - return name; -} - -static void -_thread_dump_entry(pthread_t pthread, int fd, int verbose) -{ - const char *state; - char s[512]; - char location[30]; - unsigned int j; - - /* Find last known file:line checkpoint: */ - if (pthread->fname && pthread->state != PS_RUNNING) - snprintf(location, sizeof location, "%s:%d", - truncname(pthread->fname, 21), pthread->lineno); - else - location[0] = '\0'; - - /* Find the state: */ - for (j = 0; j < (sizeof(thread_info) / - sizeof(struct s_thread_info)) - 1; j++) - if (thread_info[j].state == pthread->state) - break; - state = thread_info[j].name; - - /* Output a record for the current thread: */ - s[0] = 0; - snprintf(s, sizeof(s), - " %8p%c%-11s %2d %c%c%c%c%c%c%c%c%c%c %04x %-8.8s %s\n", - (void *)pthread, - (pthread == _thread_run) ? '*' : ' ', - state, - pthread->active_priority, - (pthread->flags & PTHREAD_FLAGS_PRIVATE) ? 'p' : '-', - (pthread->flags & PTHREAD_EXITING) ? 'E' : - (pthread->cancelflags & PTHREAD_AT_CANCEL_POINT) ? 'c' : '-', - (pthread->flags & PTHREAD_FLAGS_TRACE) ? 't' : '-', - (pthread->flags & PTHREAD_FLAGS_IN_CONDQ) ? 'C' : '-', - (pthread->flags & PTHREAD_FLAGS_IN_WORKQ) ? 'R' : '-', - (pthread->flags & PTHREAD_FLAGS_IN_WAITQ) ? 'W' : '-', - (pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) ? 'P' : '-', - (pthread->attr.flags & PTHREAD_DETACHED) ? 'd' : '-', - (pthread->attr.flags & PTHREAD_INHERIT_SCHED) ? 'i' : '-', - (pthread->attr.flags & PTHREAD_NOFLOAT) ? '-' : 'f', - ((unsigned int)pthread->sigmask & 0xffff), - (pthread->name == NULL) ? "" : pthread->name, - (verbose) ? location : "" - ); - _thread_sys_write(fd, s, strlen(s)); - - if (!verbose) - return; - - /* Show the scheduler wake and time slice properties */ - snprintf(s, sizeof(s), "%s sched wake ", info_lead); - _thread_sys_write(fd, s, strlen(s)); - if (pthread->wakeup_time.tv_sec == -1) - writestring(fd, "- slice "); - else { - struct timeval now; - struct timespec nows, delta; - - gettimeofday(&now, NULL); - TIMEVAL_TO_TIMESPEC(&now, &nows); - timespecsub(&pthread->wakeup_time, &nows, &delta); - snprintf(s, sizeof s, "%d.%09ld slice ", - delta.tv_sec, delta.tv_nsec); - _thread_sys_write(fd, s, strlen(s)); - } - if (pthread->slice_usec == -1) - writestring(fd, "-\n"); - else { - snprintf(s, sizeof s, "%ld.%06ld\n", - pthread->slice_usec / 1000000, - pthread->slice_usec % 1000000); - _thread_sys_write(fd, s, strlen(s)); - } - - /* Process according to thread state: */ - switch (pthread->state) { - /* File descriptor read lock wait: */ - case PS_CONNECT_WAIT: - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FDR_WAIT: - case PS_FDW_WAIT: - case PS_KEVENT_WAIT: - /* Write the lock details: */ - snprintf(s, sizeof(s), "%s fd %d [%s:%d]\n", - info_lead, - pthread->data.fd.fd, - truncname(pthread->data.fd.fname, 32), - pthread->data.fd.branch); - _thread_sys_write(fd, s, strlen(s)); - s[0] = 0; - if (_thread_fd_table[pthread->data.fd.fd] && - _thread_fd_table[pthread->data.fd.fd]->state != FD_ENTRY_CLOSED) - snprintf(s, sizeof(s), "%s owner %pr/%pw\n", - info_lead, - _thread_fd_table[pthread->data.fd.fd]->r_owner, - _thread_fd_table[pthread->data.fd.fd]->w_owner); - else - snprintf(s, sizeof(s), "%s owner [unknown]\n", info_lead); - _thread_sys_write(fd, s, strlen(s)); - break; - case PS_SIGWAIT: - snprintf(s, sizeof(s), "%s sigmask 0x%08lx\n", - info_lead, - (unsigned long)pthread->sigmask); - _thread_sys_write(fd, s, strlen(s)); - break; - case PS_MUTEX_WAIT: - snprintf(s, sizeof(s), - "%s mutex %p\n", - info_lead, - pthread->data.mutex); - _thread_sys_write(fd, s, strlen(s)); - if (pthread->data.mutex) { - snprintf(s, sizeof(s), - "%s owner %p\n", - info_lead, - pthread->data.mutex->m_owner); - _thread_sys_write(fd, s, strlen(s)); - } - break; - case PS_COND_WAIT: - snprintf(s, sizeof(s), - "%s cond %p\n", - info_lead, - pthread->data.cond); - _thread_sys_write(fd, s, strlen(s)); - break; -#ifdef notyet - case PS_JOIN: - { - struct pthread *t, * volatile *last; - pthread_entry_t *e; - - /* Find the end of the list: */ - for (e = &pthread->qe; e->tqe_next != NULL; - e = &e->tqe_next->qe) - ; - last = &e->tqe_next; - /* Walk backwards to the head: */ - for (e = &pthread->qe; - ((_thread_list_t *)e)->tqh_last != last; - e = (pthread_entry_t *)e->tqe_prev) - ; - /* Convert the head address into a thread address: */ - t = (pthread_t)((caddr_t)e - - offsetof(struct pthread, join_queue)); - snprintf(s, sizeof(s), - "%s thread %p\n", info_lead, t); - _thread_sys_write(fd, s, strlen(s)); - } - break; -#endif - case PS_SLEEP_WAIT: - { - struct timeval tv; - struct timespec current_time; - struct timespec remaining_time; - double remain; - - gettimeofday(&tv, NULL); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time); - timespecsub(&pthread->wakeup_time, - ¤t_time, &remaining_time); - remain = remaining_time.tv_sec - + (double)remaining_time.tv_nsec / 1e9; - snprintf(s, sizeof(s), - "%s wake in %f sec\n", - info_lead, remain); - _thread_sys_write(fd, s, strlen(s)); - } - break; - case PS_SELECT_WAIT: - case PS_POLL_WAIT: - { - nfds_t i; - - for (i = 0; i < pthread->data.poll_data->nfds; i++) - snprintf(s, sizeof(s), "%s%d:%s%s", - i ? " " : "", - pthread->data.poll_data->fds[i].fd, - pthread->data.poll_data->fds[i].events & - POLLIN ? "r" : "", - pthread->data.poll_data->fds[i].events & - POLLOUT ? "w" : "" - ); - snprintf(s, sizeof(s), "\n"); - } - break; - default: - /* Nothing to do here. */ - break; - } -} - -void -_thread_dump_info(void) -{ - char s[512]; - int fd; - int i; - pthread_t pthread; - pq_list_t * pq_list; - int verbose; - - verbose = _thread_dump_verbose; - if (getenv("PTHREAD_DEBUG") != NULL) - verbose = 1; - - /* Open the controlling tty: */ - fd = _thread_sys_open(_PATH_TTY, O_WRONLY | O_APPEND); - if (fd < 0) - return; - - if (!verbose) { - /* Display only a very brief list of threads */ - TAILQ_FOREACH(pthread, &_thread_list, tle) - if ((pthread->flags & PTHREAD_FLAGS_PRIVATE) == 0) - _thread_dump_entry(pthread, fd, 0); - return; - } - - /* Display a list of active threads: */ - snprintf(s, sizeof s, " %8s%c%-11s %2s %-10s %4s %-8s %s\n", - "id", ' ', "state", "pr", "flags", "mask", "name", "location"); - _thread_sys_write(fd, s, strlen(s)); - - writestring(fd, "active:\n"); - - TAILQ_FOREACH(pthread, &_thread_list, tle) - _thread_dump_entry(pthread, fd, 1); - - writestring(fd, "ready:\n"); - TAILQ_FOREACH (pq_list, &_readyq.pq_queue, pl_link) - TAILQ_FOREACH(pthread, &pq_list->pl_head, pqe) - _thread_dump_entry(pthread, fd, 0); - - writestring(fd, "waiting:\n"); - TAILQ_FOREACH (pthread, &_waitingq, pqe) - _thread_dump_entry(pthread, fd, 0); - - writestring(fd, "workq:\n"); - TAILQ_FOREACH (pthread, &_workq, qe) - _thread_dump_entry(pthread, fd, 0); - - writestring(fd, "dead:\n"); - TAILQ_FOREACH(pthread, &_dead_list, dle) - _thread_dump_entry(pthread, fd, 1); - - /* Output a header for file descriptors: */ - snprintf(s, sizeof(s), "file descriptor table, size %d:\n", - _thread_max_fdtsize); - _thread_sys_write(fd, s, strlen(s)); - - snprintf(s, sizeof s, - " %3s %8s %4s %21s %8s %4s %21s\n", - "fd", "rdowner", "rcnt", "rdcode", - "wrowner", "wcnt", "wrcode"); - _thread_sys_write(fd, s, strlen(s)); - - /* Enter a loop to report file descriptor lock usage: */ - for (i = 0; i < _thread_max_fdtsize; i++) { - /* - * Check if memory is allocated for this file - * descriptor: - */ - char rcode[22], wcode[22]; - - if (_thread_fd_table[i] != NULL && - _thread_fd_table[i]->state != FD_ENTRY_CLOSED) { - - /* Find the reader's last file:line: */ - if (_thread_fd_table[i]->r_owner) - snprintf(rcode, sizeof rcode, "%s:%d", - truncname(_thread_fd_table[i]->r_fname, 16), - _thread_fd_table[i]->r_lineno); - else - rcode[0] = '\0'; - - /* Find the writer's last file:line: */ - if (_thread_fd_table[i]->w_owner) - snprintf(wcode, sizeof wcode, "%s:%d", - truncname(_thread_fd_table[i]->w_fname, 16), - _thread_fd_table[i]->w_lineno); - else - wcode[0] = '\0'; - - /* Report the file descriptor lock status: */ - snprintf(s, sizeof(s), - " %3d %8p %4d %21s %8p %4d %21s\n", - i, - _thread_fd_table[i]->r_owner, - _thread_fd_table[i]->r_lockcount, - rcode, - _thread_fd_table[i]->w_owner, - _thread_fd_table[i]->w_lockcount, - wcode - ); - _thread_sys_write(fd, s, strlen(s)); - } - } - - /* Close the dump file: */ - _thread_sys_close(fd); - return; -} - -/* - * Generic "dump some data to /dev/tty in hex format" function - * output format is: - * 0 22 48 - * 0x0123456789abcdef: 00 11 22 33 44 55 66 77 01234567 - */ -#define DUMP_BUFLEN 84 -#define DUMP_HEX_OFF 22 -#define DUMP_ASCII_OFF 48 - -void -_thread_dump_data(const void *addr, int len) -{ - int fd = -1; - unsigned char data[DUMP_BUFLEN]; - const unsigned char hexdigits[] = "0123456789abcdef"; - - if (getenv("PTHREAD_DEBUG") != NULL) - fd = _thread_sys_open(_PATH_TTY, O_WRONLY | O_APPEND); - if (fd != -1) { - memset(data, ' ', DUMP_BUFLEN); - while (len) { - const unsigned char *d; - unsigned char *h; - unsigned char *a; - int count; - - d = addr; - h = &data[DUMP_HEX_OFF]; - a = &data[DUMP_ASCII_OFF]; - - if (len > 8) { - count = 8; - len -= 8; - } else { - count = len; - len = 0; - memset(data, ' ', DUMP_BUFLEN); - } - addr = (char *)addr + 8; - - snprintf((char *)data, DUMP_BUFLEN, "%18p: ", d); - while (count--) { - if (isprint(*d)) - *a++ = *d; - else - *a++ = '.'; - *h++ = hexdigits[(*d >> 4) & 0xf]; - *h++ = hexdigits[*d++ & 0xf]; - *h++ = ' '; - } - *a++ = '\n'; - *a = 0; - _thread_sys_write(fd, data, (size_t)(a - data)); - } - writestring(fd, "\n"); - _thread_sys_close(fd); - } -} - -/* Set the thread name for debug: */ -void -pthread_set_name_np(pthread_t thread, const char *name) -{ - /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == PTHREAD_MAGIC) { - if (thread->name != NULL) - free(thread->name); - thread->name = strdup(name); - } - return; -} -#endif diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c deleted file mode 100644 index 436cd73fcb1..00000000000 --- a/lib/libpthread/uthread/uthread_init.c +++ /dev/null @@ -1,420 +0,0 @@ -/* $OpenBSD: uthread_init.c,v 1.47 2012/01/17 02:52:39 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_init.c,v 1.18 1999/08/28 00:03:36 peter Exp $ - */ - -/* Allocate space for global thread variables here: */ -#define GLOBAL_PTHREAD_PRIVATE - -#include <sys/types.h> -#include <sys/param.h> - -#include <sys/event.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/socket.h> -#include <sys/stat.h> -#include <sys/sysctl.h> -#include <sys/time.h> -#include <sys/ttycom.h> -#include <sys/user.h> -#include <sys/wait.h> -#include <sys/resource.h> - -#include <dlfcn.h> -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <paths.h> -#include <poll.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#ifdef _THREAD_SAFE -#include <machine/reg.h> -#include <pthread.h> -#include "pthread_private.h" - -/* Global thread variables. */ -_stack_list_t _stackq; - -extern int _thread_autoinit_dummy_decl; - -/* - * All weak references used within libc that are redefined in libpthread - * MUST be in this table. This is necessary to force the proper version to - * be used when linking -static. - */ -static void *references[] __used = { - &_exit, - &accept, - &bind, - &close, - &closefrom, - &connect, - &dup, - &dup2, - &execve, - &fchflags, - &fchmod, - &fchown, - &fcntl, - &flock, - &fork, - &fpathconf, - &fstat, - &fstatfs, - &fsync, - &getdirentries, - &getpeername, - &getsockname, - &getsockopt, - &ioctl, - &kevent, - &kqueue, - &listen, - &msync, - &nanosleep, - &open, - &pipe, - &poll, - &pread, - &pwrite, - &read, - &readv, - &recvfrom, - &recvmsg, - &select, - &sendmsg, - &sendto, - &setsockopt, - &shutdown, - &sigaction, - &sigaltstack, - &sigpending, - &sigprocmask, - &sigsuspend, - &socket, - &socketpair, - &vfork, - &wait4, - &write, - &writev, - /* libc thread-safe helper functions */ - &_thread_malloc_lock, - &_thread_malloc_unlock, - &_thread_atexit_lock, - &_thread_atexit_unlock, - &_thread_arc4_lock, - &_thread_arc4_unlock, - &_thread_tag_lock, - &_thread_tag_unlock, - &_thread_tag_storage, - &_thread_mutex_lock, - &_thread_mutex_unlock, - &_thread_mutex_destroy, - &flockfile, - &ftruncate, - &ftrylockfile, - &funlockfile, - &lseek -}; - -/* - * Threaded process initialization - */ -void -_thread_init(void) -{ - int fd; - int flags; - int res; - int i; - size_t len; - int mib[2]; - struct clockinfo clockinfo; - struct sigaction act; - struct rlimit rl; - - /* Check if this function has already been called: */ - if (_thread_initial) - /* Only initialise the threaded application once. */ - return; - - if (references[0] == NULL) - PANIC("Failed loading mandatory references in _thread_init"); - - /* - * Check for the special case of this process running as - * or in place of init as pid = 1: - */ - if (getpid() == 1) { - /* - * Setup a new session for this process which is - * assumed to be running as root. - */ - if (setsid() == -1) - PANIC("Can't set session ID"); - if (revoke(_PATH_CONSOLE) != 0) - PANIC("Can't revoke console"); - if ((fd = _thread_sys_open(_PATH_CONSOLE, O_RDWR)) < 0) - PANIC("Can't open console"); - if (setlogin("root") == -1) - PANIC("Can't set login to root"); - if (_thread_sys_ioctl(fd,TIOCSCTTY, (char *) NULL) == -1) - PANIC("Can't set controlling terminal"); - if (_thread_sys_dup2(fd,0) == -1 || - _thread_sys_dup2(fd,1) == -1 || - _thread_sys_dup2(fd,2) == -1) - PANIC("Can't dup2"); - } - - /* - * Create a pipe that is written to by the signal handler to prevent - * signals being missed in calls to _select: - */ - if (_thread_sys_pipe(_thread_kern_pipe) != 0) - PANIC("Cannot create kernel pipe"); - - flags = _thread_sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL); - if (flags == -1) - PANIC("Cannot get kernel read pipe flags"); - - res = _thread_sys_fcntl(_thread_kern_pipe[0], F_SETFL, - flags | O_NONBLOCK); - if (res == -1) - PANIC("Cannot make kernel read pipe non-blocking"); - - flags = _thread_sys_fcntl(_thread_kern_pipe[0], F_GETFD, NULL); - if (flags == -1) - PANIC("Cannot get kernel read pipe fd flags"); - - res = _thread_sys_fcntl(_thread_kern_pipe[0], F_SETFD, - flags | FD_CLOEXEC); - if (res == -1) - PANIC("Cannot make kernel read pipe close-on-exec"); - - flags = _thread_sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL); - if (flags == -1) - PANIC("Cannot get kernel write pipe flags"); - - res = _thread_sys_fcntl(_thread_kern_pipe[1], F_SETFL, - flags | O_NONBLOCK); - if (res == -1) - PANIC("Cannot make kernel write pipe non-blocking"); - - flags = _thread_sys_fcntl(_thread_kern_pipe[1], F_GETFD, NULL); - if (flags == -1) - PANIC("Cannot get kernel write pipe fd flags"); - - res = _thread_sys_fcntl(_thread_kern_pipe[1], F_SETFD, - flags | FD_CLOEXEC); - if (res == -1) - PANIC("Cannot make kernel write pipe close-on-exec"); - - res = _pq_alloc(&_readyq, PTHREAD_MIN_PRIORITY, PTHREAD_LAST_PRIORITY); - if (res != 0) - PANIC("Cannot allocate priority ready queue."); - - _thread_initial = (pthread_t) malloc(sizeof(struct pthread)); - if (_thread_initial == NULL) - PANIC("Cannot allocate memory for initial thread"); - - - /* Zero the global kernel thread structure: */ - memset(&_thread_kern_thread, 0, sizeof(struct pthread)); - _thread_kern_thread.flags = PTHREAD_FLAGS_PRIVATE; - memset(_thread_initial, 0, sizeof(struct pthread)); - - /* Initialize the waiting and work queues: */ - TAILQ_INIT(&_waitingq); - TAILQ_INIT(&_workq); - - /* Initialize the scheduling switch hook routine: */ - _sched_switch_hook = NULL; - - /* Initialize the thread stack cache: */ - SLIST_INIT(&_stackq); - - /* - * Write a magic value to the thread structure - * to help identify valid ones: - */ - _thread_initial->magic = PTHREAD_MAGIC; - - /* Set the initial cancel state */ - _thread_initial->cancelflags = PTHREAD_CANCEL_ENABLE | - PTHREAD_CANCEL_DEFERRED; - - /* Default the priority of the initial thread: */ - _thread_initial->base_priority = PTHREAD_DEFAULT_PRIORITY; - _thread_initial->active_priority = PTHREAD_DEFAULT_PRIORITY; - _thread_initial->inherited_priority = 0; - - /* Initialise the state of the initial thread: */ - _thread_initial->state = PS_RUNNING; - - /* Initialize joiner to NULL (no joiner): */ - _thread_initial->joiner = NULL; - - /* Initialize the owned mutex queue and count: */ - TAILQ_INIT(&(_thread_initial->mutexq)); - _thread_initial->priority_mutex_count = 0; - - /* Initialize the global scheduling time: */ - _sched_ticks = 0; - gettimeofday((struct timeval *) &_sched_tod, NULL); - - /* Initialize last active: */ - _thread_initial->last_active = (long) _sched_ticks; - - /* Give it a useful name */ - pthread_set_name_np(_thread_initial, "main"); - - /* Initialise the rest of the fields: */ - _thread_initial->poll_data.nfds = 0; - _thread_initial->poll_data.fds = NULL; - _thread_initial->sig_defer_count = 0; - _thread_initial->slice_usec = -1; - _thread_initial->sig_saved = 0; - _thread_initial->yield_on_sig_undefer = 0; - _thread_initial->specific_data = NULL; - _thread_initial->cleanup = NULL; - _thread_initial->flags = 0; - _thread_initial->error = 0; - _SPINLOCK_INIT(&_thread_initial->lock); - TAILQ_INIT(&_thread_list); - TAILQ_INSERT_HEAD(&_thread_list, _thread_initial, tle); - _set_curthread(_thread_initial); - TAILQ_INIT(&_atfork_list); - pthread_mutex_init(&_atfork_mutex, NULL); - - /* Initialise the global signal action structure: */ - sigfillset(&act.sa_mask); - act.sa_handler = (void (*) (int)) _thread_sig_handler; - act.sa_flags = SA_SIGINFO; - - /* Clear pending signals for the process: */ - sigemptyset(&_process_sigpending); - - /* Initialize signal handling: */ - _thread_sig_init(); - - /* Enter a loop to get the existing signal status: */ - for (i = 1; i < NSIG; i++) { - /* Check for signals which cannot be trapped: */ - if (i == SIGKILL || i == SIGSTOP) - continue; - - /* Get the signal handler details: */ - if (_thread_sys_sigaction(i, NULL, &_thread_sigact[i - 1]) != 0) - PANIC("Cannot read signal handler info"); - - /* Initialize the SIG_DFL dummy handler count. */ - _thread_dfl_count[i] = 0; - } - - /* - * Install the signal handler for the most important - * signals that the user-thread kernel needs. Actually - * SIGINFO isn't really needed, but it is nice to have. - */ - if (_thread_sys_sigaction(_SCHED_SIGNAL, &act, NULL) != 0 || - _thread_sys_sigaction(SIGINFO, &act, NULL) != 0 || - _thread_sys_sigaction(SIGCHLD, &act, NULL) != 0) - PANIC("Cannot initialize signal handler"); - - _thread_sigact[_SCHED_SIGNAL - 1].sa_flags = SA_SIGINFO; - _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO; - _thread_sigact[SIGCHLD - 1].sa_flags = SA_SIGINFO; - - /* Get the process signal mask: */ - _thread_sys_sigprocmask(SIG_SETMASK, NULL, &_process_sigmask); - - /* Get the kernel clockrate: */ - mib[0] = CTL_KERN; - mib[1] = KERN_CLOCKRATE; - len = sizeof (struct clockinfo); - if (sysctl(mib, 2, &clockinfo, &len, NULL, 0) == 0) - _clock_res_usec = clockinfo.tick > CLOCK_RES_USEC_MIN ? - clockinfo.tick : CLOCK_RES_USEC_MIN; - - /* Get the table size: */ - if (getrlimit(RLIMIT_NOFILE, &rl) != 0) - PANIC("getrlimit failed"); - - _thread_init_fdtsize = (int)rl.rlim_cur; - _thread_max_fdtsize = (int)rl.rlim_max; - _thread_max_pfdtsize = (nfds_t)rl.rlim_max; - - /* Get the default guardsize */ - pthread_attr_default.guardsize_attr = (size_t)sysconf(_SC_PAGESIZE); - - /* Allocate memory for the file descriptor table: */ - _thread_fd_table = calloc((size_t)_thread_max_fdtsize, - sizeof(struct fd_table_entry *)); - if (_thread_fd_table == NULL) { - _thread_max_fdtsize = 0; - PANIC("Cannot allocate memory for file descriptor table"); - } - - if (_thread_fd_init_mem()) { - _thread_max_fdtsize = 0; - PANIC("Cannot allocate memory for file descriptor table"); - } - - /* Allocate memory for the pollfd table: */ - _thread_pfd_table = calloc((size_t)_thread_max_pfdtsize, sizeof(struct pollfd)); - if (_thread_pfd_table == NULL) - PANIC("Cannot allocate memory for pollfd table"); - - /* Initialize the fd table: */ - _thread_fd_init(); - - /* Initialize the key table: */ - _thread_key_init(); - - /* Initialise the garbage collector mutex and condition variable. */ - if (pthread_mutex_init(&_gc_mutex,NULL) != 0 || - pthread_cond_init(&_gc_cond,NULL) != 0) - PANIC("Failed to initialise garbage collector mutex or cond"); - -#if defined(__ELF__) - /* Register with dlctl for thread safe dlopen */ - dlctl(NULL, DL_SETTHREADLCK, _thread_kern_lock); -#endif - _thread_autoinit_dummy_decl = 0; -} -#endif diff --git a/lib/libpthread/uthread/uthread_ioctl.c b/lib/libpthread/uthread/uthread_ioctl.c deleted file mode 100644 index a8347dfb94e..00000000000 --- a/lib/libpthread/uthread/uthread_ioctl.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $OpenBSD: uthread_ioctl.c,v 1.4 2006/09/22 19:04:33 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_ioctl.c,v 1.6 1999/08/28 00:03:37 peter Exp $ - */ -#include <stdarg.h> -#include <sys/ioctl.h> -#ifdef _THREAD_SAFE -#include <sys/fcntl.h> /* O_NONBLOCK*/ -#include <pthread.h> -#include "pthread_private.h" - -int -ioctl(int fd, unsigned long request,...) -{ - int ret; - int *op; - va_list ap; - - /* Lock the file descriptor: */ - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - /* Initialise the variable argument list: */ - va_start(ap, request); - - switch( request) { - case FIONBIO: - /* - * descriptors must be non-blocking; we are only - * twiddling the flag based on the request - */ - op = va_arg(ap, int *); - _thread_fd_table[fd]->status_flags->flags &= ~O_NONBLOCK; - _thread_fd_table[fd]->status_flags->flags |= ((*op) ? O_NONBLOCK : 0); - ret = 0; - break; - default: - ret = _thread_sys_ioctl(fd, request, va_arg(ap, char *)); - break; - } - - /* Free variable arguments: */ - va_end(ap); - - /* Unlock the file descriptor: */ - _FD_UNLOCK(fd, FD_RDWR); - } - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_join.c b/lib/libpthread/uthread/uthread_join.c deleted file mode 100644 index 9701f2d1aa8..00000000000 --- a/lib/libpthread/uthread/uthread_join.c +++ /dev/null @@ -1,157 +0,0 @@ -/* $OpenBSD: uthread_join.c,v 1.11 2003/12/31 21:11:45 marc Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_join.c,v 1.9 1999/08/28 00:03:37 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_join(pthread_t pthread, void **thread_return) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - pthread_t thread; - - _thread_enter_cancellation_point(); - - /* Check if the caller has specified an invalid thread: */ - if (pthread == NULL || pthread->magic != PTHREAD_MAGIC) { - /* Invalid thread: */ - _thread_leave_cancellation_point(); - return (EINVAL); - } - - /* Check if the caller has specified itself: */ - if (pthread == curthread) { - /* Avoid a deadlock condition: */ - _thread_leave_cancellation_point(); - return (EDEADLK); - } - - /* - * Lock the garbage collector mutex to ensure that the garbage - * collector is not using the dead thread list. - */ - if (pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - /* - * Defer signals to protect the thread list from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - /* - * Unlock the garbage collector mutex, now that the garbage collector - * can't be run: - */ - if (pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - - /* - * Search for the specified thread in the list of active threads. This - * is done manually here rather than calling _find_thread() because - * the searches in _thread_list and _dead_list (as well as setting up - * join/detach state) have to be done atomically. - */ - TAILQ_FOREACH(thread, &_thread_list, tle) { - if (thread == pthread) - break; - } - if (thread == NULL) { - /* - * Search for the specified thread in the list of dead threads: - */ - TAILQ_FOREACH(thread, &_dead_list, dle) { - if (thread == pthread) - break; - } - } - - /* Check if the thread was not found or has been detached: */ - if (thread == NULL || - ((pthread->attr.flags & PTHREAD_DETACHED) != 0)) - /* Return an error: */ - ret = ESRCH; - - else if (pthread->joiner != NULL) - /* Multiple joiners are not supported. */ - ret = ENOTSUP; - - /* Check if the thread is not dead: */ - else if (pthread->state != PS_DEAD) { - /* Set the running thread to be the joiner: */ - pthread->joiner = curthread; - - /* Keep track of which thread we're joining to: */ - curthread->join_status.thread = pthread; - - while (curthread->join_status.thread == pthread) { - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); - } - - /* - * The thread return value and error are set by the thread we're - * joining to when it exits or detaches: - */ - ret = curthread->join_status.error; - if ((ret == 0) && (thread_return != NULL)) - *thread_return = curthread->join_status.ret; - } else { - /* - * The thread exited (is dead) without being detached, and no - * thread has joined it. - */ - - /* Check if the return value is required: */ - if (thread_return != NULL) { - /* Return the thread's return value: */ - *thread_return = pthread->ret; - } - - /* Make the thread collectable by the garbage collector. */ - pthread->attr.flags |= PTHREAD_DETACHED; - - } - /* Undefer and handle pending signals, yielding if necessary: */ - _thread_kern_sig_undefer(); - - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c deleted file mode 100644 index fa06b812c94..00000000000 --- a/lib/libpthread/uthread/uthread_kern.c +++ /dev/null @@ -1,1129 +0,0 @@ -/* $OpenBSD: uthread_kern.c,v 1.41 2011/10/07 08:59:43 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_kern.c,v 1.23 1999/09/29 15:18:39 marcel Exp $ - * - */ -#include <errno.h> -#include <poll.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/uio.h> -#include <sys/syscall.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * local functions. Do NOT make these static... we want so see them in - * crash dumps. - */ -void _thread_kern_poll(int); -void _dequeue_signals(void); -inline void _thread_run_switch_hook(pthread_t, pthread_t); - -/* Static variables: */ -static unsigned int last_tick = 0; - -void -_thread_kern_sched(struct sigcontext * scp) -{ - struct timespec ts; - struct timeval tv; - struct pthread *curthread = _get_curthread(); - pthread_t pthread, pthread_h; - unsigned int current_tick; - int add_to_prioq; - pthread_t old_thread_run; - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a scheduler signal from interrupting this - * execution and calling the scheduler again. - */ - _thread_kern_in_sched = 1; - - /* Check if this function was called from the signal handler: */ - if (scp != NULL) { - /* - * The signal handler should have saved the state of - * the current thread. Restore the process signal - * mask. - */ - if (_thread_sys_sigprocmask(SIG_SETMASK, - &_process_sigmask, NULL) != 0) - PANIC("Unable to restore process mask after signal"); - - /* - * Copy the signal context to the current thread's jump - * buffer: - */ - memcpy(&curthread->saved_sigcontext, scp, - sizeof(curthread->saved_sigcontext)); - - /* Flag the signal context as the last state saved: */ - curthread->sig_saved = 1; - } else - /* Flag the jump buffer was the last state saved: */ - curthread->sig_saved = 0; - - /* If the currently running thread is a user thread, save it: */ - if ((curthread->flags & PTHREAD_FLAGS_PRIVATE) == 0) - _last_user_thread = curthread; - - /* Save floating point state. */ - _thread_machdep_save_float_state(&curthread->_machdep); - - /* Save errno. */ - curthread->error = errno; - - /* Save the current thread to switch from */ - old_thread_run = curthread; - - /* - * Enter a scheduling loop that finds the next thread that is - * ready to run. This loop completes when there are no more threads - * in the global list or when a thread has its state restored by - * either a sigreturn (if the state was saved as a sigcontext) or a - * switch. - */ - while (!(TAILQ_EMPTY(&_thread_list))) { - /* Get the current time of day: */ - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, &ts); - current_tick = _sched_ticks; - - /* - * Protect the scheduling queues from access by the signal - * handler. - */ - _queue_signals = 1; - add_to_prioq = 0; - - if (curthread != &_thread_kern_thread) { - /* - * This thread no longer needs to yield the CPU. - */ - curthread->yield_on_sig_undefer = 0; - - if (curthread->state != PS_RUNNING) { - /* - * Save the current time as the time that the - * thread became inactive: - */ - curthread->last_inactive = (long)current_tick; - if (curthread->last_inactive < - curthread->last_active) { - /* Account for a rollover: */ - curthread->last_inactive =+ - UINT_MAX + 1; - } - } - - /* - * Place the currently running thread into the - * appropriate queue(s). - */ - switch (curthread->state) { - case PS_DEAD: - case PS_STATE_MAX: /* to silence -Wall */ - case PS_SUSPENDED: - /* - * Dead and suspended threads are not placed - * in any queue: - */ - break; - - case PS_RUNNING: - /* - * Runnable threads can't be placed in the - * priority queue until after waiting threads - * are polled (to preserve round-robin - * scheduling). - */ - add_to_prioq = 1; - break; - - /* - * States which do not depend on file descriptor I/O - * operations or timeouts: - */ - case PS_DEADLOCK: - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FILE_WAIT: - case PS_JOIN: - case PS_MUTEX_WAIT: - case PS_SIGSUSPEND: - case PS_SIGTHREAD: - case PS_SIGWAIT: - case PS_WAIT_WAIT: - /* No timeouts for these states: */ - curthread->wakeup_time.tv_sec = -1; - curthread->wakeup_time.tv_nsec = -1; - - /* Restart the time slice: */ - curthread->slice_usec = -1; - - /* Insert into the waiting queue: */ - PTHREAD_WAITQ_INSERT(curthread); - break; - - /* States which can timeout: */ - case PS_COND_WAIT: - case PS_SLEEP_WAIT: - /* Restart the time slice: */ - curthread->slice_usec = -1; - - /* Insert into the waiting queue: */ - PTHREAD_WAITQ_INSERT(curthread); - break; - - /* States that require periodic work: */ - case PS_SPINBLOCK: - /* No timeouts for this state: */ - curthread->wakeup_time.tv_sec = -1; - curthread->wakeup_time.tv_nsec = -1; - - /* Increment spinblock count: */ - _spinblock_count++; - - /* FALLTHROUGH */ - case PS_CONNECT_WAIT: - case PS_FDR_WAIT: - case PS_FDW_WAIT: - case PS_KEVENT_WAIT: - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Restart the time slice: */ - curthread->slice_usec = -1; - - /* Insert into the waiting queue: */ - PTHREAD_WAITQ_INSERT(curthread); - - /* Insert into the work queue: */ - PTHREAD_WORKQ_INSERT(curthread); - break; - } - } - - /* - * Avoid polling file descriptors if there are none - * waiting: - */ - if (TAILQ_EMPTY(&_workq) != 0) { - } - /* - * Poll file descriptors only if a new scheduling signal - * has occurred or if we have no more runnable threads. - */ - else if (((current_tick = _sched_ticks) != last_tick) || - ((curthread->state != PS_RUNNING) && - (PTHREAD_PRIOQ_FIRST() == NULL))) { - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - /* - * Poll file descriptors to update the state of threads - * waiting on file I/O where data may be available: - */ - _thread_kern_poll(0); - - /* Protect the scheduling queues: */ - _queue_signals = 1; - } - last_tick = current_tick; - - /* - * Wake up threads that have timedout. This has to be - * done after polling in case a thread does a poll or - * select with zero time. - */ - PTHREAD_WAITQ_SETACTIVE(); - while (((pthread = TAILQ_FIRST(&_waitingq)) != NULL) && - (pthread->wakeup_time.tv_sec != -1) && - (((pthread->wakeup_time.tv_sec == 0) && - (pthread->wakeup_time.tv_nsec == 0)) || - (pthread->wakeup_time.tv_sec < ts.tv_sec) || - ((pthread->wakeup_time.tv_sec == ts.tv_sec) && - (pthread->wakeup_time.tv_nsec <= ts.tv_nsec)))) { - switch (pthread->state) { - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Return zero file descriptors ready: */ - pthread->data.poll_data->nfds = 0; - /* fall through */ - default: - /* - * Remove this thread from the waiting queue - * (and work queue if necessary) and place it - * in the ready queue. - */ - PTHREAD_WAITQ_CLEARACTIVE(); - if (pthread->flags & PTHREAD_FLAGS_IN_WORKQ) - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread, PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - break; - } - /* - * Flag the timeout in the thread structure: - */ - pthread->timeout = 1; - } - PTHREAD_WAITQ_CLEARACTIVE(); - - /* - * Check to see if the current thread needs to be added - * to the priority queue: - */ - if (add_to_prioq != 0) { - /* - * Save the current time as the time that the - * thread became inactive: - */ - current_tick = _sched_ticks; - curthread->last_inactive = (long)current_tick; - if (curthread->last_inactive < - curthread->last_active) { - /* Account for a rollover: */ - curthread->last_inactive =+ UINT_MAX + 1; - } - - if ((curthread->slice_usec != -1) && - (curthread->attr.sched_policy != SCHED_FIFO)) { - /* - * Accumulate the number of microseconds for - * which the current thread has run: - */ - curthread->slice_usec += - (curthread->last_inactive - - curthread->last_active) * - (long)_clock_res_usec; - /* Check for time quantum exceeded: */ - if (curthread->slice_usec > TIMESLICE_USEC) - curthread->slice_usec = -1; - } - - if (curthread->slice_usec == -1) { - /* - * The thread exceeded its time - * quantum or it yielded the CPU; - * place it at the tail of the - * queue for its priority. - */ - PTHREAD_PRIOQ_INSERT_TAIL(curthread); - } else { - /* - * The thread hasn't exceeded its - * interval. Place it at the head - * of the queue for its priority. - */ - PTHREAD_PRIOQ_INSERT_HEAD(curthread); - } - } - - /* - * Get the highest priority thread in the ready queue. - */ - pthread_h = PTHREAD_PRIOQ_FIRST(); - - /* Check if there are no threads ready to run: */ - if (pthread_h == NULL) { - /* - * Lock the pthread kernel by changing the pointer to - * the running thread to point to the global kernel - * thread structure: - */ - _set_curthread(&_thread_kern_thread); - curthread = &_thread_kern_thread; - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - /* - * There are no threads ready to run, so wait until - * something happens that changes this condition: - */ - _thread_kern_poll(1); - - /* - * This process' usage will likely be very small - * while waiting in a poll. Since the scheduling - * clock is based on the profiling timer, it is - * unlikely that the profiling timer will fire - * and update the time of day. To account for this, - * get the time of day after polling with a timeout. - */ - gettimeofday((struct timeval *) &_sched_tod, NULL); - - /* Check once more for a runnable thread: */ - _queue_signals = 1; - pthread_h = PTHREAD_PRIOQ_FIRST(); - _queue_signals = 0; - } - - if (pthread_h != NULL) { - /* Remove the thread from the ready queue: */ - PTHREAD_PRIOQ_REMOVE(pthread_h); - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - /* - * Check for signals queued while the scheduling - * queues were protected: - */ - while (_sigq_check_reqd != 0) { - /* Clear before handling queued signals: */ - _sigq_check_reqd = 0; - - /* Protect the scheduling queues again: */ - _queue_signals = 1; - - _dequeue_signals(); - - /* - * Check for a higher priority thread that - * became runnable due to signal handling. - */ - if (((pthread = PTHREAD_PRIOQ_FIRST()) != NULL) && - (pthread->active_priority > pthread_h->active_priority)) { - /* Remove the thread from the ready queue: */ - PTHREAD_PRIOQ_REMOVE(pthread); - - /* - * Insert the lower priority thread - * at the head of its priority list: - */ - PTHREAD_PRIOQ_INSERT_HEAD(pthread_h); - - /* There's a new thread in town: */ - pthread_h = pthread; - } - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - } - - /* - * Prevent the signal handler from fiddling with this - * thread before its state is set. - */ - _queue_signals = 1; - - /* Make the selected thread the current thread: */ - _set_curthread(pthread_h); - curthread = pthread_h; - - /* - * Save the current time as the time that the thread - * became active: - */ - current_tick = _sched_ticks; - curthread->last_active = (long) current_tick; - - /* - * Check if this thread is running for the first time - * or running again after using its full time slice - * allocation: - */ - if (curthread->slice_usec == -1) { - /* Reset the accumulated time slice period: */ - curthread->slice_usec = 0; - } - - /* Restore errno. */ - errno = curthread->error; - - /* - * If we're 'switching' to the current thread, - * then don't bother with the save/restore - */ - if (curthread == old_thread_run) - goto after_switch; - - /* Restore floating point state. */ - _thread_machdep_restore_float_state(&curthread->_machdep); - - /* Restore the new thread, saving current. */ - _thread_machdep_switch(&curthread->_machdep, - &old_thread_run->_machdep); - - /* - * DANGER WILL ROBINSON - * All stack local variables now contain the values - * they had when this thread was last running. In - * particular, curthread is NOT pointing to the - * current thread. Make it point to the current - * before use. - */ - curthread = _get_curthread(); - - after_switch: - - /* Allow signals again. */ - _queue_signals = 0; - - /* Done with scheduling. */ - _thread_kern_in_sched = 0; - - /* run any installed switch-hooks */ - if ((_sched_switch_hook != NULL) && - (_last_user_thread != curthread)) { - _thread_run_switch_hook(_last_user_thread, - curthread); - } - - /* check for thread cancellation */ - if (((curthread->cancelflags & - PTHREAD_AT_CANCEL_POINT) == 0) && - ((curthread->cancelflags & - PTHREAD_CANCEL_ASYNCHRONOUS) != 0)) - pthread_testcancel(); - - /* dispatch any pending signals if possible */ - if (curthread->sig_defer_count == 0) - _dispatch_signals(scp); - - /* Check if a signal context was saved: */ - if (curthread->sig_saved == 1) { - /* return to signal handler. This code - should be: - _thread_sys_sigreturn(&curthread->saved_sigcontext); - but that doesn't currently work on the - sparc */ - return; - } else { - /* This is the normal way out */ - return; - } - - /* This point should not be reached. */ - PANIC("Thread has returned from sigreturn or switch"); - } - } - - /* There are no more threads, so exit this process: */ - exit(0); -} - -void -_thread_kern_sched_state(enum pthread_state state, const char *fname, - int lineno) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a scheduler signal from interrupting this - * execution and calling the scheduler again. - */ - _thread_kern_in_sched = 1; - - /* - * Prevent the signal handler from fiddling with this thread - * before its state is set and is placed into the proper queue. - */ - _queue_signals = 1; - - /* Change the state of the current thread: */ - curthread->state = state; - curthread->fname = fname; - curthread->lineno = lineno; - - /* Schedule the next thread that is ready: */ - _thread_kern_sched(NULL); -} - -void -_thread_kern_sched_state_unlock(enum pthread_state state, spinlock_t *lock, - const char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Flag the pthread kernel as executing scheduler code - * to avoid a scheduler signal from interrupting this - * execution and calling the scheduler again. - */ - _thread_kern_in_sched = 1; - - /* - * Prevent the signal handler from fiddling with this thread - * before its state is set and it is placed into the proper - * queue(s). - */ - _queue_signals = 1; - - /* Change the state of the current thread: */ - curthread->state = state; - curthread->fname = fname; - curthread->lineno = lineno; - - _SPINUNLOCK(lock); - - /* Schedule the next thread that is ready: */ - _thread_kern_sched(NULL); -} - -void -_thread_kern_poll(int wait_reqd) -{ - int count = 0; - int kern_pipe_added = 0; - nfds_t i, found, nfds = 0; - int timeout_ms = 0; - struct pthread *pthread, *next; - struct timespec ts; - struct timeval tv; - - /* Check if the caller wants to wait: */ - if (wait_reqd == 0) { - timeout_ms = 0; - } - else { - /* Get the current time of day: */ - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, &ts); - - _queue_signals = 1; - pthread = TAILQ_FIRST(&_waitingq); - _queue_signals = 0; - - if ((pthread == NULL) || (pthread->wakeup_time.tv_sec == -1)) { - /* - * Either there are no threads in the waiting queue, - * or there are no threads that can timeout. - */ - timeout_ms = INFTIM; - } - else if (pthread->wakeup_time.tv_sec - ts.tv_sec > 60000) - /* Limit maximum timeout to prevent rollover. */ - timeout_ms = 60000; - else { - /* - * Calculate the time left for the next thread to - * timeout: - */ - timeout_ms = ((pthread->wakeup_time.tv_sec - ts.tv_sec) * - 1000) + (time_t)((pthread->wakeup_time.tv_nsec - ts.tv_nsec) / - 1000000); - /* - * Don't allow negative timeouts: - */ - if (timeout_ms < 0) - timeout_ms = 0; - } - } - - /* Protect the scheduling queues: */ - _queue_signals = 1; - - /* - * Check to see if the signal queue needs to be walked to look - * for threads awoken by a signal while in the scheduler. - */ - if (_sigq_check_reqd != 0) { - /* Reset flag before handling queued signals: */ - _sigq_check_reqd = 0; - _dequeue_signals(); - } - - /* - * Check for a thread that became runnable due to a signal: - */ - if (PTHREAD_PRIOQ_FIRST() != NULL) { - /* - * Since there is at least one runnable thread, - * disable the wait. - */ - timeout_ms = 0; - } - - /* - * Form the poll table: - */ - nfds = 0; - if (timeout_ms != 0) { - /* Add the kernel pipe to the poll table: */ - _thread_pfd_table[nfds].fd = _thread_kern_pipe[0]; - _thread_pfd_table[nfds].events = POLLRDNORM; - _thread_pfd_table[nfds].revents = 0; - nfds++; - kern_pipe_added = 1; - } - - PTHREAD_WAITQ_SETACTIVE(); - for (pthread = TAILQ_FIRST(&_workq); pthread != NULL; pthread = next) { - next = TAILQ_NEXT(pthread, qe); - switch (pthread->state) { - case PS_SPINBLOCK: - /* - * If the lock is available, let the thread run. - */ - if (pthread->data.spinlock->access_lock == - _SPINLOCK_UNLOCKED) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - /* One less thread in a spinblock state: */ - _spinblock_count--; - /* - * Since there is at least one runnable - * thread, disable the wait. - */ - timeout_ms = 0; - } - break; - - /* File descriptor read wait: */ - case PS_FDR_WAIT: - case PS_KEVENT_WAIT: - /* if fd is closing then reschedule this thread */ - if (_thread_fd_table[pthread->data.fd.fd]->state == FD_ENTRY_CLOSING) { - pthread->closing_fd = 1; - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } else { - /* Limit number of polled files to table size: */ - if (nfds < _thread_max_pfdtsize) { - _thread_pfd_table[nfds].events = POLLRDNORM; - _thread_pfd_table[nfds].fd = pthread->data.fd.fd; - nfds++; - } - } - break; - - /* File descriptor write wait: */ - case PS_CONNECT_WAIT: - case PS_FDW_WAIT: - /* if fd is closing then reschedule this thread */ - if (_thread_fd_table[pthread->data.fd.fd]->state == FD_ENTRY_CLOSING) { - pthread->closing_fd = 1; - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } else { - /* Limit number of polled files to table size: */ - if (nfds < _thread_max_pfdtsize) { - _thread_pfd_table[nfds].events = POLLWRNORM; - _thread_pfd_table[nfds].fd = pthread->data.fd.fd; - nfds++; - } - } - break; - - /* File descriptor poll or select wait: */ - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* Limit number of polled files to table size: */ - if (pthread->data.poll_data->nfds + nfds < - _thread_max_pfdtsize) { - for (i = 0; i < pthread->data.poll_data->nfds; i++) { - _thread_pfd_table[nfds + i].fd = - pthread->data.poll_data->fds[i].fd; - _thread_pfd_table[nfds + i].events = - pthread->data.poll_data->fds[i].events; - } - nfds += pthread->data.poll_data->nfds; - } - break; - - /* Other states do not depend on file I/O. */ - default: - break; - } - } - PTHREAD_WAITQ_CLEARACTIVE(); - - /* - * Wait for a file descriptor to be ready for read, write, or - * an exception, or a timeout to occur: - */ - count = _thread_sys_poll(_thread_pfd_table, nfds, timeout_ms); - - if (kern_pipe_added != 0) - /* - * Remove the pthread kernel pipe file descriptor - * from the pollfd table: - */ - nfds = 1; - else - nfds = 0; - - /* - * Check if it is possible that there are bytes in the kernel - * read pipe waiting to be read: - */ - if (count < 0 || ((kern_pipe_added != 0) && - (_thread_pfd_table[0].revents & POLLRDNORM))) { - /* - * If the kernel read pipe was included in the - * count: - */ - if (count > 0) { - /* Decrement the count of file descriptors: */ - count--; - } - - if (_sigq_check_reqd != 0) { - /* Reset flag before handling signals: */ - _sigq_check_reqd = 0; - _dequeue_signals(); - } - } - - /* - * Check if any file descriptors are ready: - */ - if (count > 0) { - /* - * Enter a loop to look for threads waiting on file - * descriptors that are flagged as available by the - * _poll syscall: - */ - PTHREAD_WAITQ_SETACTIVE(); - for (pthread = TAILQ_FIRST(&_workq); pthread != NULL; - pthread = next) { - next = TAILQ_NEXT(pthread, qe); - switch (pthread->state) { - case PS_SPINBLOCK: - /* - * If the lock is available, let the thread run. - */ - if (pthread->data.spinlock->access_lock == - _SPINLOCK_UNLOCKED) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - - /* - * One less thread in a spinblock state: - */ - _spinblock_count--; - } - break; - - /* File descriptor read wait: */ - case PS_FDR_WAIT: - case PS_KEVENT_WAIT: - if ((nfds < _thread_max_pfdtsize) && - (_thread_pfd_table[nfds].revents - & (POLLRDNORM|POLLERR|POLLHUP|POLLNVAL)) - != 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } - nfds++; - break; - - /* File descriptor write wait: */ - case PS_CONNECT_WAIT: - case PS_FDW_WAIT: - if ((nfds < _thread_max_pfdtsize) && - (_thread_pfd_table[nfds].revents - & (POLLWRNORM|POLLERR|POLLHUP|POLLNVAL)) - != 0) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } - nfds++; - break; - - /* File descriptor poll or select wait: */ - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - if (pthread->data.poll_data->nfds + nfds < - _thread_max_pfdtsize) { - /* - * Enter a loop looking for I/O - * readiness: - */ - found = 0; - for (i = 0; i < pthread->data.poll_data->nfds; i++) { - if (_thread_pfd_table[nfds + i].revents != 0) { - pthread->data.poll_data->fds[i].revents = - _thread_pfd_table[nfds + i].revents; - found++; - } - } - - /* Increment before destroying: */ - nfds += pthread->data.poll_data->nfds; - - if (found != 0) { - pthread->data.poll_data->nfds = found; - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - } - } - else - nfds += pthread->data.poll_data->nfds; - break; - - /* Other states do not depend on file I/O. */ - default: - break; - } - } - PTHREAD_WAITQ_CLEARACTIVE(); - } - else if (_spinblock_count != 0) { - /* - * Enter a loop to look for threads waiting on a spinlock - * that is now available. - */ - PTHREAD_WAITQ_SETACTIVE(); - for (pthread = TAILQ_FIRST(&_workq); pthread != NULL; - pthread = next) { - next = TAILQ_NEXT(pthread, qe); - if (pthread->state == PS_SPINBLOCK) { - /* - * If the lock is available, let the thread run. - */ - if (pthread->data.spinlock->access_lock == - _SPINLOCK_UNLOCKED) { - PTHREAD_WAITQ_CLEARACTIVE(); - PTHREAD_WORKQ_REMOVE(pthread); - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - PTHREAD_WAITQ_SETACTIVE(); - - /* - * One less thread in a spinblock state: - */ - _spinblock_count--; - } - } - } - PTHREAD_WAITQ_CLEARACTIVE(); - } - - /* Unprotect the scheduling queues: */ - _queue_signals = 0; - - while (_sigq_check_reqd != 0) { - /* Handle queued signals: */ - _sigq_check_reqd = 0; - - /* Protect the scheduling queues: */ - _queue_signals = 1; - _dequeue_signals(); - _queue_signals = 0; - } -} - -void -_thread_kern_set_timeout(const struct timespec * timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec current_time; - struct timeval tv; - - /* Reset the timeout flag for the running thread: */ - curthread->timeout = 0; - - /* Check if the thread is to wait forever: */ - if (timeout == NULL) { - /* - * Set the wakeup time to something that can be recognised as - * different to an actual time of day: - */ - curthread->wakeup_time.tv_sec = -1; - curthread->wakeup_time.tv_nsec = -1; - } - /* Check if no waiting is required: */ - else if (timeout->tv_sec == 0 && timeout->tv_nsec == 0) { - /* Set the wake up time to 'immediately': */ - curthread->wakeup_time.tv_sec = 0; - curthread->wakeup_time.tv_nsec = 0; - } else { - gettimeofday((struct timeval *) &_sched_tod, NULL); - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time); - timespecadd(¤t_time, timeout, &curthread->wakeup_time); - } -} - -/* - * Function registered with dlctl to lock/unlock the kernel for - * threade safe dlopen calls. - * which == 0: defer signals (stops scheduler) - * which != 0: undefer signals and process any queued sigs - */ -void -_thread_kern_lock(int which) -{ - if (which == 0) - _thread_kern_sig_defer(); - else - _thread_kern_sig_undefer(); -} - - -void -_thread_kern_sig_defer(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Allow signal deferral to be recursive. */ - curthread->sig_defer_count++; -} - -void -_thread_kern_sig_undefer(void) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Perform checks to yield only if we are about to undefer - * signals. - */ - if (curthread->sig_defer_count > 1) { - /* Decrement the signal deferral count. */ - curthread->sig_defer_count--; - } - else if (curthread->sig_defer_count == 1) { - /* Reenable signals: */ - curthread->sig_defer_count = 0; - - /* - * Check if there are queued signals: - */ - if (_sigq_check_reqd != 0) - _thread_kern_sched(NULL); - - /* - * Check for asynchronous cancellation before delivering any - * pending signals: - */ - if (((curthread->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0) && - ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)) - pthread_testcancel(); - - /* - * If there are pending signals or this thread has - * to yield the CPU, call the kernel scheduler: - * - * XXX - Come back and revisit the pending signal problem - */ - if ((curthread->yield_on_sig_undefer != 0) || - curthread->sigpend != 0) { - curthread->yield_on_sig_undefer = 0; - _thread_kern_sched(NULL); - } - } -} - -void -_dequeue_signals(void) -{ - char bufr[128]; - int i; - ssize_t num; - - /* - * Enter a loop to read and handle queued signals from the - * pthread kernel pipe: - */ - while (((num = _thread_sys_read(_thread_kern_pipe[0], bufr, - sizeof(bufr))) > 0) || (num == -1 && errno == EINTR)) { - /* - * The buffer read contains one byte per signal and - * each byte is the signal number. - */ - for (i = 0; i < num; i++) { - if ((int) bufr[i] != _SCHED_SIGNAL) - _thread_sig_handle((int) bufr[i], NULL); - } - } - if ((num < 0) && (errno != EAGAIN)) { - /* - * The only error we should expect is if there is - * no data to read. - */ - PANIC("Unable to read from thread kernel pipe"); - } -} - -inline void -_thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in) -{ - pthread_t tid_out = thread_out; - pthread_t tid_in = thread_in; - - if ((tid_out != NULL) && - (tid_out->flags & PTHREAD_FLAGS_PRIVATE) != 0) - tid_out = NULL; - if ((tid_in != NULL) && - (tid_in->flags & PTHREAD_FLAGS_PRIVATE) != 0) - tid_in = NULL; - - if ((_sched_switch_hook != NULL) && (tid_out != tid_in)) { - /* Run the scheduler switch hook: */ - _sched_switch_hook(tid_out, tid_in); - } -} - -struct pthread * -_get_curthread(void) -{ - if (_thread_initial == NULL) - _thread_init(); - - return (_thread_run); -} - -void -_set_curthread(struct pthread *newthread) -{ - _thread_run = newthread; -} -#endif diff --git a/lib/libpthread/uthread/uthread_kevent.c b/lib/libpthread/uthread/uthread_kevent.c deleted file mode 100644 index 7530e5e4184..00000000000 --- a/lib/libpthread/uthread/uthread_kevent.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $OpenBSD: uthread_kevent.c,v 1.6 2011/09/13 23:56:00 fgsch Exp $ */ - -/*- - * Copyright (c) 2000 Jonathan Lemon <jlemon@flugsvamp.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_kevent.c,v 1.6 2001/12/08 00:53:37 sobomax Exp $ - */ - -#include <unistd.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/event.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -kevent(int kq, const struct kevent *changelist, int nchanges, - struct kevent *eventlist, int nevents, const struct timespec *timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec nullts = { 0, 0 }; - int rc; - - /* Set the wake up time */ - _thread_kern_set_timeout(timeout); - - rc = _thread_sys_kevent(kq, changelist, nchanges, - eventlist, nevents, &nullts); - if (rc == 0 && eventlist != NULL && nevents > 0 && (timeout == NULL || - timeout->tv_sec != 0 || timeout->tv_nsec != 0)) { - /* Save the socket file descriptor: */ - curthread->data.fd.fd = kq; - curthread->data.fd.fname = __FILE__; - curthread->data.fd.branch = __LINE__; - - do { - /* Reset the interrupted and timeout flags: */ - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - - _thread_kern_sched_state(PS_KEVENT_WAIT, - __FILE__, __LINE__); - - if (curthread->interrupted) { - errno = EINTR; - rc = -1; - break; - } else if (curthread->closing_fd) { - errno = EBADF; - rc = -1; - break; - } - rc = _thread_sys_kevent(kq, NULL, 0, - eventlist, nevents, &nullts); - } while (rc == 0 && curthread->timeout == 0); - } - return (rc); -} -#endif diff --git a/lib/libpthread/uthread/uthread_kill.c b/lib/libpthread/uthread/uthread_kill.c deleted file mode 100644 index 8b6c6e2456f..00000000000 --- a/lib/libpthread/uthread/uthread_kill.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD: uthread_kill.c,v 1.12 2007/01/28 16:47:41 kettenis Exp $ */ -/* PUBLIC_DOMAIN <marc@snafu.org> */ - -#include <errno.h> -#include <signal.h> -#include <string.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> - -#include "pthread_private.h" - -/* - * Fake up a minimal siginfo_t for the given signal unless one is already - * pending. The signal number is assumed to be valid. - */ -void -_thread_kill_siginfo(int sig) -{ - struct sigstatus *ss = &_thread_sigq[sig - 1]; - - _SPINLOCK(&ss->lock); - if (ss->pending == 0) { - ss->pending = 1; - memset(&ss->siginfo, 0, sizeof ss->siginfo); - ss->siginfo.si_signo = sig; - ss->siginfo.si_code = SI_USER; - ss->siginfo.si_errno = errno; - ss->siginfo.si_pid = getpid(); - } - _SPINUNLOCK(&ss->lock); -} - -/* - * Validate the signal number and thread. If valid process the signal. - */ -int -pthread_kill(pthread_t pthread, int sig) -{ - int ret; - - if (sig >= 0 && sig < NSIG) { - ret = _find_thread(pthread); - if (ret == 0 && sig != 0) { - if (_thread_sigact[sig - 1].sa_handler != SIG_IGN) { - _thread_kern_sig_defer(); - if (pthread->state == PS_SIGWAIT && - sigismember(pthread->data.sigwait, sig)) { - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - pthread->signo = sig; - } else { - _thread_kill_siginfo(sig); - _thread_signal(pthread,sig); - } - _thread_kern_sig_undefer(); - } - } - } else - ret = EINVAL; - - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_kqueue.c b/lib/libpthread/uthread/uthread_kqueue.c deleted file mode 100644 index e9c751b9807..00000000000 --- a/lib/libpthread/uthread/uthread_kqueue.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_kqueue.c,v 1.3 2006/09/26 14:18:28 kurt Exp $ */ - -/* - * Copyright (c) 2003 Mark Peek <mp@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_kqueue.c,v 1.1 2003/07/25 17:02:33 mp Exp $ - */ - -#include <sys/types.h> -#include <sys/event.h> -#include <fcntl.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -kqueue(void) -{ - int fd; - - /* Create a kqueue: */ - if ((fd = _thread_sys_kqueue()) < 0) { - /* Error creating socket. */ - - /* Initialise the entry in the file descriptor table: */ - } else if (_thread_fd_table_init(fd, FD_INIT_NEW, NULL) != 0) { - _thread_sys_close(fd); - fd = -1; - } - return (fd); -} -#endif diff --git a/lib/libpthread/uthread/uthread_listen.c b/lib/libpthread/uthread/uthread_listen.c deleted file mode 100644 index 0f9b312b3bb..00000000000 --- a/lib/libpthread/uthread/uthread_listen.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: uthread_listen.c,v 1.3 1999/11/25 07:01:38 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_listen.c,v 1.5 1999/08/28 00:03:38 peter Exp $ - */ -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -listen(int fd, int backlog) -{ - int ret; - - if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { - ret = _thread_sys_listen(fd, backlog); - _FD_UNLOCK(fd, FD_RDWR); - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_lseek.c b/lib/libpthread/uthread/uthread_lseek.c deleted file mode 100644 index 152d707938b..00000000000 --- a/lib/libpthread/uthread/uthread_lseek.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $OpenBSD: uthread_lseek.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */ -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <unistd.h> -#include <sys/syscall.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -off_t __syscall(quad_t, ...); - -/* - * This function provides 64-bit offset padding that - * is not supplied by GCC 1.X but is supplied by GCC 2.X. - */ -off_t -lseek(int fd, off_t offset, int whence) -{ - off_t retval; - - if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { - retval = -1; - } else { - retval = __syscall((quad_t)SYS_lseek, fd, 0, offset, whence); - _FD_UNLOCK(fd, FD_RDWR); - } - return retval; -} -#endif diff --git a/lib/libpthread/uthread/uthread_main_np.c b/lib/libpthread/uthread/uthread_main_np.c deleted file mode 100644 index 84dd1674a18..00000000000 --- a/lib/libpthread/uthread/uthread_main_np.c +++ /dev/null @@ -1,48 +0,0 @@ -/* $OpenBSD: uthread_main_np.c,v 1.1 2001/08/17 22:12:31 pvalchev Exp $ */ -/* - * Copyright (c) 2001 Alfred Perlstein - * Author: Alfred Perlstein <alfred@FreeBSD.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_main_np.c,v 1.2 2001/04/03 22:25:39 iedowse Exp $ - */ - -#ifdef _THREAD_SAFE -#include <pthread.h> -#include <pthread_np.h> -#include "pthread_private.h" - -/* - * Provide the equivalent to Solaris thr_main() function - */ -int -pthread_main_np() -{ - - if (!_thread_initial) - return (-1); - else - return (pthread_equal(pthread_self(), _thread_initial) ? 1 : 0); -} -#endif diff --git a/lib/libpthread/uthread/uthread_mattr_init.c b/lib/libpthread/uthread/uthread_mattr_init.c deleted file mode 100644 index 172ddb45b35..00000000000 --- a/lib/libpthread/uthread/uthread_mattr_init.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_mattr_init.c,v 1.4 1999/11/25 07:01:38 d Exp $ */ -/* - * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_mattr_init.c,v 1.5 1999/08/28 00:03:39 peter Exp $ - */ -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_mutexattr_init(pthread_mutexattr_t *attr) -{ - int ret; - pthread_mutexattr_t pattr; - - if ((pattr = (pthread_mutexattr_t) - malloc(sizeof(struct pthread_mutex_attr))) == NULL) { - ret = ENOMEM; - } else { - memcpy(pattr, &pthread_mutexattr_default, - sizeof(struct pthread_mutex_attr)); - *attr = pattr; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_mattr_kind_np.c b/lib/libpthread/uthread/uthread_mattr_kind_np.c deleted file mode 100644 index d18bad1ec4a..00000000000 --- a/lib/libpthread/uthread/uthread_mattr_kind_np.c +++ /dev/null @@ -1,92 +0,0 @@ -/* $OpenBSD: uthread_mattr_kind_np.c,v 1.8 2005/10/31 20:48:31 brad Exp $ */ -/* - * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_mattr_kind_np.c,v 1.4 1999/08/28 00:03:39 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind) -{ - int ret; - if (attr == NULL || *attr == NULL) { - ret = EINVAL; - } else { - (*attr)->m_type = kind; - ret = 0; - } - return(ret); -} - -int -pthread_mutexattr_getkind_np(pthread_mutexattr_t attr) -{ - int ret; - if (attr == NULL) { - ret = EINVAL; - } else { - ret = attr->m_type; - } - return(ret); -} - -int -pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) -{ - int ret; - if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) { - ret = EINVAL; - } else { - (*attr)->m_type = type; - ret = 0; - } - return(ret); -} - -int -pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type) -{ - int ret; - - if (attr == NULL || *attr == NULL || (*attr)->m_type >= - PTHREAD_MUTEX_TYPE_MAX) { - ret = EINVAL; - } else { - *type = (*attr)->m_type; - ret = 0; - } - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_msync.c b/lib/libpthread/uthread/uthread_msync.c deleted file mode 100644 index 2cbbe9c6f47..00000000000 --- a/lib/libpthread/uthread/uthread_msync.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * David Leonard <d@openbsd.org>, 1999. Public Domain. - * - * $OpenBSD: uthread_msync.c,v 1.4 2004/04/10 06:48:03 brad Exp $ - */ - -#include <sys/types.h> -#include <sys/mman.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -msync(void *addr, size_t len, int flags) -{ - int ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - ret = _thread_sys_msync(addr, len, flags); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_multi_np.c b/lib/libpthread/uthread/uthread_multi_np.c deleted file mode 100644 index 88c6cbbfddf..00000000000 --- a/lib/libpthread/uthread/uthread_multi_np.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $OpenBSD: uthread_multi_np.c,v 1.3 1999/11/25 07:01:38 d Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_multi_np.c,v 1.3 1999/08/28 00:03:40 peter Exp $ - */ -#include <string.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int pthread_multi_np() -{ - /* Return to multi-threaded scheduling mode: */ - _thread_single = NULL; - return(0); -} -#endif diff --git a/lib/libpthread/uthread/uthread_mutex.c b/lib/libpthread/uthread/uthread_mutex.c deleted file mode 100644 index a2f0e97387a..00000000000 --- a/lib/libpthread/uthread/uthread_mutex.c +++ /dev/null @@ -1,1474 +0,0 @@ -/* $OpenBSD: uthread_mutex.c,v 1.22 2009/10/28 13:49:10 kurt Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_mutex.c,v 1.16 1999/08/28 00:03:40 peter Exp $ - */ -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <sys/param.h> -#include <sys/queue.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -#if defined(_PTHREADS_INVARIANTS) -#define _MUTEX_INIT_LINK(m) do { \ - (m)->m_qe.tqe_prev = NULL; \ - (m)->m_qe.tqe_next = NULL; \ -} while (0) -#define _MUTEX_REMOVE_IF_OWNED(m) do { \ - if ((m)->m_qe.tqe_prev != NULL) \ - TAILQ_REMOVE(&(m)->m_owner->mutexq, \ - (m), m_qe); \ -} while (0) -#define _MUTEX_ASSERT_IS_OWNED(m) do { \ - if ((m)->m_qe.tqe_prev == NULL) \ - PANIC("mutex is not on list"); \ -} while (0) -#define _MUTEX_ASSERT_NOT_OWNED(m) do { \ - if (((m)->m_qe.tqe_prev != NULL) || \ - ((m)->m_qe.tqe_next != NULL)) \ - PANIC("mutex is on list"); \ -} while (0) -#else -#define _MUTEX_INIT_LINK(m) -#define _MUTEX_REMOVE_IF_OWNED(m) -#define _MUTEX_ASSERT_IS_OWNED(m) -#define _MUTEX_ASSERT_NOT_OWNED(m) -#endif - -/* - * Prototypes - */ -static inline int mutex_self_trylock(pthread_mutex_t); -static inline int mutex_self_lock(pthread_mutex_t); -static inline int mutex_unlock_common(pthread_mutex_t *, int); -static void mutex_priority_adjust(pthread_mutex_t); -static void mutex_rescan_owned (pthread_t, pthread_mutex_t); -static inline pthread_t mutex_queue_deq(pthread_mutex_t); -static inline void mutex_queue_remove(pthread_mutex_t, pthread_t); -static inline void mutex_queue_enq(pthread_mutex_t, pthread_t); - - -static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER; - -/* Reinitialize a mutex to defaults. */ -int -_mutex_reinit(pthread_mutex_t * mutex) -{ - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - else if (*mutex == NULL) - ret = pthread_mutex_init(mutex, NULL); - else { - /* - * Initialize the mutex structure: - */ - _MUTEX_REMOVE_IF_OWNED(*mutex); - _MUTEX_INIT_LINK(*mutex); - (*mutex)->m_type = PTHREAD_MUTEX_DEFAULT; - (*mutex)->m_protocol = PTHREAD_PRIO_NONE; - TAILQ_INIT(&(*mutex)->m_queue); - (*mutex)->m_owner = NULL; - (*mutex)->m_data.m_count = 0; - (*mutex)->m_flags &= MUTEX_FLAGS_PRIVATE; - (*mutex)->m_flags |= MUTEX_FLAGS_INITED; - (*mutex)->m_refcount = 0; - (*mutex)->m_prio = 0; - (*mutex)->m_saved_prio = 0; - _SPINLOCK_INIT(&(*mutex)->lock); - } - return (ret); -} - -int -pthread_mutex_init(pthread_mutex_t * mutex, - const pthread_mutexattr_t * mutex_attr) -{ - pthread_mutex_t pmutex; - enum pthread_mutextype type = 0; - int protocol = 0; - int ceiling = 0; - long flags = 0; - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - - /* Check if default mutex attributes: */ - else if (mutex_attr == NULL || *mutex_attr == NULL) { - /* Default to a (error checking) POSIX mutex: */ - type = PTHREAD_MUTEX_ERRORCHECK; - protocol = PTHREAD_PRIO_NONE; - ceiling = PTHREAD_MAX_PRIORITY; - flags = 0; - } - - /* Check mutex type: */ - else if (((*mutex_attr)->m_type < PTHREAD_MUTEX_ERRORCHECK) || - ((*mutex_attr)->m_type >= PTHREAD_MUTEX_TYPE_MAX)) - /* Return an invalid argument error: */ - ret = EINVAL; - - /* Check mutex protocol: */ - else if (((*mutex_attr)->m_protocol < PTHREAD_PRIO_NONE) || - ((*mutex_attr)->m_protocol > PTHREAD_PRIO_PROTECT)) - /* Return an invalid argument error: */ - ret = EINVAL; - - else { - /* Use the requested mutex type and protocol: */ - type = (*mutex_attr)->m_type; - protocol = (*mutex_attr)->m_protocol; - ceiling = (*mutex_attr)->m_ceiling; - flags = (*mutex_attr)->m_flags; - } - - /* Check no errors so far: */ - if (ret == 0) { - if ((pmutex = (pthread_mutex_t) - malloc(sizeof(struct pthread_mutex))) == NULL) - ret = ENOMEM; - else { - /* Set the mutex flags: */ - pmutex->m_flags = flags; - - /* Process according to mutex type: */ - switch (type) { - /* case PTHREAD_MUTEX_DEFAULT: */ - case PTHREAD_MUTEX_ERRORCHECK: - case PTHREAD_MUTEX_NORMAL: - /* Nothing to do here. */ - break; - - /* Single UNIX Spec 2 recursive mutex: */ - case PTHREAD_MUTEX_RECURSIVE: - /* Reset the mutex count: */ - pmutex->m_data.m_count = 0; - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - if (ret == 0) { - /* Initialise the rest of the mutex: */ - TAILQ_INIT(&pmutex->m_queue); - pmutex->m_flags |= MUTEX_FLAGS_INITED; - pmutex->m_owner = NULL; - pmutex->m_type = type; - pmutex->m_protocol = protocol; - pmutex->m_refcount = 0; - if (protocol == PTHREAD_PRIO_PROTECT) - pmutex->m_prio = ceiling; - else - pmutex->m_prio = 0; - pmutex->m_saved_prio = 0; - _MUTEX_INIT_LINK(pmutex); - _SPINLOCK_INIT(&pmutex->lock); - *mutex = pmutex; - } else { - free((void *)pmutex); - *mutex = NULL; - } - } - } - /* Return the completion status: */ - return(ret); -} - -int -pthread_mutex_destroy(pthread_mutex_t * mutex) -{ - int ret = 0; - - if (mutex == NULL || *mutex == NULL) - ret = EINVAL; - else { - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * Check to see if this mutex is in use: - */ - if (((*mutex)->m_owner != NULL) || - (TAILQ_FIRST(&(*mutex)->m_queue) != NULL) || - ((*mutex)->m_refcount != 0)) { - ret = EBUSY; - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - } - else { - /* - * Free the memory allocated for the mutex - * structure: - */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - free((void *)*mutex); - - /* - * Leave the caller's pointer NULL now that - * the mutex has been destroyed: - */ - *mutex = NULL; - } - } - - /* Return the completion status: */ - return (ret); -} - -static int -init_static(pthread_mutex_t *mutex) -{ - int ret; - - _SPINLOCK(&static_init_lock); - - if (*mutex == NULL) - ret = pthread_mutex_init(mutex, NULL); - else - ret = 0; - - _SPINUNLOCK(&static_init_lock); - - return(ret); -} - -static int -mutex_trylock_common(pthread_mutex_t *mutex) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL), - "Uninitialized mutex in mutex_trylock_common"); - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * If the mutex was statically allocated, properly - * initialize the tail queue. - */ - if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) { - TAILQ_INIT(&(*mutex)->m_queue); - _MUTEX_INIT_LINK(*mutex); - (*mutex)->m_flags |= MUTEX_FLAGS_INITED; - } - - /* Process according to mutex type: */ - switch ((*mutex)->m_protocol) { - /* Default POSIX mutex: */ - case PTHREAD_PRIO_NONE: - /* Check if this mutex is not locked: */ - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for the running thread: */ - (*mutex)->m_owner = curthread; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(*mutex); - else - /* Return a busy error: */ - ret = EBUSY; - break; - - /* POSIX priority inheritence mutex: */ - case PTHREAD_PRIO_INHERIT: - /* Check if this mutex is not locked: */ - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for the running thread: */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The mutex takes on the attributes of the - * running thread when there are no waiters. - */ - (*mutex)->m_prio = curthread->active_priority; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(*mutex); - else - /* Return a busy error: */ - ret = EBUSY; - break; - - /* POSIX priority protection mutex: */ - case PTHREAD_PRIO_PROTECT: - /* Check for a priority ceiling violation: */ - if (curthread->active_priority > (*mutex)->m_prio) - ret = EINVAL; - - /* Check if this mutex is not locked: */ - else if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for the running thread: */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The running thread inherits the ceiling - * priority of the mutex and executes at that - * priority. - */ - curthread->active_priority = (*mutex)->m_prio; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - curthread->inherited_priority = - (*mutex)->m_prio; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(*mutex); - else - /* Return a busy error: */ - ret = EBUSY; - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - - /* Return the completion status: */ - return (ret); -} - -int -pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization: - */ - else if ((*mutex != NULL) || (ret = init_static(mutex)) == 0) - ret = mutex_trylock_common(mutex); - - return (ret); -} - -static int -mutex_lock_common(pthread_mutex_t * mutex) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL), - "Uninitialized mutex in mutex_lock_common"); - - /* Reset the interrupted flag: */ - curthread->interrupted = 0; - - /* - * Enter a loop waiting to become the mutex owner. We need a - * loop in case the waiting thread is interrupted by a signal - * to execute a signal handler. It is not (currently) possible - * to remain in the waiting queue while running a handler. - * Instead, the thread is interrupted and backed out of the - * waiting queue prior to executing the signal handler. - */ - do { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * If the mutex was statically allocated, properly - * initialize the tail queue. - */ - if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) { - TAILQ_INIT(&(*mutex)->m_queue); - (*mutex)->m_flags |= MUTEX_FLAGS_INITED; - _MUTEX_INIT_LINK(*mutex); - } - - /* Process according to mutex type: */ - switch ((*mutex)->m_protocol) { - /* Default POSIX mutex: */ - case PTHREAD_PRIO_NONE: - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for this thread: */ - (*mutex)->m_owner = curthread; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_lock(*mutex); - else { - /* - * Join the queue of threads waiting to lock - * the mutex: - */ - mutex_queue_enq(*mutex, curthread); - - /* - * Keep a pointer to the mutex this thread - * is waiting on: - */ - curthread->data.mutex = *mutex; - - /* - * Unlock the mutex structure and schedule the - * next thread: - */ - _thread_kern_sched_state_unlock(PS_MUTEX_WAIT, - &(*mutex)->lock, __FILE__, __LINE__); - - /* Lock the mutex structure again: */ - _SPINLOCK(&(*mutex)->lock); - } - break; - - /* POSIX priority inheritence mutex: */ - case PTHREAD_PRIO_INHERIT: - /* Check if this mutex is not locked: */ - if ((*mutex)->m_owner == NULL) { - /* Lock the mutex for this thread: */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The mutex takes on attributes of the - * running thread when there are no waiters. - */ - (*mutex)->m_prio = curthread->active_priority; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - curthread->inherited_priority = - (*mutex)->m_prio; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_lock(*mutex); - else { - /* - * Join the queue of threads waiting to lock - * the mutex: - */ - mutex_queue_enq(*mutex, curthread); - - /* - * Keep a pointer to the mutex this thread - * is waiting on: - */ - curthread->data.mutex = *mutex; - - if (curthread->active_priority > - (*mutex)->m_prio) - /* Adjust priorities: */ - mutex_priority_adjust(*mutex); - - /* - * Unlock the mutex structure and schedule the - * next thread: - */ - _thread_kern_sched_state_unlock(PS_MUTEX_WAIT, - &(*mutex)->lock, __FILE__, __LINE__); - - /* Lock the mutex structure again: */ - _SPINLOCK(&(*mutex)->lock); - } - break; - - /* POSIX priority protection mutex: */ - case PTHREAD_PRIO_PROTECT: - /* Check for a priority ceiling violation: */ - if (curthread->active_priority > (*mutex)->m_prio) - ret = EINVAL; - - /* Check if this mutex is not locked: */ - else if ((*mutex)->m_owner == NULL) { - /* - * Lock the mutex for the running - * thread: - */ - (*mutex)->m_owner = curthread; - - /* Track number of priority mutexes owned: */ - curthread->priority_mutex_count++; - - /* - * The running thread inherits the ceiling - * priority of the mutex and executes at that - * priority: - */ - curthread->active_priority = (*mutex)->m_prio; - (*mutex)->m_saved_prio = - curthread->inherited_priority; - curthread->inherited_priority = - (*mutex)->m_prio; - - /* Add to the list of owned mutexes: */ - _MUTEX_ASSERT_NOT_OWNED(*mutex); - TAILQ_INSERT_TAIL(&curthread->mutexq, - (*mutex), m_qe); - } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_lock(*mutex); - else { - /* - * Join the queue of threads waiting to lock - * the mutex: - */ - mutex_queue_enq(*mutex, curthread); - - /* - * Keep a pointer to the mutex this thread - * is waiting on: - */ - curthread->data.mutex = *mutex; - - /* Clear any previous error: */ - curthread->error = 0; - - /* - * Unlock the mutex structure and schedule the - * next thread: - */ - _thread_kern_sched_state_unlock(PS_MUTEX_WAIT, - &(*mutex)->lock, __FILE__, __LINE__); - - /* Lock the mutex structure again: */ - _SPINLOCK(&(*mutex)->lock); - - /* - * The threads priority may have changed while - * waiting for the mutex causing a ceiling - * violation. - */ - ret = curthread->error; - curthread->error = 0; - } - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - - /* - * Check to see if this thread was interrupted and - * is still in the mutex queue of waiting threads: - */ - if (curthread->interrupted != 0) - mutex_queue_remove(*mutex, curthread); - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } while (((*mutex)->m_owner != curthread) && (ret == 0) && - (curthread->interrupted == 0)); - - if (curthread->interrupted != 0 && - curthread->continuation != NULL) - curthread->continuation(curthread); - - /* Return the completion status: */ - return (ret); -} - -int -pthread_mutex_lock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (_thread_initial == NULL) - _thread_init(); - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization. Note: _thread_mutex_lock() in libc requires - * pthread_mutex_lock() to perform the mutex init when *mutex - * is NULL. - */ - else if ((*mutex != NULL) || ((ret = init_static(mutex)) == 0)) - ret = mutex_lock_common(mutex); - - return (ret); -} - -int -pthread_mutex_unlock(pthread_mutex_t * mutex) -{ - return (mutex_unlock_common(mutex, /* add reference */ 0)); -} - -int -_mutex_cv_unlock(pthread_mutex_t * mutex) -{ - return (mutex_unlock_common(mutex, /* add reference */ 1)); -} - -int -_mutex_cv_lock(pthread_mutex_t * mutex) -{ - int ret; - if ((ret = pthread_mutex_lock(mutex)) == 0) - (*mutex)->m_refcount--; - return (ret); -} - -static inline int -mutex_self_trylock(pthread_mutex_t mutex) -{ - int ret = 0; - - switch (mutex->m_type) { - - /* case PTHREAD_MUTEX_DEFAULT: */ - case PTHREAD_MUTEX_ERRORCHECK: - case PTHREAD_MUTEX_NORMAL: - /* - * POSIX specifies that mutexes should return EDEADLK if a - * recursive lock is detected. - */ - ret = EBUSY; - break; - - case PTHREAD_MUTEX_RECURSIVE: - /* Increment the lock count: */ - mutex->m_data.m_count++; - break; - - default: - /* Trap invalid mutex types; */ - ret = EINVAL; - } - - return(ret); -} - -static inline int -mutex_self_lock(pthread_mutex_t mutex) -{ - int ret = 0; - - switch (mutex->m_type) { - /* case PTHREAD_MUTEX_DEFAULT: */ - case PTHREAD_MUTEX_ERRORCHECK: - /* - * POSIX specifies that mutexes should return EDEADLK if a - * recursive lock is detected. - */ - ret = EDEADLK; - break; - - case PTHREAD_MUTEX_NORMAL: - /* - * What SS2 define as a 'normal' mutex. Intentionally - * deadlock on attempts to get a lock you already own. - */ - _thread_kern_sched_state_unlock(PS_DEADLOCK, - &mutex->lock, __FILE__, __LINE__); - break; - - case PTHREAD_MUTEX_RECURSIVE: - /* Increment the lock count: */ - mutex->m_data.m_count++; - break; - - default: - /* Trap invalid mutex types; */ - ret = EINVAL; - } - - return(ret); -} - -static inline int -mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - if (mutex == NULL || *mutex == NULL) { - ret = EINVAL; - } else { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - /* Lock the mutex structure: */ - _SPINLOCK(&(*mutex)->lock); - - /* Process according to mutex type: */ - switch ((*mutex)->m_protocol) { - /* Default POSIX mutex: */ - case PTHREAD_PRIO_NONE: - /* - * Check if the running thread is not the owner of the - * mutex: - */ - if ((*mutex)->m_owner != curthread) { - /* - * Return an invalid argument error for no - * owner and a permission error otherwise: - */ - ret = (*mutex)->m_owner == NULL ? EINVAL : EPERM; - } - else if (((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) && - ((*mutex)->m_data.m_count > 0)) { - /* Decrement the count: */ - (*mutex)->m_data.m_count--; - } else { - /* - * Clear the count in case this is recursive - * mutex. - */ - (*mutex)->m_data.m_count = 0; - - /* Remove the mutex from the threads queue. */ - _MUTEX_ASSERT_IS_OWNED(*mutex); - TAILQ_REMOVE(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - _MUTEX_INIT_LINK(*mutex); - - /* - * Get the next thread from the queue of - * threads waiting on the mutex: - */ - if (((*mutex)->m_owner = - mutex_queue_deq(*mutex)) != NULL) { - /* - * Unless the new owner of the mutex is - * currently suspended, allow the owner - * to run. If the thread is suspended, - * make a note that the thread isn't in - * a wait queue any more. - */ - if (((*mutex)->m_owner->state != - PS_SUSPENDED)) { - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - } else { - (*mutex)->m_owner->suspended = - SUSP_NOWAIT; - } - - /* - * Add the mutex to the threads list of - * owned mutexes: - */ - TAILQ_INSERT_TAIL(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - - /* - * The owner is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - } - } - break; - - /* POSIX priority inheritence mutex: */ - case PTHREAD_PRIO_INHERIT: - /* - * Check if the running thread is not the owner of the - * mutex: - */ - if ((*mutex)->m_owner != curthread) { - /* - * Return an invalid argument error for no - * owner and a permission error otherwise: - */ - ret = (*mutex)->m_owner == NULL ? EINVAL : EPERM; - } - else if (((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) && - ((*mutex)->m_data.m_count > 0)) { - /* Decrement the count: */ - (*mutex)->m_data.m_count--; - } else { - /* - * Clear the count in case this is recursive - * mutex. - */ - (*mutex)->m_data.m_count = 0; - - /* - * Restore the threads inherited priority and - * recompute the active priority (being careful - * not to override changes in the threads base - * priority subsequent to locking the mutex). - */ - curthread->inherited_priority = - (*mutex)->m_saved_prio; - curthread->active_priority = - MAX(curthread->inherited_priority, - curthread->base_priority); - - /* - * This thread now owns one less priority mutex. - */ - curthread->priority_mutex_count--; - - /* Remove the mutex from the threads queue. */ - _MUTEX_ASSERT_IS_OWNED(*mutex); - TAILQ_REMOVE(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - _MUTEX_INIT_LINK(*mutex); - - /* - * Get the next thread from the queue of threads - * waiting on the mutex: - */ - if (((*mutex)->m_owner = - mutex_queue_deq(*mutex)) == NULL) - /* This mutex has no priority. */ - (*mutex)->m_prio = 0; - else { - /* - * Track number of priority mutexes owned: - */ - (*mutex)->m_owner->priority_mutex_count++; - - /* - * Add the mutex to the threads list - * of owned mutexes: - */ - TAILQ_INSERT_TAIL(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - - /* - * The owner is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - - /* - * Set the priority of the mutex. Since - * our waiting threads are in descending - * priority order, the priority of the - * mutex becomes the active priority of - * the thread we just dequeued. - */ - (*mutex)->m_prio = - (*mutex)->m_owner->active_priority; - - /* - * Save the owning threads inherited - * priority: - */ - (*mutex)->m_saved_prio = - (*mutex)->m_owner->inherited_priority; - - /* - * The owning threads inherited priority - * now becomes his active priority (the - * priority of the mutex). - */ - (*mutex)->m_owner->inherited_priority = - (*mutex)->m_prio; - - /* - * Unless the new owner of the mutex is - * currently suspended, allow the owner - * to run. If the thread is suspended, - * make a note that the thread isn't in - * a wait queue any more. - */ - if (((*mutex)->m_owner->state != - PS_SUSPENDED)) { - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - } else { - (*mutex)->m_owner->suspended = - SUSP_NOWAIT; - } - } - } - break; - - /* POSIX priority ceiling mutex: */ - case PTHREAD_PRIO_PROTECT: - /* - * Check if the running thread is not the owner of the - * mutex: - */ - if ((*mutex)->m_owner != curthread) { - /* - * Return an invalid argument error for no - * owner and a permission error otherwise: - */ - ret = (*mutex)->m_owner == NULL ? EINVAL : EPERM; - } - else if (((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) && - ((*mutex)->m_data.m_count > 0)) { - /* Decrement the count: */ - (*mutex)->m_data.m_count--; - } else { - /* - * Clear the count in case this is recursive - * mutex. - */ - (*mutex)->m_data.m_count = 0; - - /* - * Restore the threads inherited priority and - * recompute the active priority (being careful - * not to override changes in the threads base - * priority subsequent to locking the mutex). - */ - curthread->inherited_priority = - (*mutex)->m_saved_prio; - curthread->active_priority = - MAX(curthread->inherited_priority, - curthread->base_priority); - - /* - * This thread now owns one less priority mutex. - */ - curthread->priority_mutex_count--; - - /* Remove the mutex from the threads queue. */ - _MUTEX_ASSERT_IS_OWNED(*mutex); - TAILQ_REMOVE(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - _MUTEX_INIT_LINK(*mutex); - - /* - * Enter a loop to find a waiting thread whose - * active priority will not cause a ceiling - * violation: - */ - while ((((*mutex)->m_owner = - mutex_queue_deq(*mutex)) != NULL) && - ((*mutex)->m_owner->active_priority > - (*mutex)->m_prio)) { - /* - * Either the mutex ceiling priority - * been lowered and/or this threads - * priority has been raised subsequent - * to this thread being queued on the - * waiting list. - */ - (*mutex)->m_owner->error = EINVAL; - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - /* - * The thread is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - } - - /* Check for a new owner: */ - if ((*mutex)->m_owner != NULL) { - /* - * Track number of priority mutexes owned: - */ - (*mutex)->m_owner->priority_mutex_count++; - - /* - * Add the mutex to the threads list - * of owned mutexes: - */ - TAILQ_INSERT_TAIL(&(*mutex)->m_owner->mutexq, - (*mutex), m_qe); - - /* - * The owner is no longer waiting for - * this mutex: - */ - (*mutex)->m_owner->data.mutex = NULL; - - /* - * Save the owning threads inherited - * priority: - */ - (*mutex)->m_saved_prio = - (*mutex)->m_owner->inherited_priority; - - /* - * The owning thread inherits the - * ceiling priority of the mutex and - * executes at that priority: - */ - (*mutex)->m_owner->inherited_priority = - (*mutex)->m_prio; - (*mutex)->m_owner->active_priority = - (*mutex)->m_prio; - - /* - * Unless the new owner of the mutex is - * currently suspended, allow the owner - * to run. If the thread is suspended, - * make a note that the thread isn't in - * a wait queue any more. - */ - if (((*mutex)->m_owner->state != - PS_SUSPENDED)) { - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); - } else { - (*mutex)->m_owner->suspended = - SUSP_NOWAIT; - } - } - } - break; - - /* Trap invalid mutex types: */ - default: - /* Return an invalid argument error: */ - ret = EINVAL; - break; - } - - if ((ret == 0) && (add_reference != 0)) { - /* Increment the reference count: */ - (*mutex)->m_refcount++; - } - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - - /* Return the completion status: */ - return (ret); -} - - -/* - * This function is called when a change in base priority occurs for - * a thread that is holding or waiting for a priority protection or - * inheritence mutex. A change in a threads base priority can effect - * changes to active priorities of other threads and to the ordering - * of mutex locking by waiting threads. - * - * This must be called while thread scheduling is deferred. - */ -void -_mutex_notify_priochange(pthread_t pthread) -{ - /* Adjust the priorites of any owned priority mutexes: */ - if (pthread->priority_mutex_count > 0) { - /* - * Rescan the mutexes owned by this thread and correct - * their priorities to account for this threads change - * in priority. This has the side effect of changing - * the threads active priority. - */ - mutex_rescan_owned(pthread, /* rescan all owned */ NULL); - } - - /* - * If this thread is waiting on a priority inheritence mutex, - * check for priority adjustments. A change in priority can - * also effect a ceiling violation(*) for a thread waiting on - * a priority protection mutex; we don't perform the check here - * as it is done in pthread_mutex_unlock. - * - * (*) It should be noted that a priority change to a thread - * _after_ taking and owning a priority ceiling mutex - * does not affect ownership of that mutex; the ceiling - * priority is only checked before mutex ownership occurs. - */ - if (pthread->state == PS_MUTEX_WAIT) { - /* Lock the mutex structure: */ - _SPINLOCK(&pthread->data.mutex->lock); - - /* - * Check to make sure this thread is still in the same state - * (the spinlock above can yield the CPU to another thread): - */ - if (pthread->state == PS_MUTEX_WAIT) { - /* - * Remove and reinsert this thread into the list of - * waiting threads to preserve decreasing priority - * order. - */ - mutex_queue_remove(pthread->data.mutex, pthread); - mutex_queue_enq(pthread->data.mutex, pthread); - - if (pthread->data.mutex->m_protocol == - PTHREAD_PRIO_INHERIT) { - /* Adjust priorities: */ - mutex_priority_adjust(pthread->data.mutex); - } - } - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&pthread->data.mutex->lock); - } -} - -/* - * Called when a new thread is added to the mutex waiting queue or - * when a threads priority changes that is already in the mutex - * waiting queue. - */ -static void -mutex_priority_adjust(pthread_mutex_t mutex) -{ - pthread_t pthread_next, pthread = mutex->m_owner; - int temp_prio; - pthread_mutex_t m = mutex; - - /* - * Calculate the mutex priority as the maximum of the highest - * active priority of any waiting threads and the owning threads - * active priority(*). - * - * (*) Because the owning threads current active priority may - * reflect priority inherited from this mutex (and the mutex - * priority may have changed) we must recalculate the active - * priority based on the threads saved inherited priority - * and its base priority. - */ - pthread_next = TAILQ_FIRST(&m->m_queue); /* should never be NULL */ - temp_prio = MAX(pthread_next->active_priority, - MAX(m->m_saved_prio, pthread->base_priority)); - - /* See if this mutex really needs adjusting: */ - if (temp_prio == m->m_prio) - /* No need to propagate the priority: */ - return; - - /* Set new priority of the mutex: */ - m->m_prio = temp_prio; - - while (m != NULL) { - /* - * Save the threads priority before rescanning the - * owned mutexes: - */ - temp_prio = pthread->active_priority; - - /* - * Fix the priorities for all the mutexes this thread has - * locked since taking this mutex. This also has a - * potential side-effect of changing the threads priority. - */ - mutex_rescan_owned(pthread, m); - - /* - * If the thread is currently waiting on a mutex, check - * to see if the threads new priority has affected the - * priority of the mutex. - */ - if ((temp_prio != pthread->active_priority) && - (pthread->state == PS_MUTEX_WAIT) && - (pthread->data.mutex->m_protocol == PTHREAD_PRIO_INHERIT)) { - /* Grab the mutex this thread is waiting on: */ - m = pthread->data.mutex; - - /* - * The priority for this thread has changed. Remove - * and reinsert this thread into the list of waiting - * threads to preserve decreasing priority order. - */ - mutex_queue_remove(m, pthread); - mutex_queue_enq(m, pthread); - - /* Grab the waiting thread with highest priority: */ - pthread_next = TAILQ_FIRST(&m->m_queue); - - /* - * Calculate the mutex priority as the maximum of the - * highest active priority of any waiting threads and - * the owning threads active priority. - */ - temp_prio = MAX(pthread_next->active_priority, - MAX(m->m_saved_prio, m->m_owner->base_priority)); - - if (temp_prio != m->m_prio) { - /* - * The priority needs to be propagated to the - * mutex this thread is waiting on and up to - * the owner of that mutex. - */ - m->m_prio = temp_prio; - pthread = m->m_owner; - } - else - /* We're done: */ - m = NULL; - - } - else - /* We're done: */ - m = NULL; - } -} - -static void -mutex_rescan_owned(pthread_t pthread, pthread_mutex_t mutex) -{ - int active_prio, inherited_prio; - pthread_mutex_t m; - pthread_t pthread_next; - - /* - * Start walking the mutexes the thread has taken since - * taking this mutex. - */ - if (mutex == NULL) { - /* - * A null mutex means start at the beginning of the owned - * mutex list. - */ - m = TAILQ_FIRST(&pthread->mutexq); - - /* There is no inherited priority yet. */ - inherited_prio = 0; - } - else { - /* - * The caller wants to start after a specific mutex. It - * is assumed that this mutex is a priority inheritence - * mutex and that its priority has been correctly - * calculated. - */ - m = TAILQ_NEXT(mutex, m_qe); - - /* Start inheriting priority from the specified mutex. */ - inherited_prio = mutex->m_prio; - } - active_prio = MAX(inherited_prio, pthread->base_priority); - - while (m != NULL) { - /* - * We only want to deal with priority inheritence - * mutexes. This might be optimized by only placing - * priority inheritence mutexes into the owned mutex - * list, but it may prove to be useful having all - * owned mutexes in this list. Consider a thread - * exiting while holding mutexes... - */ - if (m->m_protocol == PTHREAD_PRIO_INHERIT) { - /* - * Fix the owners saved (inherited) priority to - * reflect the priority of the previous mutex. - */ - m->m_saved_prio = inherited_prio; - - if ((pthread_next = TAILQ_FIRST(&m->m_queue)) != NULL) - /* Recalculate the priority of the mutex: */ - m->m_prio = MAX(active_prio, - pthread_next->active_priority); - else - m->m_prio = active_prio; - - /* Recalculate new inherited and active priorities: */ - inherited_prio = m->m_prio; - active_prio = MAX(m->m_prio, pthread->base_priority); - } - - /* Advance to the next mutex owned by this thread: */ - m = TAILQ_NEXT(m, m_qe); - } - - /* - * Fix the threads inherited priority and recalculate its - * active priority. - */ - pthread->inherited_priority = inherited_prio; - active_prio = MAX(inherited_prio, pthread->base_priority); - - if (active_prio != pthread->active_priority) { - /* - * If this thread is in the priority queue, it must be - * removed and reinserted for its new priority. - */ - if (pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) { - /* - * Remove the thread from the priority queue - * before changing its priority: - */ - PTHREAD_PRIOQ_REMOVE(pthread); - - /* - * POSIX states that if the priority is being - * lowered, the thread must be inserted at the - * head of the queue for its priority if it owns - * any priority protection or inheritence mutexes. - */ - if ((active_prio < pthread->active_priority) && - (pthread->priority_mutex_count > 0)) { - /* Set the new active priority. */ - pthread->active_priority = active_prio; - - PTHREAD_PRIOQ_INSERT_HEAD(pthread); - } - else { - /* Set the new active priority. */ - pthread->active_priority = active_prio; - - PTHREAD_PRIOQ_INSERT_TAIL(pthread); - } - } - else { - /* Set the new active priority. */ - pthread->active_priority = active_prio; - } - } -} - -/* - * Dequeue a waiting thread from the head of a mutex queue in descending - * priority order. - */ -static inline pthread_t -mutex_queue_deq(pthread_mutex_t mutex) -{ - pthread_t pthread; - - while ((pthread = TAILQ_FIRST(&mutex->m_queue)) != NULL) { - TAILQ_REMOVE(&mutex->m_queue, pthread, sqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_MUTEXQ; - - /* - * Only exit the loop if the thread hasn't been - * cancelled. - */ - if (pthread->interrupted == 0) - break; - } - - return(pthread); -} - -/* - * Remove a waiting thread from a mutex queue in descending priority order. - */ -static inline void -mutex_queue_remove(pthread_mutex_t mutex, pthread_t pthread) -{ - if ((pthread->flags & PTHREAD_FLAGS_IN_MUTEXQ) != 0) { - TAILQ_REMOVE(&mutex->m_queue, pthread, sqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_MUTEXQ; - } -} - -/* - * Enqueue a waiting thread to a queue in descending priority order. - */ -static inline void -mutex_queue_enq(pthread_mutex_t mutex, pthread_t pthread) -{ - pthread_t tid = TAILQ_LAST(&mutex->m_queue, mutex_head); - - PTHREAD_ASSERT_NOT_IN_SYNCQ(pthread); - /* - * For the common case of all threads having equal priority, - * we perform a quick check against the priority of the thread - * at the tail of the queue. - */ - if ((tid == NULL) || (pthread->active_priority <= tid->active_priority)) - TAILQ_INSERT_TAIL(&mutex->m_queue, pthread, sqe); - else { - tid = TAILQ_FIRST(&mutex->m_queue); - while (pthread->active_priority <= tid->active_priority) - tid = TAILQ_NEXT(tid, sqe); - TAILQ_INSERT_BEFORE(tid, pthread, sqe); - } - pthread->flags |= PTHREAD_FLAGS_IN_MUTEXQ; -} - -#endif diff --git a/lib/libpthread/uthread/uthread_mutex_prioceiling.c b/lib/libpthread/uthread/uthread_mutex_prioceiling.c deleted file mode 100644 index afcd9372d47..00000000000 --- a/lib/libpthread/uthread/uthread_mutex_prioceiling.c +++ /dev/null @@ -1,111 +0,0 @@ -/* $OpenBSD: uthread_mutex_prioceiling.c,v 1.2 1999/11/25 07:01:40 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_mutex_prioceiling.c,v 1.3 1999/08/28 00:03:40 peter Exp $ - */ -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL)) - ret = EINVAL; - else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else - *prioceiling = (*mattr)->m_ceiling; - - return(ret); -} - -int -pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL)) - ret = EINVAL; - else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else - (*mattr)->m_ceiling = prioceiling; - - return(ret); -} - -int -pthread_mutex_getprioceiling(pthread_mutex_t *mutex, - int *prioceiling) -{ - int ret; - - if ((mutex == NULL) || (*mutex == NULL)) - ret = EINVAL; - else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else - ret = (*mutex)->m_prio; - - return(ret); -} - -int -pthread_mutex_setprioceiling(pthread_mutex_t *mutex, - int prioceiling, int *old_ceiling) -{ - int ret = 0; - - if ((mutex == NULL) || (*mutex == NULL)) - ret = EINVAL; - else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) - ret = EINVAL; - else { - /* Lock the mutex: */ - if ((ret = pthread_mutex_lock(mutex)) == 0) { - /* Return the old ceiling and set the new ceiling: */ - *old_ceiling = (*mutex)->m_prio; - (*mutex)->m_prio = prioceiling; - - /* Unlock the mutex: */ - ret = pthread_mutex_unlock(mutex); - } - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_mutex_protocol.c b/lib/libpthread/uthread/uthread_mutex_protocol.c deleted file mode 100644 index 6b075ee4f2b..00000000000 --- a/lib/libpthread/uthread/uthread_mutex_protocol.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: uthread_mutex_protocol.c,v 1.2 1999/11/25 07:01:40 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_mutex_protocol.c,v 1.3 1999/08/28 00:03:41 peter Exp $ - */ -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL)) - ret = EINVAL; - else - *protocol = (*mattr)->m_protocol; - - return(ret); -} - -int -pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol) -{ - int ret = 0; - - if ((mattr == NULL) || (*mattr == NULL) || - (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT)) - ret = EINVAL; - else { - (*mattr)->m_protocol = protocol; - (*mattr)->m_ceiling = PTHREAD_MAX_PRIORITY; - } - return(ret); -} - -#endif diff --git a/lib/libpthread/uthread/uthread_mutexattr_destroy.c b/lib/libpthread/uthread/uthread_mutexattr_destroy.c deleted file mode 100644 index 39b7d66efd3..00000000000 --- a/lib/libpthread/uthread/uthread_mutexattr_destroy.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: uthread_mutexattr_destroy.c,v 1.4 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_mutexattr_destroy.c,v 1.4 1999/08/28 00:03:41 peter Exp $ - */ -#include <stdlib.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_mutexattr_destroy(pthread_mutexattr_t *attr) -{ - int ret; - if (attr == NULL || *attr == NULL) { - ret = EINVAL; - } else { - free(*attr); - *attr = NULL; - ret = 0; - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_nanosleep.c b/lib/libpthread/uthread/uthread_nanosleep.c deleted file mode 100644 index 05ace81b915..00000000000 --- a/lib/libpthread/uthread/uthread_nanosleep.c +++ /dev/null @@ -1,139 +0,0 @@ -/* $OpenBSD: uthread_nanosleep.c,v 1.8 2006/02/16 21:53:24 kurt Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_nanosleep.c,v 1.10 1999/08/28 00:03:41 peter Exp $ - */ -#include <stdio.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -nanosleep(const struct timespec * time_to_sleep, - struct timespec * time_remaining) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - struct timespec current_time; - struct timespec current_time1; - struct timespec remaining_time; - struct timeval tv; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Check if the time to sleep is legal: */ - if (time_to_sleep == NULL || - time_to_sleep->tv_sec < 0 || time_to_sleep->tv_sec > 100000000 || - time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec >= 1000000000) { - /* Return an EINVAL error : */ - errno = EINVAL; - ret = -1; - } else { - /* - * As long as we're going to get the time of day, we - * might as well store it in the global time of day: - */ - gettimeofday((struct timeval *) &_sched_tod, NULL); - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time); - - /* Calculate the time for the current thread to wake up: */ - curthread->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec; - curthread->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec; - - /* Check if the nanosecond field has overflowed: */ - if (curthread->wakeup_time.tv_nsec >= 1000000000) { - /* Wrap the nanosecond field: */ - curthread->wakeup_time.tv_sec += 1; - curthread->wakeup_time.tv_nsec -= 1000000000; - } - curthread->interrupted = 0; - - /* Reschedule the current thread to sleep: */ - _thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__); - - /* - * As long as we're going to get the time of day, we - * might as well store it in the global time of day: - */ - gettimeofday((struct timeval *) &_sched_tod, NULL); - GET_CURRENT_TOD(tv); - TIMEVAL_TO_TIMESPEC(&tv, ¤t_time1); - - /* Calculate the remaining time to sleep: */ - remaining_time.tv_sec = time_to_sleep->tv_sec + current_time.tv_sec - current_time1.tv_sec; - remaining_time.tv_nsec = time_to_sleep->tv_nsec + current_time.tv_nsec - current_time1.tv_nsec; - - /* Check if the nanosecond field has underflowed: */ - if (remaining_time.tv_nsec < 0) { - /* Handle the underflow: */ - remaining_time.tv_sec -= 1; - remaining_time.tv_nsec += 1000000000; - } - - /* Check if the nanosecond field has overflowed: */ - if (remaining_time.tv_nsec >= 1000000000) { - /* Handle the overflow: */ - remaining_time.tv_sec += 1; - remaining_time.tv_nsec -= 1000000000; - } - - /* Check if the sleep was longer than the required time: */ - if (remaining_time.tv_sec < 0) { - /* Reset the time left: */ - remaining_time.tv_sec = 0; - remaining_time.tv_nsec = 0; - } - - /* Check if the time remaining is to be returned: */ - if (time_remaining != NULL) { - /* Return the actual time slept: */ - time_remaining->tv_sec = remaining_time.tv_sec; - time_remaining->tv_nsec = remaining_time.tv_nsec; - } - - /* Check if the sleep was interrupted: */ - if (curthread->interrupted) { - /* Return an EINTR error : */ - errno = EINTR; - ret = -1; - } - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_once.c b/lib/libpthread/uthread/uthread_once.c deleted file mode 100644 index a69116bfa33..00000000000 --- a/lib/libpthread/uthread/uthread_once.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_once.c,v 1.4 2000/01/06 07:20:01 d Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_once.c,v 1.3 1999/08/28 00:03:42 peter Exp $ - */ -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_once(pthread_once_t * once_control, void (*init_routine) (void)) -{ - int ret; - - if (once_control->state == PTHREAD_NEEDS_INIT) { - if ((ret = pthread_mutex_lock(&(once_control->mutex))) != 0) - return ret; - if (once_control->state == PTHREAD_NEEDS_INIT) { - init_routine(); - once_control->state = PTHREAD_DONE_INIT; - } - pthread_mutex_unlock(&(once_control->mutex)); - } - return (0); -} -#endif diff --git a/lib/libpthread/uthread/uthread_open.c b/lib/libpthread/uthread/uthread_open.c deleted file mode 100644 index f49bfe6d22b..00000000000 --- a/lib/libpthread/uthread/uthread_open.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $OpenBSD: uthread_open.c,v 1.8 2006/09/26 14:18:28 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_open.c,v 1.6 1999/08/28 00:03:42 peter Exp $ - * - */ -#include <stdarg.h> -#include <unistd.h> -#include <fcntl.h> -#include <dirent.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -open(const char *path, int flags,...) -{ - int fd; - int mode = 0; - va_list ap; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Check if the file is being created: */ - if (flags & O_CREAT) { - /* Get the creation mode: */ - va_start(ap, flags); - mode = va_arg(ap, int); - va_end(ap); - } - /* Open the file: */ - if ((fd = _thread_sys_open(path, flags, mode)) < 0) { - } - /* Initialise the file descriptor table entry: */ - else if (_thread_fd_table_init(fd, FD_INIT_NEW, NULL) != 0) { - /* Quietly close the file: */ - _thread_sys_close(fd); - - /* Reset the file descriptor: */ - fd = -1; - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - /* Return the file descriptor or -1 on error: */ - return (fd); -} -#endif diff --git a/lib/libpthread/uthread/uthread_openat.c b/lib/libpthread/uthread/uthread_openat.c deleted file mode 100644 index 8b68c7d0026..00000000000 --- a/lib/libpthread/uthread/uthread_openat.c +++ /dev/null @@ -1,81 +0,0 @@ -/* $OpenBSD: uthread_openat.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_open.c,v 1.6 1999/08/28 00:03:42 peter Exp $ - * - */ -#include <stdarg.h> -#include <unistd.h> -#include <fcntl.h> -#include <dirent.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -openat(int atfd, const char *path, int flags,...) -{ - int fd; - int mode = 0; - va_list ap; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Check if the file is being created: */ - if (flags & O_CREAT) { - /* Get the creation mode: */ - va_start(ap, flags); - mode = va_arg(ap, int); - va_end(ap); - } - - /* Open the file: */ - if ((fd = _thread_sys_openat(atfd, path, flags, mode)) < 0) { - } - /* Initialise the file descriptor table entry: */ - else if (_thread_fd_table_init(fd, FD_INIT_NEW, NULL) != 0) { - /* Quietly close the file: */ - _thread_sys_close(fd); - - /* Reset the file descriptor: */ - fd = -1; - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - /* Return the file descriptor or -1 on error: */ - return (fd); -} -#endif diff --git a/lib/libpthread/uthread/uthread_pipe.c b/lib/libpthread/uthread/uthread_pipe.c deleted file mode 100644 index 9636e59700b..00000000000 --- a/lib/libpthread/uthread/uthread_pipe.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: uthread_pipe.c,v 1.5 2006/09/26 14:18:28 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_pipe.c,v 1.5 1999/08/28 00:03:42 peter Exp $ - */ -#include <unistd.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pipe(int fds[2]) -{ - int ret; - if ((ret = _thread_sys_pipe(fds)) >= 0) { - if (_thread_fd_table_init(fds[0], FD_INIT_NEW, NULL) != 0 || - _thread_fd_table_init(fds[1], FD_INIT_NEW, NULL) != 0) { - _thread_sys_close(fds[0]); - _thread_sys_close(fds[1]); - ret = -1; - } - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_poll.c b/lib/libpthread/uthread/uthread_poll.c deleted file mode 100644 index ddb1c275bf5..00000000000 --- a/lib/libpthread/uthread/uthread_poll.c +++ /dev/null @@ -1,108 +0,0 @@ -/* $OpenBSD: uthread_poll.c,v 1.15 2007/05/21 16:50:36 kurt Exp $ */ -/* - * Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_poll.c,v 1.4 1999/08/30 00:02:08 deischen Exp $ - */ -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <poll.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - - -int -poll(struct pollfd fds[], nfds_t nfds, int timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec ts; - nfds_t n, numfds = nfds; - int ret = 0; - struct pthread_poll_data data; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if (numfds > _thread_max_pfdtsize) { - numfds = _thread_max_pfdtsize; - } - /* Check if a timeout was specified: */ - if (timeout == INFTIM) { - /* Wait for ever: */ - _thread_kern_set_timeout(NULL); - } else if (timeout > 0) { - /* Convert the timeout in msec to a timespec: */ - ts.tv_sec = timeout / 1000; - ts.tv_nsec = (timeout % 1000) * 1000000; - - /* Set the wake up time: */ - _thread_kern_set_timeout(&ts); - } else if (timeout < 0) { - /* a timeout less than zero but not == INFTIM is invalid */ - errno = EINVAL; - _thread_leave_cancellation_point(); - return (-1); - } - - if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) { - data.nfds = numfds; - data.fds = fds; - - /* - * Clear revents in case of a timeout which leaves fds - * unchanged: - */ - for (n = 0; n < numfds; n++) { - fds[n].revents = 0; - } - - curthread->data.poll_data = &data; - curthread->interrupted = 0; - _thread_kern_sched_state(PS_POLL_WAIT, __FILE__, __LINE__); - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - } else { - ret = (int)data.nfds; - } - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_pread.c b/lib/libpthread/uthread/uthread_pread.c deleted file mode 100644 index 5fd305b6e33..00000000000 --- a/lib/libpthread/uthread/uthread_pread.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: uthread_pread.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_read.c,v 1.8 1999/08/28 00:03:43 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -pread(int fd, void *buf, size_t nbytes, off_t offset) -{ - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - ret = _thread_sys_pread(fd, buf, nbytes, offset); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_preadv.c b/lib/libpthread/uthread/uthread_preadv.c deleted file mode 100644 index c301afde7c5..00000000000 --- a/lib/libpthread/uthread/uthread_preadv.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: uthread_preadv.c,v 1.2 2012/01/18 17:24:23 chl Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_readv.c,v 1.8 1999/08/28 00:03:43 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -preadv(int fd, const struct iovec * iov, int iovcnt, off_t offset) -{ - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - ret = _thread_sys_preadv(fd, iov, iovcnt, offset); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_priority_queue.c b/lib/libpthread/uthread/uthread_priority_queue.c deleted file mode 100644 index a9fe248f704..00000000000 --- a/lib/libpthread/uthread/uthread_priority_queue.c +++ /dev/null @@ -1,330 +0,0 @@ -/* $OpenBSD: uthread_priority_queue.c,v 1.5 2007/05/18 19:28:50 kurt Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_priority_queue.c,v 1.3 1999/08/28 00:03:43 peter Exp $ - */ -#include <stdlib.h> -#include <sys/queue.h> -#include <string.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* Prototypes: */ -static void pq_insert_prio_list(pq_queue_t *pq, int prio); - -#if defined(_PTHREADS_INVARIANTS) - -static int _pq_active = 0; - -#define _PQ_IN_SCHEDQ (PTHREAD_FLAGS_IN_PRIOQ | PTHREAD_FLAGS_IN_WAITQ | PTHREAD_FLAGS_IN_WORKQ) - -#define _PQ_SET_ACTIVE() _pq_active = 1 -#define _PQ_CLEAR_ACTIVE() _pq_active = 0 -#define _PQ_ASSERT_ACTIVE(msg) do { \ - if (_pq_active == 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_INACTIVE(msg) do { \ - if (_pq_active != 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_IN_WAITQ(thrd, msg) do { \ - if (((thrd)->flags & PTHREAD_FLAGS_IN_WAITQ) == 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_IN_PRIOQ(thrd, msg) do { \ - if (((thrd)->flags & PTHREAD_FLAGS_IN_PRIOQ) == 0) \ - PANIC(msg); \ -} while (0) -#define _PQ_ASSERT_NOT_QUEUED(thrd, msg) do { \ - if (((thrd)->flags & _PQ_IN_SCHEDQ) != 0) \ - PANIC(msg); \ -} while (0) - -#else - -#define _PQ_SET_ACTIVE() -#define _PQ_CLEAR_ACTIVE() -#define _PQ_ASSERT_ACTIVE(msg) -#define _PQ_ASSERT_INACTIVE(msg) -#define _PQ_ASSERT_IN_WAITQ(thrd, msg) -#define _PQ_ASSERT_IN_PRIOQ(thrd, msg) -#define _PQ_ASSERT_NOT_QUEUED(thrd, msg) - -#endif - -int -_pq_alloc(pq_queue_t *pq, int minprio, int maxprio) -{ - int ret = 0; - int prioslots = maxprio - minprio + 1; - - if (pq == NULL || prioslots < 1) - ret = -1; - - /* Create the priority queue with (maxprio - minprio + 1) slots: */ - else if ((pq->pq_lists = - (pq_list_t *) malloc(sizeof(pq_list_t) * (size_t)prioslots)) == NULL) - ret = -1; - - else { - /* Remember the queue size: */ - pq->pq_size = prioslots; - ret = _pq_init(pq); - } - return (ret); -} - -int -_pq_init(pq_queue_t *pq) -{ - int i, ret = 0; - - if ((pq == NULL) || (pq->pq_lists == NULL)) - ret = -1; - - else { - /* Initialize the queue for each priority slot: */ - for (i = 0; i < pq->pq_size; i++) { - TAILQ_INIT(&pq->pq_lists[i].pl_head); - pq->pq_lists[i].pl_prio = i; - pq->pq_lists[i].pl_queued = 0; - } - - /* Initialize the priority queue: */ - TAILQ_INIT(&pq->pq_queue); - _PQ_CLEAR_ACTIVE(); - } - return (ret); -} - -void -_pq_remove(pq_queue_t *pq, pthread_t pthread) -{ - int prio = pthread->active_priority; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_remove: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_IN_PRIOQ(pthread, "_pq_remove: Not in priority queue"); - - /* - * Remove this thread from priority list. Note that if - * the priority list becomes empty, it is not removed - * from the priority queue because another thread may be - * added to the priority list (resulting in a needless - * removal/insertion). Priority lists are only removed - * from the priority queue when _pq_first is called. - */ - TAILQ_REMOVE(&pq->pq_lists[prio].pl_head, pthread, pqe); - - /* This thread is now longer in the priority queue. */ - pthread->flags &= ~PTHREAD_FLAGS_IN_PRIOQ; - - _PQ_CLEAR_ACTIVE(); -} - - -void -_pq_insert_head(pq_queue_t *pq, pthread_t pthread) -{ - int prio = pthread->active_priority; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_insert_head: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_NOT_QUEUED(pthread, - "_pq_insert_head: Already in priority queue"); - - TAILQ_INSERT_HEAD(&pq->pq_lists[prio].pl_head, pthread, pqe); - if (pq->pq_lists[prio].pl_queued == 0) - /* Insert the list into the priority queue: */ - pq_insert_prio_list(pq, prio); - - /* Mark this thread as being in the priority queue. */ - pthread->flags |= PTHREAD_FLAGS_IN_PRIOQ; - - _PQ_CLEAR_ACTIVE(); -} - - -void -_pq_insert_tail(pq_queue_t *pq, pthread_t pthread) -{ - int prio = pthread->active_priority; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_insert_tail: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_NOT_QUEUED(pthread, - "_pq_insert_tail: Already in priority queue"); - - TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe); - if (pq->pq_lists[prio].pl_queued == 0) - /* Insert the list into the priority queue: */ - pq_insert_prio_list(pq, prio); - - /* Mark this thread as being in the priority queue. */ - pthread->flags |= PTHREAD_FLAGS_IN_PRIOQ; - - _PQ_CLEAR_ACTIVE(); -} - - -pthread_t -_pq_first(pq_queue_t *pq) -{ - pq_list_t *pql; - pthread_t pthread = NULL; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_pq_first: pq_active"); - _PQ_SET_ACTIVE(); - - while (((pql = TAILQ_FIRST(&pq->pq_queue)) != NULL) && - (pthread == NULL)) { - if ((pthread = TAILQ_FIRST(&pql->pl_head)) == NULL) { - /* - * The priority list is empty; remove the list - * from the queue. - */ - TAILQ_REMOVE(&pq->pq_queue, pql, pl_link); - - /* Mark the list as not being in the queue: */ - pql->pl_queued = 0; - } - } - - _PQ_CLEAR_ACTIVE(); - return (pthread); -} - - -static void -pq_insert_prio_list(pq_queue_t *pq, int prio) -{ - pq_list_t *pql; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_ACTIVE("pq_insert_prio_list: pq_active"); - - /* - * The priority queue is in descending priority order. Start at - * the beginning of the queue and find the list before which the - * new list should be inserted. - */ - pql = TAILQ_FIRST(&pq->pq_queue); - while ((pql != NULL) && (pql->pl_prio > prio)) - pql = TAILQ_NEXT(pql, pl_link); - - /* Insert the list: */ - if (pql == NULL) - TAILQ_INSERT_TAIL(&pq->pq_queue, &pq->pq_lists[prio], pl_link); - else - TAILQ_INSERT_BEFORE(pql, &pq->pq_lists[prio], pl_link); - - /* Mark this list as being in the queue: */ - pq->pq_lists[prio].pl_queued = 1; -} - -void -_waitq_insert(pthread_t pthread) -{ - pthread_t tid; - - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_waitq_insert: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_NOT_QUEUED(pthread, "_waitq_insert: Already in queue"); - - if (pthread->wakeup_time.tv_sec == -1) - TAILQ_INSERT_TAIL(&_waitingq, pthread, pqe); - else { - tid = TAILQ_FIRST(&_waitingq); - while ((tid != NULL) && (tid->wakeup_time.tv_sec != -1) && - ((tid->wakeup_time.tv_sec < pthread->wakeup_time.tv_sec) || - ((tid->wakeup_time.tv_sec == pthread->wakeup_time.tv_sec) && - (tid->wakeup_time.tv_nsec <= pthread->wakeup_time.tv_nsec)))) - tid = TAILQ_NEXT(tid, pqe); - if (tid == NULL) - TAILQ_INSERT_TAIL(&_waitingq, pthread, pqe); - else - TAILQ_INSERT_BEFORE(tid, pthread, pqe); - } - pthread->flags |= PTHREAD_FLAGS_IN_WAITQ; - - _PQ_CLEAR_ACTIVE(); -} - -void -_waitq_remove(pthread_t pthread) -{ - /* - * Make some assertions when debugging is enabled: - */ - _PQ_ASSERT_INACTIVE("_waitq_remove: pq_active"); - _PQ_SET_ACTIVE(); - _PQ_ASSERT_IN_WAITQ(pthread, "_waitq_remove: Not in queue"); - - TAILQ_REMOVE(&_waitingq, pthread, pqe); - pthread->flags &= ~PTHREAD_FLAGS_IN_WAITQ; - - _PQ_CLEAR_ACTIVE(); -} - -void -_waitq_setactive(void) -{ - _PQ_ASSERT_INACTIVE("_waitq_setactive: pq_active"); - _PQ_SET_ACTIVE(); -} - -void -_waitq_clearactive(void) -{ - _PQ_ASSERT_ACTIVE("_waitq_clearactive: ! pq_active"); - _PQ_CLEAR_ACTIVE(); -} -#endif diff --git a/lib/libpthread/uthread/uthread_pwrite.c b/lib/libpthread/uthread/uthread_pwrite.c deleted file mode 100644 index 6e780ea4800..00000000000 --- a/lib/libpthread/uthread/uthread_pwrite.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $OpenBSD: uthread_pwrite.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_write.c,v 1.12 1999/08/28 00:03:54 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <stddef.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -pwrite(int fd, const void *buf, size_t nbytes, off_t offset) -{ - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - ret = _thread_sys_pwrite(fd, buf, nbytes, offset); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_pwritev.c b/lib/libpthread/uthread/uthread_pwritev.c deleted file mode 100644 index 090eeb8928d..00000000000 --- a/lib/libpthread/uthread/uthread_pwritev.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD: uthread_pwritev.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_writev.c,v 1.12 1999/08/28 00:03:55 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -pwritev(int fd, const struct iovec * iov, int iovcnt, off_t offset) -{ - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - ret = _thread_sys_pwritev(fd, iov, iovcnt, offset); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_read.c b/lib/libpthread/uthread/uthread_read.c deleted file mode 100644 index 7cdf9adc08e..00000000000 --- a/lib/libpthread/uthread/uthread_read.c +++ /dev/null @@ -1,116 +0,0 @@ -/* $OpenBSD: uthread_read.c,v 1.10 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_read.c,v 1.8 1999/08/28 00:03:43 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -read(int fd, void *buf, size_t nbytes) -{ - struct pthread *curthread = _get_curthread(); - ssize_t ret; - int type; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* POSIX says to do just this: */ - if (nbytes == 0) - ret = 0; - - /* Lock the file descriptor for read: */ - else if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_table[fd]->status_flags->flags & O_ACCMODE; - - /* Check if the file is not open for read: */ - if (type != O_RDONLY && type != O_RDWR) { - /* File is not open for read: */ - errno = EBADF; - ret = -1; - } - - /* Perform a non-blocking read syscall: */ - else while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { - if ((_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) == 0 && - (errno == EWOULDBLOCK || errno == EAGAIN)) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(_FD_RCVTIMEO(fd)); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - - _thread_kern_sched_state(PS_FDR_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal, - * a closing fd or timed out. - */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - errno = EBADF; - ret = -1; - break; - } else if (curthread->timeout) { - errno = EWOULDBLOCK; - ret = -1; - break; - } - } else { - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_readv.c b/lib/libpthread/uthread/uthread_readv.c deleted file mode 100644 index c152b0cfb77..00000000000 --- a/lib/libpthread/uthread/uthread_readv.c +++ /dev/null @@ -1,114 +0,0 @@ -/* $OpenBSD: uthread_readv.c,v 1.10 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_readv.c,v 1.8 1999/08/28 00:03:43 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -readv(int fd, const struct iovec * iov, int iovcnt) -{ - struct pthread *curthread = _get_curthread(); - ssize_t ret; - int type; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Lock the file descriptor for read: */ - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_table[fd]->status_flags->flags & O_ACCMODE; - - /* Check if the file is not open for read: */ - if (type != O_RDONLY && type != O_RDWR) { - /* File is not open for read: */ - errno = EBADF; - _FD_UNLOCK(fd, FD_READ); - _thread_leave_cancellation_point(); - return (-1); - } - - /* Perform a non-blocking readv syscall: */ - while ((ret = _thread_sys_readv(fd, iov, iovcnt)) < 0) { - if ((_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) == 0 && - (errno == EWOULDBLOCK || errno == EAGAIN)) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(_FD_RCVTIMEO(fd)); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - - _thread_kern_sched_state(PS_FDR_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal, - * a closing fd or timed out. - */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - errno = EBADF; - ret = -1; - break; - } else if (curthread->timeout) { - errno = EWOULDBLOCK; - ret = -1; - break; - } - } else { - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_recvfrom.c b/lib/libpthread/uthread/uthread_recvfrom.c deleted file mode 100644 index 424ba6550b7..00000000000 --- a/lib/libpthread/uthread/uthread_recvfrom.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $OpenBSD: uthread_recvfrom.c,v 1.11 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_recvfrom.c,v 1.5 1999/08/28 00:03:44 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, socklen_t *from_len) -{ - struct pthread *curthread = _get_curthread(); - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - while ((ret = _thread_sys_recvfrom(fd, buf, len, flags, from, from_len)) < 0) { - if (!(_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) && - !(flags & MSG_DONTWAIT) && - ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(_FD_RCVTIMEO(fd)); - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - _thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__); - - /* Check if the wait was interrupted: */ - if (curthread->interrupted) { - /* Return an error status: */ - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - /* Return an error status: */ - errno = EBADF; - ret = -1; - break; - } else if (curthread->timeout) { - /* Return an error status: */ - errno = EWOULDBLOCK; - ret = -1; - break; - } - } else { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_recvmsg.c b/lib/libpthread/uthread/uthread_recvmsg.c deleted file mode 100644 index 66de9d14998..00000000000 --- a/lib/libpthread/uthread/uthread_recvmsg.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $OpenBSD: uthread_recvmsg.c,v 1.10 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_recvmsg.c,v 1.4 1999/08/28 00:03:44 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -recvmsg(int fd, struct msghdr *msg, int flags) -{ - struct pthread *curthread = _get_curthread(); - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { - while ((ret = _thread_sys_recvmsg(fd, msg, flags)) < 0) { - if (!(_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) && - !(flags & MSG_DONTWAIT) && - ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(_FD_RCVTIMEO(fd)); - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - _thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__); - - /* Check if the wait was interrupted: */ - if (curthread->interrupted) { - /* Return an error status: */ - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - /* Return an error status: */ - errno = EBADF; - ret = -1; - break; - } else if (curthread->timeout) { - /* Return an error status: */ - errno = EWOULDBLOCK; - ret = -1; - break; - } - } else { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_READ); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_resume_np.c b/lib/libpthread/uthread/uthread_resume_np.c deleted file mode 100644 index ce891bcb9c8..00000000000 --- a/lib/libpthread/uthread/uthread_resume_np.c +++ /dev/null @@ -1,137 +0,0 @@ -/* $OpenBSD: uthread_resume_np.c,v 1.6 2004/05/01 22:15:10 marc Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_resume_np.c,v 1.7 1999/08/28 00:03:44 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -static void resume_common(struct pthread *, enum pthread_susp); - -/* Resume a thread: */ -int -pthread_resume_np(pthread_t thread) -{ - int ret; - enum pthread_susp old_suspended; - - /* Find the thread in the list of active threads: */ - if ((ret = _find_thread(thread)) == 0) { - /* Cancel any pending suspensions: */ - old_suspended = thread->suspended; - thread->suspended = SUSP_NO; - - /* Is it currently suspended? */ - if (thread->state == PS_SUSPENDED) { - /* - * Defer signals to protect the scheduling queues - * from access by the signal handler: - */ - _thread_kern_sig_defer(); - - resume_common(thread, old_suspended); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - } - return(ret); -} - -void -pthread_resume_all_np(void) -{ - struct pthread *curthread = _get_curthread(); - struct pthread *thread; - enum pthread_susp old_suspended; - - /* - * Defer signals to protect the scheduling queues from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - TAILQ_FOREACH(thread, &_thread_list, tle) { - if (thread != curthread) { - /* Cancel any pending suspensions: */ - old_suspended = thread->suspended; - thread->suspended = SUSP_NO; - - /* Is it currently suspended? */ - if (thread->state == PS_SUSPENDED) - resume_common(thread, old_suspended); - } - } - - /* - * Undefer and handle pending signals, yielding if necessary: - */ - _thread_kern_sig_undefer(); -} - -static void -resume_common(struct pthread *thread, enum pthread_susp old_suspended) -{ - switch (old_suspended) { - case SUSP_MUTEX_WAIT: - /* Set the thread's state back. */ - PTHREAD_SET_STATE(thread,PS_MUTEX_WAIT); - break; - case SUSP_COND_WAIT: - /* Set the thread's state back. */ - PTHREAD_SET_STATE(thread,PS_COND_WAIT); - break; - case SUSP_JOIN: - /* Set the thread's state back. */ - PTHREAD_SET_STATE(thread,PS_JOIN); - break; - case SUSP_NOWAIT: - /* Allow the thread to run. */ - PTHREAD_SET_STATE(thread,PS_RUNNING); - PTHREAD_WAITQ_REMOVE(thread); - PTHREAD_PRIOQ_INSERT_TAIL(thread); - break; - case SUSP_NO: - case SUSP_YES: - /* Allow the thread to run. */ - PTHREAD_SET_STATE(thread,PS_RUNNING); - PTHREAD_PRIOQ_INSERT_TAIL(thread); - break; - } - -} -#endif diff --git a/lib/libpthread/uthread/uthread_rwlock.c b/lib/libpthread/uthread/uthread_rwlock.c deleted file mode 100644 index cf6edf5e6d7..00000000000 --- a/lib/libpthread/uthread/uthread_rwlock.c +++ /dev/null @@ -1,408 +0,0 @@ -/* $OpenBSD: uthread_rwlock.c,v 1.7 2010/04/12 01:54:23 tedu Exp $ */ -/*- - * Copyright (c) 1998 Alex Nash - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_rwlock.c,v 1.9 2004/01/08 15:39:12 deischen Exp $ - */ - -#ifdef _THREAD_SAFE -#include <errno.h> -#include <limits.h> -#include <stdlib.h> - -#include <pthread.h> -#include "pthread_private.h" - -/* maximum number of times a read lock may be obtained */ -#define MAX_READ_LOCKS (INT_MAX - 1) - -static int init_static (pthread_rwlock_t *rwlock); - -static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER; - -static int -init_static (pthread_rwlock_t *rwlock) -{ - int ret; - - _SPINLOCK(&static_init_lock); - - if (*rwlock == NULL) - ret = pthread_rwlock_init(rwlock, NULL); - else - ret = 0; - - _SPINUNLOCK(&static_init_lock); - - return (ret); -} - -int -pthread_rwlock_destroy (pthread_rwlock_t *rwlock) -{ - int ret; - - if (rwlock == NULL) - ret = EINVAL; - else { - pthread_rwlock_t prwlock; - - prwlock = *rwlock; - - pthread_mutex_destroy(&prwlock->lock); - pthread_cond_destroy(&prwlock->read_signal); - pthread_cond_destroy(&prwlock->write_signal); - free(prwlock); - - *rwlock = NULL; - - ret = 0; - } - return (ret); -} - -/* ARGSUSED */ -int -pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) -{ - pthread_rwlock_t prwlock; - int ret; - - /* allocate rwlock object */ - prwlock = (pthread_rwlock_t)malloc(sizeof(struct pthread_rwlock)); - - if (prwlock == NULL) - return(ENOMEM); - - /* initialize the lock */ - if ((ret = pthread_mutex_init(&prwlock->lock, NULL)) != 0) - free(prwlock); - else { - /* initialize the read condition signal */ - ret = pthread_cond_init(&prwlock->read_signal, NULL); - - if (ret != 0) { - pthread_mutex_destroy(&prwlock->lock); - free(prwlock); - } else { - /* initialize the write condition signal */ - ret = pthread_cond_init(&prwlock->write_signal, NULL); - - if (ret != 0) { - pthread_cond_destroy(&prwlock->read_signal); - pthread_mutex_destroy(&prwlock->lock); - free(prwlock); - } else { - /* success */ - prwlock->state = 0; - prwlock->blocked_writers = 0; - - *rwlock = prwlock; - } - } - } - - return (ret); -} - -static int -rwlock_rdlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime) -{ - pthread_rwlock_t prwlock; - struct pthread *curthread; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - /* check lock count */ - if (prwlock->state == MAX_READ_LOCKS) { - pthread_mutex_unlock(&prwlock->lock); - return (EAGAIN); - } - - curthread = _get_curthread(); - if ((curthread->rdlock_count > 0) && (prwlock->state > 0)) { - /* - * To avoid having to track all the rdlocks held by - * a thread or all of the threads that hold a rdlock, - * we keep a simple count of all the rdlocks held by - * a thread. If a thread holds any rdlocks it is - * possible that it is attempting to take a recursive - * rdlock. If there are blocked writers and precedence - * is given to them, then that would result in the thread - * deadlocking. So allowing a thread to take the rdlock - * when it already has one or more rdlocks avoids the - * deadlock. I hope the reader can follow that logic ;-) - */ - ; /* nothing needed */ - } else { - /* give writers priority over readers */ - while (prwlock->blocked_writers || prwlock->state < 0) { - if (abstime) { - ret = pthread_cond_timedwait(&prwlock->read_signal, - &prwlock->lock, abstime); - } else { - ret = pthread_cond_wait(&prwlock->read_signal, - &prwlock->lock); - } - - if (ret != 0) { - /* can't do a whole lot if this fails */ - pthread_mutex_unlock(&prwlock->lock); - return(ret); - } - } - } - - curthread->rdlock_count++; - prwlock->state++; /* indicate we are locked for reading */ - - /* - * Something is really wrong if this call fails. Returning - * error won't do because we've already obtained the read - * lock. Decrementing 'state' is no good because we probably - * don't have the monitor lock. - */ - pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) -{ - return rwlock_rdlock_common (rwlock, NULL); -} - -int -pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, - const struct timespec *abstime) -{ - return rwlock_rdlock_common(rwlock, abstime); -} - -int -pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - struct pthread *curthread; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - curthread = _get_curthread(); - if (prwlock->state == MAX_READ_LOCKS) - ret = EAGAIN; /* too many read locks acquired */ - else if ((curthread->rdlock_count > 0) && (prwlock->state > 0)) { - /* see comment for pthread_rwlock_rdlock() */ - curthread->rdlock_count++; - prwlock->state++; - } - /* give writers priority over readers */ - else if (prwlock->blocked_writers || prwlock->state < 0) - ret = EBUSY; - else { - prwlock->state++; /* indicate we are locked for reading */ - curthread->rdlock_count++; - } - - /* see the comment on this in pthread_rwlock_rdlock */ - pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - if (prwlock->state != 0) - ret = EBUSY; - else - /* indicate we are locked for writing */ - prwlock->state = -1; - - /* see the comment on this in pthread_rwlock_rdlock */ - pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -pthread_rwlock_unlock (pthread_rwlock_t *rwlock) -{ - pthread_rwlock_t prwlock; - struct pthread *curthread; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - if (prwlock == NULL) - return(EINVAL); - - /* grab the monitor lock */ - if ((ret = pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - curthread = _get_curthread(); - if (prwlock->state > 0) { - curthread->rdlock_count--; - prwlock->state--; - if (prwlock->state == 0 && prwlock->blocked_writers) - ret = pthread_cond_signal(&prwlock->write_signal); - } else if (prwlock->state < 0) { - prwlock->state = 0; - - if (prwlock->blocked_writers) - ret = pthread_cond_signal(&prwlock->write_signal); - else - ret = pthread_cond_broadcast(&prwlock->read_signal); - } else - ret = EINVAL; - - /* see the comment on this in pthread_rwlock_rdlock */ - pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -static int -rwlock_wrlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime) -{ - pthread_rwlock_t prwlock; - int ret; - - if (rwlock == NULL) - return(EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (prwlock == NULL) { - if ((ret = init_static(rwlock)) != 0) - return(ret); - - prwlock = *rwlock; - } - - /* grab the monitor lock */ - if ((ret = pthread_mutex_lock(&prwlock->lock)) != 0) - return(ret); - - while (prwlock->state != 0) { - prwlock->blocked_writers++; - - if (abstime != NULL) { - ret = pthread_cond_timedwait(&prwlock->write_signal, - &prwlock->lock, abstime); - } else { - ret = pthread_cond_wait(&prwlock->write_signal, - &prwlock->lock); - } - - if (ret != 0) { - prwlock->blocked_writers--; - pthread_mutex_unlock(&prwlock->lock); - return(ret); - } - - prwlock->blocked_writers--; - } - - /* indicate we are locked for writing */ - prwlock->state = -1; - - /* see the comment on this in pthread_rwlock_rdlock */ - pthread_mutex_unlock(&prwlock->lock); - - return (ret); -} - -int -pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) -{ - return rwlock_wrlock_common (rwlock, NULL); -} - -int -pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, - const struct timespec *abstime) -{ - return rwlock_wrlock_common (rwlock, abstime); -} - -#endif /* _THREAD_SAFE */ diff --git a/lib/libpthread/uthread/uthread_rwlockattr.c b/lib/libpthread/uthread/uthread_rwlockattr.c deleted file mode 100644 index 1cc23bfbef4..00000000000 --- a/lib/libpthread/uthread/uthread_rwlockattr.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: uthread_rwlockattr.c,v 1.4 2000/01/04 22:34:24 alex Exp $ */ -/*- - * Copyright (c) 1998 Alex Nash - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_rwlockattr.c,v 1.3 1999/08/28 00:03:45 peter Exp $ - */ - -#ifdef _THREAD_SAFE -#include <errno.h> -#include <stdlib.h> - -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_rwlockattr_destroy (pthread_rwlockattr_t *rwlockattr) -{ - pthread_rwlockattr_t prwlockattr; - - if (rwlockattr == NULL) - return(EINVAL); - - prwlockattr = *rwlockattr; - - if (prwlockattr == NULL) - return(EINVAL); - - free(prwlockattr); - - return(0); -} - -int -pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *rwlockattr, - int *pshared) -{ - *pshared = (*rwlockattr)->pshared; - - return(0); -} - -int -pthread_rwlockattr_init (pthread_rwlockattr_t *rwlockattr) -{ - pthread_rwlockattr_t prwlockattr; - - if (rwlockattr == NULL) - return(EINVAL); - - prwlockattr = (pthread_rwlockattr_t) - malloc(sizeof(struct pthread_rwlockattr)); - - if (prwlockattr == NULL) - return(ENOMEM); - - prwlockattr->pshared = PTHREAD_PROCESS_PRIVATE; - *rwlockattr = prwlockattr; - - return(0); -} - -int -pthread_rwlockattr_setpshared (pthread_rwlockattr_t *rwlockattr, - int pshared) -{ - /* only PTHREAD_PROCESS_PRIVATE is supported */ - if (pshared != PTHREAD_PROCESS_PRIVATE) - return(EINVAL); - - (*rwlockattr)->pshared = pshared; - - return(0); -} - -#endif /* _THREAD_SAFE */ diff --git a/lib/libpthread/uthread/uthread_select.c b/lib/libpthread/uthread/uthread_select.c deleted file mode 100644 index 676221ee965..00000000000 --- a/lib/libpthread/uthread/uthread_select.c +++ /dev/null @@ -1,243 +0,0 @@ -/* $OpenBSD: uthread_select.c,v 1.16 2007/05/21 16:50:36 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_select.c,v 1.13 1999/08/30 00:02:08 deischen Exp $ - */ -#include <unistd.h> -#include <errno.h> -#include <poll.h> -#include <stdlib.h> -#include <string.h> -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * Minimum number of poll_data entries to allocate - */ -#define POLLDATA_MIN 128 - -int -select(int numfds, fd_set * readfds, fd_set * writefds, - fd_set * exceptfds, struct timeval * timeout) -{ - struct pthread *curthread = _get_curthread(); - struct timespec ts; - int bit, i, j, ret = 0, f_wait = 1; - short events; - int got_events = 0, fd_count = 0; - struct pthread_poll_data data; - fd_mask mask, rmask, wmask, emask; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if (numfds > _thread_max_fdtsize) { - numfds = _thread_max_fdtsize; - } - - /* Check if a timeout was specified: */ - if (timeout) { - if (timeout->tv_sec < 0 || - timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) { - errno = EINVAL; - ret = -1; - goto done; - } - - /* Convert the timeval to a timespec: */ - TIMEVAL_TO_TIMESPEC(timeout, &ts); - - /* Set the wake up time: */ - _thread_kern_set_timeout(&ts); - if (ts.tv_sec == 0 && ts.tv_nsec == 0) - f_wait = 0; - } else { - /* Wait for ever: */ - _thread_kern_set_timeout(NULL); - } - - /* Count the number of file descriptors to be polled: */ - if (numfds && (readfds || writefds || exceptfds)) { - for (i = (numfds - 1) / (int)NFDBITS; i >= 0; i--) { - rmask = readfds ? readfds->fds_bits[i] : 0; - wmask = writefds ? writefds->fds_bits[i] : 0; - emask = exceptfds ? exceptfds->fds_bits[i] : 0; - mask = rmask | wmask | emask; - for (; (bit = ffs(mask)); mask ^= (1 << (bit - 1))) - fd_count++; - } - } - - /* - * Allocate memory for poll data if it hasn't already been - * allocated or if previously allocated memory is insufficient. - */ - if ((curthread->poll_data.fds == NULL) || - (curthread->poll_data.nfds < (nfds_t)fd_count)) { - data.fds = (struct pollfd *) realloc(curthread->poll_data.fds, - sizeof(struct pollfd) * (size_t)MAX(POLLDATA_MIN, fd_count)); - if (data.fds == NULL) { - errno = ENOMEM; - ret = -1; - } - else { - /* - * Note that the threads poll data always - * indicates what is allocated, not what is - * currently being polled. - */ - curthread->poll_data.fds = data.fds; - curthread->poll_data.nfds = (nfds_t)MAX(POLLDATA_MIN, fd_count); - } - } - if (ret == 0) { - /* Setup the wait data. */ - data.fds = curthread->poll_data.fds; - data.nfds = (nfds_t)fd_count; - - /* - * Setup the array of pollfds. Optimize this by - * running the loop in reverse and stopping when - * the number of selected file descriptors is reached. - */ - for (i = (numfds - 1) / (int)NFDBITS, j = fd_count; - j != 0 && i >= 0; i--) { - rmask = readfds ? readfds->fds_bits[i] : 0; - wmask = writefds ? writefds->fds_bits[i] : 0; - emask = exceptfds ? exceptfds->fds_bits[i] : 0; - mask = rmask | wmask | emask; - while ((bit = ffs(mask))) { - int n = 1 << (bit - 1); - mask ^= n; - events = 0; - if (rmask & n) - events |= POLLRDNORM; - if (wmask & n) - events |= POLLWRNORM; - if (emask & n) - events |= POLLRDBAND; - if (events != 0) { - /* - * Set the file descriptor to be polled - * and clear revents in case of a - * timeout which leaves fds unchanged: - */ - data.fds[--j].fd = - (i * (int)NFDBITS) + bit - 1; - data.fds[j].events = events; - data.fds[j].revents = 0; - } - } - } - if (((ret = _thread_sys_poll(data.fds, data.nfds, 0)) == 0) && - (f_wait != 0)) { - curthread->data.poll_data = &data; - curthread->interrupted = 0; - _thread_kern_sched_state(PS_SELECT_WAIT, __FILE__, __LINE__); - if (curthread->interrupted) { - errno = EINTR; - data.nfds = 0; - ret = -1; - } else - ret = (int)data.nfds; - } - } - - if (ret >= 0) { - numfds = 0; - for (i = 0; i < fd_count; i++) { - /* - * Check the results of the poll and clear - * this file descriptor from the fdset if - * the requested event wasn't ready. - */ - - /* - * First check for invalid descriptor. - * If found, set errno and return -1. - */ - if (data.fds[i].revents & POLLNVAL) { - errno = EBADF; - ret = -1; - goto done; - } - - got_events = 0; - if (readfds != NULL) { - if (FD_ISSET(data.fds[i].fd, readfds)) { - if ((data.fds[i].revents & (POLLIN - | POLLRDNORM | POLLERR - | POLLHUP)) != 0) - got_events++; - else - FD_CLR(data.fds[i].fd, readfds); - } - } - if (writefds != NULL) { - if (FD_ISSET(data.fds[i].fd, writefds)) { - if ((data.fds[i].revents & (POLLOUT - | POLLWRNORM | POLLWRBAND | POLLERR - | POLLHUP)) != 0) - got_events++; - else - FD_CLR(data.fds[i].fd, - writefds); - } - } - if (exceptfds != NULL) { - if (FD_ISSET(data.fds[i].fd, exceptfds)) { - if (data.fds[i].revents & (POLLRDBAND | - POLLPRI)) - got_events++; - else - FD_CLR(data.fds[i].fd, - exceptfds); - } - } - if (got_events != 0) - numfds+=got_events; - } - ret = numfds; - } - -done: - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_self.c b/lib/libpthread/uthread/uthread_self.c deleted file mode 100644 index 5c0c53c4cbc..00000000000 --- a/lib/libpthread/uthread/uthread_self.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $OpenBSD: uthread_self.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_self.c,v 1.3 1999/08/28 00:03:46 peter Exp $ - */ -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -pthread_t -pthread_self(void) -{ - /* Return the running thread pointer: */ - return (_get_curthread()); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sem.c b/lib/libpthread/uthread/uthread_sem.c deleted file mode 100644 index 925910cbda5..00000000000 --- a/lib/libpthread/uthread/uthread_sem.c +++ /dev/null @@ -1,252 +0,0 @@ -/* $OpenBSD: uthread_sem.c,v 1.3 2008/06/20 02:58:00 kurt Exp $ */ -/* - * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice(s), this list of conditions and the following disclaimer as - * the first lines of this file unmodified other than the possible - * addition of one or more copyright notices. - * 2. Redistributions in binary form must reproduce the above copyright - * notice(s), this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: uthread_sem.c,v 1.10 2001/05/18 00:36:05 jasone Exp $ - */ - -#include <stdlib.h> -#include <errno.h> -#include <semaphore.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -#define _SEM_CHECK_VALIDITY(sem) \ - if ((sem) == NULL || \ - *(sem) == NULL || \ - (*(sem))->magic != SEM_MAGIC) { \ - errno = EINVAL; \ - retval = -1; \ - goto RETURN; \ - } - -int -sem_init(sem_t *sem, int pshared, unsigned int value) -{ - int retval; - - /* - * Range check the arguments. - */ - if (pshared != 0) { - /* - * The user wants a semaphore that can be shared among - * processes, which this implementation can't do. Sounds like a - * permissions problem to me (yeah right). - */ - errno = EPERM; - retval = -1; - goto RETURN; - } - - if (value > SEM_VALUE_MAX) { - errno = EINVAL; - retval = -1; - goto RETURN; - } - - *sem = (sem_t)malloc(sizeof(struct sem)); - if (*sem == NULL) { - errno = ENOSPC; - retval = -1; - goto RETURN; - } - - /* - * Initialize the semaphore. - */ - if (pthread_mutex_init(&(*sem)->lock, NULL) != 0) { - free(*sem); - errno = ENOSPC; - retval = -1; - goto RETURN; - } - - if (pthread_cond_init(&(*sem)->gtzero, NULL) != 0) { - pthread_mutex_destroy(&(*sem)->lock); - free(*sem); - errno = ENOSPC; - retval = -1; - goto RETURN; - } - - (*sem)->count = (u_int32_t)value; - (*sem)->nwaiters = 0; - (*sem)->magic = SEM_MAGIC; - - retval = 0; - RETURN: - return retval; -} - -int -sem_destroy(sem_t *sem) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - /* Make sure there are no waiters. */ - pthread_mutex_lock(&(*sem)->lock); - if ((*sem)->nwaiters > 0) { - pthread_mutex_unlock(&(*sem)->lock); - errno = EBUSY; - retval = -1; - goto RETURN; - } - pthread_mutex_unlock(&(*sem)->lock); - - pthread_mutex_destroy(&(*sem)->lock); - pthread_cond_destroy(&(*sem)->gtzero); - (*sem)->magic = 0; - - free(*sem); - - retval = 0; - RETURN: - return retval; -} - -/* ARGSUSED */ -sem_t * -sem_open(const char *name, int oflag, ...) -{ - errno = ENOSYS; - return SEM_FAILED; -} - -/* ARGSUSED */ -int -sem_close(sem_t *sem) -{ - errno = ENOSYS; - return -1; -} - -/* ARGSUSED */ -int -sem_unlink(const char *name) -{ - errno = ENOSYS; - return -1; -} - -int -sem_wait(sem_t *sem) -{ - int retval; - - _thread_enter_cancellation_point(); - - _SEM_CHECK_VALIDITY(sem); - - pthread_mutex_lock(&(*sem)->lock); - - while ((*sem)->count == 0) { - (*sem)->nwaiters++; - pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock); - (*sem)->nwaiters--; - } - (*sem)->count--; - - pthread_mutex_unlock(&(*sem)->lock); - - retval = 0; - RETURN: - _thread_leave_cancellation_point(); - return retval; -} - -int -sem_trywait(sem_t *sem) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - pthread_mutex_lock(&(*sem)->lock); - - if ((*sem)->count > 0) { - (*sem)->count--; - retval = 0; - } else { - errno = EAGAIN; - retval = -1; - } - - pthread_mutex_unlock(&(*sem)->lock); - - RETURN: - return retval; -} - -int -sem_post(sem_t *sem) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - /* - * sem_post() is required to be safe to call from within signal - * handlers. Thus, we must defer signals. - */ - _thread_kern_sig_defer(); - - pthread_mutex_lock(&(*sem)->lock); - - (*sem)->count++; - if ((*sem)->nwaiters > 0) - pthread_cond_signal(&(*sem)->gtzero); - - pthread_mutex_unlock(&(*sem)->lock); - - _thread_kern_sig_undefer(); - retval = 0; - RETURN: - return retval; -} - -int -sem_getvalue(sem_t *sem, int *sval) -{ - int retval; - - _SEM_CHECK_VALIDITY(sem); - - pthread_mutex_lock(&(*sem)->lock); - *sval = (int)(*sem)->count; - pthread_mutex_unlock(&(*sem)->lock); - - retval = 0; - RETURN: - return retval; -} - -#endif diff --git a/lib/libpthread/uthread/uthread_sendmsg.c b/lib/libpthread/uthread/uthread_sendmsg.c deleted file mode 100644 index d0d1010d75b..00000000000 --- a/lib/libpthread/uthread/uthread_sendmsg.c +++ /dev/null @@ -1,92 +0,0 @@ -/* $OpenBSD: uthread_sendmsg.c,v 1.9 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sendmsg.c,v 1.4 1999/08/28 00:03:46 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -sendmsg(int fd, const struct msghdr *msg, int flags) -{ - struct pthread *curthread = _get_curthread(); - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - while ((ret = _thread_sys_sendmsg(fd, msg, flags)) < 0) { - if (!(_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) && - ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(_FD_SNDTIMEO(fd)); - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - _thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__); - - /* Check if the operation was interrupted: */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - errno = EBADF; - ret = -1; - break; - } else if (curthread->timeout) { - errno = EWOULDBLOCK; - ret = -1; - break; - } - } else { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_WRITE); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sendto.c b/lib/libpthread/uthread/uthread_sendto.c deleted file mode 100644 index fc5aa5152b0..00000000000 --- a/lib/libpthread/uthread/uthread_sendto.c +++ /dev/null @@ -1,92 +0,0 @@ -/* $OpenBSD: uthread_sendto.c,v 1.10 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sendto.c,v 1.5 1999/08/28 00:03:46 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * to, socklen_t to_len) -{ - struct pthread *curthread = _get_curthread(); - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - while ((ret = _thread_sys_sendto(fd, msg, len, flags, to, to_len)) < 0) { - if (!(_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) && - ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { - curthread->data.fd.fd = fd; - - /* Set the timeout: */ - _thread_kern_set_timeout(_FD_SNDTIMEO(fd)); - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - _thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__); - - /* Check if the operation was interrupted: */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } else if (curthread->closing_fd) { - errno = EBADF; - ret = -1; - break; - } else if (curthread->timeout) { - errno = EWOULDBLOCK; - ret = -1; - break; - } - } else { - ret = -1; - break; - } - } - _FD_UNLOCK(fd, FD_WRITE); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_seterrno.c b/lib/libpthread/uthread/uthread_seterrno.c deleted file mode 100644 index 1b008122ca3..00000000000 --- a/lib/libpthread/uthread/uthread_seterrno.c +++ /dev/null @@ -1,68 +0,0 @@ -/* $OpenBSD: uthread_seterrno.c,v 1.4 1999/11/27 01:30:11 d Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_seterrno.c,v 1.4 1999/08/28 00:03:46 peter Exp $ - */ -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * This function needs to reference the global error variable which is - * normally hidden from the user. - */ -#ifdef errno -#undef errno -#endif -extern int errno; - -void -_thread_seterrno(pthread_t thread, int error) -{ - - /* Don't allow _thread_run to change: */ - _thread_kern_sig_defer(); - - /* Check for the current thread: */ - if (thread == _thread_run) - /* The current thread always uses the global error variable: */ - errno = error; - else - /* - * Threads other than the current thread will keep the error - * field in the thread structure: - */ - thread->error = error; - - _thread_kern_sig_undefer(); -} -#endif diff --git a/lib/libpthread/uthread/uthread_setprio.c b/lib/libpthread/uthread/uthread_setprio.c deleted file mode 100644 index b0be80a20ad..00000000000 --- a/lib/libpthread/uthread/uthread_setprio.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: uthread_setprio.c,v 1.5 1999/11/25 07:01:43 d Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_setprio.c,v 1.6 1999/08/28 00:03:47 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_setprio(pthread_t pthread, int prio) -{ - int ret, policy; - struct sched_param param; - - if ((ret = pthread_getschedparam(pthread, &policy, ¶m)) == 0) { - param.sched_priority = prio; - ret = pthread_setschedparam(pthread, policy, ¶m); - } - - /* Return the error status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_setschedparam.c b/lib/libpthread/uthread/uthread_setschedparam.c deleted file mode 100644 index 438691930b8..00000000000 --- a/lib/libpthread/uthread/uthread_setschedparam.c +++ /dev/null @@ -1,119 +0,0 @@ -/* $OpenBSD: uthread_setschedparam.c,v 1.5 2002/01/19 23:49:32 fgsch Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_setschedparam.c,v 1.3 1999/08/28 00:03:47 peter Exp $ - */ -#include <errno.h> -#include <sys/param.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param) -{ - int old_prio, in_readyq = 0, ret = 0; - - if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR)) { - /* Return an invalid argument error: */ - ret = EINVAL; - } else if ((param->sched_priority < PTHREAD_MIN_PRIORITY) || - (param->sched_priority > PTHREAD_MAX_PRIORITY)) { - /* Return an unsupported value error. */ - ret = ENOTSUP; - - /* Find the thread in the list of active threads: */ - } else if ((ret = _find_thread(pthread)) == 0) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - if (param->sched_priority != - PTHREAD_BASE_PRIORITY(pthread->base_priority)) { - /* - * Remove the thread from its current priority - * queue before any adjustments are made to its - * active priority: - */ - old_prio = pthread->active_priority; - if ((pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) != 0) { - in_readyq = 1; - PTHREAD_PRIOQ_REMOVE(pthread); - } - - /* Set the thread base priority: */ - pthread->base_priority &= - (PTHREAD_SIGNAL_PRIORITY | PTHREAD_RT_PRIORITY); - pthread->base_priority = param->sched_priority; - - /* Recalculate the active priority: */ - pthread->active_priority = MAX(pthread->base_priority, - pthread->inherited_priority); - - if (in_readyq) { - if ((pthread->priority_mutex_count > 0) && - (old_prio > pthread->active_priority)) { - /* - * POSIX states that if the priority is - * being lowered, the thread must be - * inserted at the head of the queue for - * its priority if it owns any priority - * protection or inheritence mutexes. - */ - PTHREAD_PRIOQ_INSERT_HEAD(pthread); - } - else - PTHREAD_PRIOQ_INSERT_TAIL(pthread); - } - - /* - * Check for any mutex priority adjustments. This - * includes checking for a priority mutex on which - * this thread is waiting. - */ - _mutex_notify_priochange(pthread); - } - - /* Set the scheduling policy: */ - pthread->attr.sched_policy = policy; - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_setsockopt.c b/lib/libpthread/uthread/uthread_setsockopt.c deleted file mode 100644 index b453b8bef11..00000000000 --- a/lib/libpthread/uthread/uthread_setsockopt.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: uthread_setsockopt.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_setsockopt.c,v 1.5 1999/08/28 00:03:47 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) -{ - int ret; - struct fd_table_entry *entry; - - ret = _thread_fd_table_init(fd, FD_INIT_UNKNOWN, NULL); - if (ret == 0) { - entry = _thread_fd_table[fd]; - - _thread_kern_sig_defer(); - if (entry->state == FD_ENTRY_OPEN) { - ret = _thread_sys_setsockopt(fd, level, optname, optval, optlen); - } else { - ret = -1; - errno = EBADF; - } - _thread_kern_sig_undefer(); - } - - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_shutdown.c b/lib/libpthread/uthread/uthread_shutdown.c deleted file mode 100644 index dcb7e38c42c..00000000000 --- a/lib/libpthread/uthread/uthread_shutdown.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: uthread_shutdown.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_shutdown.c,v 1.6 1999/08/28 00:03:48 peter Exp $ - */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -shutdown(int fd, int how) -{ - int ret; - struct fd_table_entry *entry; - - ret = _thread_fd_table_init(fd, FD_INIT_UNKNOWN, NULL); - if (ret == 0) { - entry = _thread_fd_table[fd]; - - _thread_kern_sig_defer(); - if (entry->state == FD_ENTRY_OPEN) { - ret = _thread_sys_shutdown(fd, how); - } else { - ret = -1; - errno = EBADF; - } - _thread_kern_sig_undefer(); - } - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sig.c b/lib/libpthread/uthread/uthread_sig.c deleted file mode 100644 index 08d3f7fc67f..00000000000 --- a/lib/libpthread/uthread/uthread_sig.c +++ /dev/null @@ -1,439 +0,0 @@ -/* $OpenBSD: uthread_sig.c,v 1.28 2011/10/07 08:59:43 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sig.c,v 1.20 1999/09/29 15:18:39 marcel Exp $ - */ -#include <string.h> -#include <signal.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - - -/* Initialize signal handling facility: */ -void -_thread_sig_init(void) -{ - int i; - - /* Clear local state */ - for (i = 1; i < NSIG; i++) { - _SPINLOCK_INIT(&_thread_sigq[i - 1].lock); - _thread_sigq[i - 1].pending = 0; - } -} - -/* - * This is the only installed signal handler. In addition to handling - * thread kernel signals it is installed in place of application handlers - * and dispatches signals appropriately. - */ -void -_thread_sig_handler(int sig, siginfo_t *info, struct sigcontext * scp) -{ - struct pthread *curthread = _get_curthread(); - int dispatch; - char c; - - if (sig == _SCHED_SIGNAL) { - /* Update the scheduling clock: */ - gettimeofday((struct timeval *)&_sched_tod, NULL); - _sched_ticks++; - - /* only process signal when scheduler isn't running */ - if (_thread_kern_in_sched == 0) { - if (curthread->sig_defer_count > 0) { - /* - * The scheduler interrupt has come when - * the currently running thread has deferred - * thread signals. - */ - curthread->yield_on_sig_undefer = 1; - } else { - /* Schedule the next thread. */ - _thread_kern_sched(scp); - - /* - * The scheduler currently returns here instead - * of calling sigreturn due to a sparc sigreturn - * bug. We should also return. That brings - * us back to the sigtramp code which will - * sigreturn to the context stored on the - * current stack (which is the same as scp, - * above). The code originally did this: - * - * PANIC("Returned to signal function " - * "from scheduler"); - */ - return; - } - } - } else { - /* - * save the info for this signal in a per signal queue of depth - * one. Per a POSIX suggestion, only the info for the first - * of multiple activations of the same signal is kept. - */ - _SPINLOCK(&_thread_sigq[sig - 1].lock); - if (_thread_sigq[sig - 1].pending == 0) { - sigaddset(&_process_sigpending, sig); - _thread_sigq[sig - 1].pending++; - memcpy(&_thread_sigq[sig - 1].siginfo, info, - sizeof *info); - } - _SPINUNLOCK(&_thread_sigq[sig - 1].lock); - - if ((_queue_signals != 0) || - ((_thread_kern_in_sched == 0) && - (curthread->sig_defer_count > 0))) { - /* - * The kernel has been interrupted while the scheduler - * is accessing the scheduling queues or there is a - * currently running thread that has deferred signals. - * - * Cast the signal number to a character variable - * and Write the signal number to the kernel pipe so - * that it will be ready to read when this signal - * handler returns. - */ - c = (char)sig; - _thread_sys_write(_thread_kern_pipe[1], &c, 1); - _sigq_check_reqd = 1; - } else { - _queue_signals = 1; - dispatch = _thread_sig_handle(sig, scp); - _queue_signals = 0; - if (dispatch) - _dispatch_signals(scp); - } - } -} - -/* - * Clear the pending flag for the given signal on all threads - * if per process, or only for the given thread if non null - * and the signal doesn't exist in _process_sigpending. - */ -void -_thread_clear_pending(int sig, pthread_t thread) -{ - pthread_t pthread; - - _thread_sigq[sig - 1].pending = 0; - if (sigismember(&_process_sigpending, sig)) { - sigdelset(&_process_sigpending, sig); - TAILQ_FOREACH(pthread, &_thread_list, tle) { - sigdelset(&pthread->sigpend, sig); - } - } else if (thread) - sigdelset(&thread->sigpend, sig); -} - -void -_thread_nonblock_fds(void) -{ - int i; - - /* - * Go through the file list and set all files to non-blocking - * again in case the child set some of them to block. Sigh. - */ - for (i = 0; i < _thread_max_fdtsize; i++) - if (_thread_fd_table[i] != NULL && - _thread_fd_table[i]->status_flags != NULL) - _thread_sys_fcntl(i, F_SETFL, - (_thread_fd_table[i]->status_flags->flags & ~_FD_NOTSOCK) | - O_NONBLOCK); -} - -/* - * Process the given signal. Returns 1 if the signal may be dispatched, - * otherwise 0. Signals MUST be defered when this function is called. - */ -/* ARGSUSED */ -int -_thread_sig_handle(int sig, struct sigcontext * scp) -{ - struct pthread *curthread = _get_curthread(); - pthread_t pthread, pthread_next; - - if (sig == SIGINFO) - _thread_dump_info(); /* Dump thread information */ - else if (sig == _SCHED_SIGNAL) - ; /* This shouldn't ever occur (should this panic?). */ - else { - if (sig == SIGCHLD) - _thread_nonblock_fds(); - - /* - * If the handler is SIG_IGN the signal never happened. - * remove it from the pending list and return. - */ - if (_thread_sigact[sig - 1].sa_handler == SIG_IGN) { - _thread_clear_pending(sig, curthread); - return 0; - } - - /* - * POSIX says that pending SIGCONT signals are discarded - * when one of these signals occurs and vice versa. - */ - if (sig == SIGSTOP || sig == SIGTSTP || sig == SIGTTIN || - sig == SIGTTOU) - _thread_clear_pending(SIGCONT, curthread); - if (sig == SIGCONT) { - _thread_clear_pending(SIGSTOP, curthread); - _thread_clear_pending(SIGTSTP, curthread); - _thread_clear_pending(SIGTTIN, curthread); - _thread_clear_pending(SIGTTOU, curthread); - } - - /* - * Enter a loop to process each thread in the waiting - * list that is sigwait-ing on a signal. Since POSIX - * doesn't specify which thread will get the signal - * if there are multiple waiters, we'll give it to the - * first one we find. - */ - for (pthread = TAILQ_FIRST(&_waitingq); - pthread != NULL; pthread = pthread_next) { - /* - * Grab the next thread before possibly destroying - * the link entry. - */ - pthread_next = TAILQ_NEXT(pthread, pqe); - - if ((pthread->state == PS_SIGWAIT) && - sigismember(pthread->data.sigwait, sig)) { - /* - * found a sigwaiter. Mark its state as - * running, save the signal that will be - * returned, and mark the signal as no - * longer pending. - */ - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - pthread->signo = sig; - _thread_clear_pending(sig, pthread); - return 0; - } - } - - /* - * mark the signal as pending for each thread - * and give the thread a chance to update - * its state. - */ - TAILQ_FOREACH(pthread, &_thread_list, tle) { - /* Current thread inside critical region? */ - if (curthread->sig_defer_count > 0) - pthread->sig_defer_count++; - _thread_signal(pthread,sig); - if (curthread->sig_defer_count > 0) - pthread->sig_defer_count--; - } - return 1; - } - return 0; -} - -/* Perform thread specific actions in response to a signal: */ -void -_thread_signal(pthread_t pthread, int sig) -{ - int interrupted = 1; - - /* Flag the signal as pending. It may be dispatched later. */ - sigaddset(&pthread->sigpend,sig); - - /* skip this thread if signal is masked */ - if (sigismember(&pthread->sigmask, sig)) - return; - - /* Process according to thread state: */ - switch (pthread->state) { - /* - * States which do not change when a signal is trapped: - */ - case PS_COND_WAIT: - case PS_DEAD: - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FILE_WAIT: - case PS_JOIN: - case PS_MUTEX_WAIT: - case PS_RUNNING: - case PS_SIGTHREAD: - case PS_SIGWAIT: - case PS_SUSPENDED: - case PS_SPINBLOCK: - case PS_DEADLOCK: - case PS_STATE_MAX: /* only here to quell a compiler warning */ - /* Nothing to do here. */ - break; - - /* - * The wait state is a special case due to the handling of - * SIGCHLD signals. - */ - case PS_WAIT_WAIT: - /* - * Check for signals other than the death of a child - * process: - */ - if (sig != SIGCHLD) - /* Flag the operation as interrupted: */ - pthread->interrupted = 1; - - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - break; - - /* - * States that are interrupted by the occurrence of a signal - * other than the scheduling alarm: - */ - case PS_FDR_WAIT: - case PS_FDW_WAIT: - if (_thread_sigact[sig - 1].sa_flags & SA_RESTART) - interrupted = 0; - /* FALLTHROUGH */ - - case PS_CONNECT_WAIT: - case PS_KEVENT_WAIT: - case PS_POLL_WAIT: - case PS_SLEEP_WAIT: - case PS_SELECT_WAIT: - if (sig != SIGCHLD || - _thread_sigact[sig - 1].sa_handler != SIG_DFL) { - /* Flag the operation as interrupted: */ - pthread->interrupted = interrupted; - - if (pthread->flags & PTHREAD_FLAGS_IN_WORKQ) - PTHREAD_WORKQ_REMOVE(pthread); - - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } - break; - - case PS_SIGSUSPEND: - /* - * Only wake up the thread if the signal is unblocked - * and there is a handler installed for the signal. - */ - if (_thread_sigact[sig - 1].sa_handler != SIG_DFL) { - /* Change the state of the thread to run: */ - PTHREAD_NEW_STATE(pthread,PS_RUNNING); - - /* Return the signal number: */ - pthread->signo = sig; - } - break; - } -} - -/* - * Dispatch a signal to the current thread after setting up the - * appropriate signal mask. - */ -void -_dispatch_signal(int sig, struct sigcontext * scp) -{ - struct pthread *curthread = _get_curthread(); - - sigset_t set; - sigset_t oset; - struct sigaction act; - void (*action)(int, siginfo_t *, void *); - - /* save off the action and set the signal mask */ - action = _thread_sigact[sig - 1].sa_sigaction; - set = _thread_sigact[sig - 1].sa_mask; - if ((_thread_sigact[sig-1].sa_flags & SA_NODEFER) == 0) - sigaddset(&set, sig); - oset = curthread->sigmask; - curthread->sigmask |= set; - - /* clear custom handler if SA_RESETHAND set. */ - if (_thread_sigact[sig - 1].sa_flags & SA_RESETHAND) { - act.sa_handler = SIG_DFL; - act.sa_flags = 0; - sigemptyset(&act.sa_mask); - sigaction(sig, &act, NULL); - } - - /* - * clear the pending flag, deliver the signal, then reset the - * signal mask - */ - _thread_clear_pending(sig, curthread); - (*action)(sig, &_thread_sigq[sig - 1].siginfo, scp); - curthread->sigmask = oset; -} - -/* - * possibly dispatch a signal to the current thread. - */ -void -_dispatch_signals(struct sigcontext * scp) -{ - struct pthread *curthread = _get_curthread(); - int i; - - /* - * Check if there are pending signals for the running - * thread that aren't blocked: - */ - if ((curthread->sigpend & ~curthread->sigmask) != 0) - /* Look for all possible pending signals: */ - for (i = 1; i < NSIG; i++) - /* - * Check that a custom handler is installed - * and if the signal is not blocked: - */ - if (_thread_sigact[i - 1].sa_handler != SIG_DFL && - _thread_sigact[i - 1].sa_handler != SIG_IGN && - sigismember(&curthread->sigpend,i) && - !sigismember(&curthread->sigmask,i)) - /* dispatch */ - _dispatch_signal(i, scp); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigaction.c b/lib/libpthread/uthread/uthread_sigaction.c deleted file mode 100644 index ef01871360e..00000000000 --- a/lib/libpthread/uthread/uthread_sigaction.c +++ /dev/null @@ -1,104 +0,0 @@ -/* $OpenBSD: uthread_sigaction.c,v 1.8 2003/09/22 21:39:35 miod Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigaction.c,v 1.8 1999/08/28 00:03:48 peter Exp $ - */ -#include <signal.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sigaction(int sig, const struct sigaction * act, struct sigaction * oact) -{ - int ret = 0; - struct sigaction gact; - - /* Check if the signal number is out of range: */ - if (sig < 1 || sig >= NSIG) { - /* Return an invalid argument: */ - errno = EINVAL; - ret = -1; - } else { - /* - * Check if the existing signal action structure contents are - * to be returned: - */ - if (oact != NULL) { - /* Return the existing signal action contents: */ - oact->sa_handler = _thread_sigact[sig - 1].sa_handler; - oact->sa_mask = _thread_sigact[sig - 1].sa_mask; - oact->sa_flags = _thread_sigact[sig - 1].sa_flags; - } - - /* Check if a signal action was supplied: */ - if (act != NULL) { - /* Set the new signal handler: */ - _thread_sigact[sig - 1].sa_mask = act->sa_mask; - _thread_sigact[sig - 1].sa_flags = act->sa_flags; - _thread_sigact[sig - 1].sa_handler = act->sa_handler; - } - - /* - * Check if the kernel needs to be advised of a change - * in signal action: - */ - if (act != NULL && sig != _SCHED_SIGNAL && sig != SIGCHLD && - sig != SIGINFO) { - gact.sa_mask = act->sa_mask; - sigaddset(&gact.sa_mask, _SCHED_SIGNAL); - gact.sa_flags = act->sa_flags | SA_SIGINFO; - - /* - * Check if the signal handler is being set to - * the default or ignore handlers: - */ - if (act->sa_handler == SIG_DFL || - act->sa_handler == SIG_IGN) - /* Specify the built in handler: */ - gact.sa_handler = act->sa_handler; - else - /* Specify the thread kernel signal handler */ - gact.sa_handler = - (void (*) (int)) _thread_sig_handler; - - /* Change the signal action in the kernel: */ - if (_thread_sys_sigaction(sig, &gact, NULL) != 0) - ret = -1; - } - } - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigaltstack.c b/lib/libpthread/uthread/uthread_sigaltstack.c deleted file mode 100644 index 93cfc1f0865..00000000000 --- a/lib/libpthread/uthread/uthread_sigaltstack.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: uthread_sigaltstack.c,v 1.3 2003/01/20 19:24:24 marc Exp $ */ -/* PUBLIC DOMAIN <marc@snafu.org */ - -#include <signal.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * IEEE Std 1003.1-2001 says: - * - * "Use of this function by library threads that are not bound to - * kernel-scheduled entities results in undefined behavior." - * - * There exists code (e.g. alpha setjmp) that uses this function - * to get information about the current stack. - * - * The "undefined behaviour" in this implementation is thus: - * o if ss is *not* null return -1 with errno set to EINVAL - * o if oss is *not* null fill it in with information about the - * current stack and return 0. - * - * This lets things like alpha setjmp work in threaded applications. - */ - -int -sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss) -{ - struct pthread *curthread = _get_curthread(); - - int ret = 0; - if (ss != NULL) { - errno = EINVAL; - ret = -1; - } else if (oss != NULL) { - /* - * get the requested info from the kernel if there is no - * thread or if the main thread (no thread stack). - */ - if (curthread == NULL || curthread->stack == NULL) - _thread_sys_sigaltstack(ss, oss); - else { - oss->ss_sp = curthread->stack->base; - oss->ss_size = curthread->stack->size; - oss->ss_flags = SS_DISABLE; - } - } - return (ret); -} -#endif /* _THREAD_SAFE */ diff --git a/lib/libpthread/uthread/uthread_sigblock.c b/lib/libpthread/uthread/uthread_sigblock.c deleted file mode 100644 index dd08126ce70..00000000000 --- a/lib/libpthread/uthread/uthread_sigblock.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: uthread_sigblock.c,v 1.3 1999/11/25 07:01:44 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigblock.c,v 1.4 1999/08/28 00:03:49 peter Exp $ - */ -#include <signal.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -_thread_sys_sigblock(int mask) -{ - int omask, n; - - n = _thread_sys_sigprocmask(SIG_BLOCK, (sigset_t *) & mask, (sigset_t *) & omask); - if (n) - return (n); - return (omask); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigmask.c b/lib/libpthread/uthread/uthread_sigmask.c deleted file mode 100644 index d44bfef7ae6..00000000000 --- a/lib/libpthread/uthread/uthread_sigmask.c +++ /dev/null @@ -1,100 +0,0 @@ -/* $OpenBSD: uthread_sigmask.c,v 1.9 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigmask.c,v 1.5 1999/09/29 15:18:40 marcel Exp $ - */ -#include <errno.h> -#include <signal.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) -{ - struct pthread *curthread = _get_curthread(); - sigset_t sigset; - int ret = 0; - - /* Check if the existing signal process mask is to be returned: */ - if (oset != NULL) { - /* Return the current mask: */ - *oset = curthread->sigmask; - } - /* Check if a new signal set was provided by the caller: */ - if (set != NULL) { - /* Process according to what to do: */ - switch (how) { - /* Block signals: */ - case SIG_BLOCK: - /* Add signals to the existing mask: */ - curthread->sigmask |= *set; - break; - - /* Unblock signals: */ - case SIG_UNBLOCK: - /* Clear signals from the existing mask: */ - curthread->sigmask &= ~(*set); - break; - - /* Set the signal process mask: */ - case SIG_SETMASK: - /* Set the new mask: */ - curthread->sigmask = *set; - break; - - /* Trap invalid actions: */ - default: - /* Return an invalid argument: */ - ret = EINVAL; - break; - } - - /* - * Check if there are pending signals for the running - * thread or process that aren't blocked: - */ - sigset = curthread->sigpend; - sigset |= _process_sigpending; - sigset &= ~curthread->sigmask; - if (sigset != 0) - /* - * Call the kernel scheduler which will safely - * install a signal frame for the running thread: - */ - _thread_kern_sched(NULL); - } - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_signal.c b/lib/libpthread/uthread/uthread_signal.c deleted file mode 100644 index 3cc2373fc64..00000000000 --- a/lib/libpthread/uthread/uthread_signal.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_signal.c,v 1.5 2002/10/30 19:11:56 marc Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_signal.c,v 1.4 1999/08/28 00:03:49 peter Exp $ - */ -#include <signal.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -sig_t -_thread_sys_signal(int s, sig_t a) -{ - struct sigaction sa; - struct sigaction osa; - - /* Initialise the signal action structure: */ - sigemptyset(&sa.sa_mask); - sa.sa_handler = a; - sa.sa_flags = SA_SIGINFO; - - /* Perform the sigaction syscall: */ - if (_thread_sys_sigaction(s, &sa, &osa) < 0) { - /* Return an error: */ - return (SIG_ERR); - } - /* Return a pointer to the old signal handler: */ - return (osa.sa_handler); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigpending.c b/lib/libpthread/uthread/uthread_sigpending.c deleted file mode 100644 index 911d1b4b891..00000000000 --- a/lib/libpthread/uthread/uthread_sigpending.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: uthread_sigpending.c,v 1.3 2001/08/21 19:24:53 fgsch Exp $ */ -/* - * Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigpending.c,v 1.3 1999/08/28 00:03:50 peter Exp $ - */ -#include <signal.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sigpending(sigset_t * set) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - - /* Check for a null signal set pointer: */ - if (set == NULL) { - /* Return an invalid argument: */ - ret = EINVAL; - } - else { - *set = curthread->sigpend; - } - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigprocmask.c b/lib/libpthread/uthread/uthread_sigprocmask.c deleted file mode 100644 index 658fe84cd9b..00000000000 --- a/lib/libpthread/uthread/uthread_sigprocmask.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: uthread_sigprocmask.c,v 1.5 2008/04/24 03:31:33 kurt Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigprocmask.c,v 1.6 1999/09/29 15:18:40 marcel Exp $ - */ -#include <signal.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sigprocmask(int how, const sigset_t *set, sigset_t *oset) -{ - int ret; - - ret = pthread_sigmask(how, set, oset); - if (ret != 0) - { - errno = ret; - ret = -1; - } - return ret; -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigsetmask.c b/lib/libpthread/uthread/uthread_sigsetmask.c deleted file mode 100644 index 878efe36add..00000000000 --- a/lib/libpthread/uthread/uthread_sigsetmask.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: uthread_sigsetmask.c,v 1.3 1999/11/25 07:01:45 d Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigsetmask.c,v 1.4 1999/08/28 00:03:50 peter Exp $ - */ -#include <signal.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -_thread_sys_sigsetmask(int mask) -{ - int omask, n; - - n = _thread_sys_sigprocmask(SIG_SETMASK, (sigset_t *) & mask, (sigset_t *) & omask); - if (n) - return (n); - return (omask); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigsuspend.c b/lib/libpthread/uthread/uthread_sigsuspend.c deleted file mode 100644 index bbf9c7c9870..00000000000 --- a/lib/libpthread/uthread/uthread_sigsuspend.c +++ /dev/null @@ -1,76 +0,0 @@ -/* $OpenBSD: uthread_sigsuspend.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigsuspend.c,v 1.7 1999/08/28 00:03:50 peter Exp $ - */ -#include <signal.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sigsuspend(const sigset_t * set) -{ - struct pthread *curthread = _get_curthread(); - int ret = -1; - sigset_t oset; - - _thread_enter_cancellation_point(); - - /* Check if a new signal set was provided by the caller: */ - if (set != NULL) { - /* Save the current signal mask: */ - oset = curthread->sigmask; - - /* Change the caller's mask: */ - curthread->sigmask = *set; - - /* Wait for a signal: */ - _thread_kern_sched_state(PS_SIGSUSPEND, __FILE__, __LINE__); - - /* Always return an interrupted error: */ - errno = EINTR; - - /* Restore the signal mask: */ - curthread->sigmask = oset; - } else { - /* Return an invalid argument error: */ - errno = EINVAL; - } - - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_sigwait.c b/lib/libpthread/uthread/uthread_sigwait.c deleted file mode 100644 index 3b11c001352..00000000000 --- a/lib/libpthread/uthread/uthread_sigwait.c +++ /dev/null @@ -1,174 +0,0 @@ -/* $OpenBSD: uthread_sigwait.c,v 1.13 2003/01/31 04:46:17 marc Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_sigwait.c,v 1.10 1999/09/30 14:51:31 marcel Exp $ - */ -#include <signal.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sigwait(const sigset_t * set, int *sig) -{ - struct pthread *curthread = _get_curthread(); - int ret = 0; - int i; - sigset_t tempset, waitset; - struct sigaction act; - - _thread_enter_cancellation_point(); - - /* - * Specify the thread kernel signal handler. - */ - act.sa_handler = (void (*) (int)) _thread_sig_handler; - act.sa_flags = SA_SIGINFO | SA_RESTART; - - /* Ensure the signal handler cannot be interrupted by other signals: */ - sigfillset(&act.sa_mask); - - /* - * Initialize the set of signals that will be waited on: - */ - waitset = *set; - - /* These signals can't be waited on. */ - sigdelset(&waitset, SIGKILL); - sigdelset(&waitset, SIGSTOP); - sigdelset(&waitset, _SCHED_SIGNAL); - sigdelset(&waitset, SIGCHLD); - sigdelset(&waitset, SIGINFO); - - /* Check to see if a pending signal is in the wait mask. */ - tempset = curthread->sigpend; - tempset |= _process_sigpending; - tempset &= waitset; - if (tempset != 0) { - /* Enter a loop to find a pending signal: */ - for (i = 1; i < NSIG; i++) { - if (sigismember(&tempset, i)) - break; - } - - /* Clear the pending signal: */ - _thread_clear_pending(i, curthread); - - /* Return the signal number to the caller: */ - *sig = i; - - _thread_leave_cancellation_point(); - return (0); - } - - /* - * Access the _thread_dfl_count array under the protection of signal - * deferral. - */ - _thread_kern_sig_defer(); - - /* - * Enter a loop to find the signals that are SIG_DFL. For - * these signals we must install a dummy signal handler in - * order for the kernel to pass them in to us. POSIX says - * that the _application_ must explicitly install a dummy - * handler for signals that are SIG_IGN in order to sigwait - * on them. Note that SIG_IGN signals are left in the - * mask because a subsequent sigaction could enable an - * ignored signal. - */ - sigemptyset(&tempset); - for (i = 1; i < NSIG; i++) { - if (sigismember(&waitset, i) && - (_thread_sigact[i - 1].sa_handler == SIG_DFL)) { - _thread_dfl_count[i]++; - sigaddset(&tempset, i); - if (_thread_dfl_count[i] == 1) { - if (_thread_sys_sigaction(i, &act, NULL) != 0) - ret = -1; - } - } - } - - /* Done accessing _thread_dfl_count for now. */ - _thread_kern_sig_undefer(); - - if (ret == 0) { - /* - * Save the wait signal mask. The wait signal - * mask is independent of the threads signal mask - * and requires separate storage. - */ - curthread->data.sigwait = &waitset; - - /* Wait for a signal: */ - _thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__); - - /* Return the signal number to the caller: */ - *sig = curthread->signo; - - /* - * Probably unnecessary, but since it's in a union struct - * we don't know how it could be used in the future. - */ - curthread->data.sigwait = NULL; - } - - /* - * Access the _thread_dfl_count array under the protection of signal - * deferral. - */ - _thread_kern_sig_defer(); - - /* Restore the sigactions: */ - act.sa_handler = SIG_DFL; - for (i = 1; i < NSIG; i++) { - if (sigismember(&tempset, i)) { - _thread_dfl_count[i]--; - if ((_thread_sigact[i - 1].sa_handler == SIG_DFL) && - (_thread_dfl_count[i] == 0)) { - if (_thread_sys_sigaction(i, &act, NULL) != 0) - ret = -1; - } - } - } - - /* Done accessing _thread_dfl_count. */ - _thread_kern_sig_undefer(); - - _thread_leave_cancellation_point(); - - /* Return the completion status: */ - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_single_np.c b/lib/libpthread/uthread/uthread_single_np.c deleted file mode 100644 index 242ebd92fa8..00000000000 --- a/lib/libpthread/uthread/uthread_single_np.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: uthread_single_np.c,v 1.5 2002/11/07 02:56:20 marc Exp $ */ -/* - * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_single_np.c,v 1.3 1999/08/28 00:03:51 peter Exp $ - */ -#include <string.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -pthread_single_np() -{ - struct pthread *curthread = _get_curthread(); - - /* Enter single-threaded (non-POSIX) scheduling mode: */ - _thread_single = curthread; - return(0); -} -#endif diff --git a/lib/libpthread/uthread/uthread_socket.c b/lib/libpthread/uthread/uthread_socket.c deleted file mode 100644 index f43564060e3..00000000000 --- a/lib/libpthread/uthread/uthread_socket.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: uthread_socket.c,v 1.5 2006/09/26 14:18:28 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_socket.c,v 1.5 1999/08/28 00:03:51 peter Exp $ - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -socket(int af, int type, int protocol) -{ - int fd; - - /* Create a socket: */ - if ((fd = _thread_sys_socket(af, type, protocol)) < 0) { - /* Error creating socket. */ - - /* Initialise the entry in the file descriptor table: */ - } else if (_thread_fd_table_init(fd, FD_INIT_NEW, NULL) != 0) { - _thread_sys_close(fd); - fd = -1; - } - return (fd); -} -#endif diff --git a/lib/libpthread/uthread/uthread_socketpair.c b/lib/libpthread/uthread/uthread_socketpair.c deleted file mode 100644 index 60f7db40338..00000000000 --- a/lib/libpthread/uthread/uthread_socketpair.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD: uthread_socketpair.c,v 1.6 2006/09/26 14:18:28 kurt Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_socketpair.c,v 1.6 1999/08/28 00:03:52 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/socket.h> -#include <fcntl.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -socketpair(int af, int type, int protocol, int pair[2]) -{ - int ret; - if (!((ret = _thread_sys_socketpair(af, type, protocol, pair)) < 0)) - if (_thread_fd_table_init(pair[0], FD_INIT_NEW, NULL) != 0 || - _thread_fd_table_init(pair[1], FD_INIT_NEW, NULL) != 0) { - _thread_sys_close(pair[0]); - _thread_sys_close(pair[1]); - ret = -1; - } - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_spec.c b/lib/libpthread/uthread/uthread_spec.c deleted file mode 100644 index 2e2e9c96303..00000000000 --- a/lib/libpthread/uthread/uthread_spec.c +++ /dev/null @@ -1,212 +0,0 @@ -/* $OpenBSD: uthread_spec.c,v 1.12 2011/07/05 00:42:46 tedu Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_spec.c,v 1.13 1999/08/28 00:03:52 peter Exp $ - */ -#include <signal.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* Static variables: */ -static struct pthread_key key_table[PTHREAD_KEYS_MAX]; - -void -_thread_key_init(void) -{ - int key; - - for (key = 0; key < PTHREAD_KEYS_MAX; key++) - _SPINLOCK_INIT(&key_table[key].lock); -} - -int -pthread_key_create(pthread_key_t * key, void (*destructor) (void *)) -{ - for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) { - /* Lock the key table entry: */ - _SPINLOCK(&key_table[*key].lock); - - if (key_table[(*key)].allocated == 0) { - key_table[(*key)].allocated = 1; - key_table[(*key)].destructor = destructor; - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[*key].lock); - return (0); - } - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[*key].lock); - } - return (EAGAIN); -} - -int -pthread_key_delete(pthread_key_t key) -{ - int ret = 0; - pthread_t pthread; - - if (key >= 0 && key < PTHREAD_KEYS_MAX) { - /* Lock the key table entry: */ - _SPINLOCK(&key_table[key].lock); - - if (key_table[key].allocated) { - key_table[key].allocated = 0; - - _thread_kern_sig_defer(); - TAILQ_FOREACH(pthread, &_thread_list, tle) { - if (pthread->specific_data != NULL && - pthread->specific_data[key]) { - pthread->specific_data[key] = NULL; - pthread->specific_data_count--; - } - } - _thread_kern_sig_undefer(); - } else - ret = EINVAL; - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[key].lock); - - } else - ret = EINVAL; - return (ret); -} - -void -_thread_cleanupspecific(void) -{ - struct pthread *curthread = _get_curthread(); - void *data; - int key; - int itr; - void (*destructor)( void *); - - for (itr = 0; itr < PTHREAD_DESTRUCTOR_ITERATIONS; itr++) { - for (key = 0; key < PTHREAD_KEYS_MAX; key++) { - if (curthread->specific_data_count) { - /* Lock the key table entry: */ - _SPINLOCK(&key_table[key].lock); - destructor = data = NULL; - - if (key_table[key].allocated) { - if (curthread->specific_data[key]) { - data = (void *) curthread->specific_data[key]; - curthread->specific_data[key] = NULL; - curthread->specific_data_count--; - destructor = key_table[key].destructor; - } - } - - /* Unlock the key table entry: */ - _SPINUNLOCK(&key_table[key].lock); - - /* - * If there is a destructore, call it - * with the key table entry unlocked: - */ - if (destructor) - destructor(data); - } else { - free(curthread->specific_data); - curthread->specific_data = NULL; - return; - } - } - } - free(curthread->specific_data); - curthread->specific_data = NULL; -} - -static inline const void ** -pthread_key_allocate_data(void) -{ - return calloc(PTHREAD_KEYS_MAX, sizeof(void *)); -} - -int -pthread_setspecific(pthread_key_t key, const void *value) -{ - struct pthread *pthread; - int ret = EINVAL; - - /* Point to the running thread: */ - pthread = _get_curthread(); - - if ((pthread->specific_data) || - (pthread->specific_data = pthread_key_allocate_data())) { - if (key >= 0 && key < PTHREAD_KEYS_MAX) { - if (key_table[key].allocated) { - if (pthread->specific_data[key] == NULL) { - if (value != NULL) - pthread->specific_data_count++; - } else { - if (value == NULL) - pthread->specific_data_count--; - } - pthread->specific_data[key] = value; - ret = 0; - } - } - } else { - ret = ENOMEM; - } - return (ret); -} - -void * -pthread_getspecific(pthread_key_t key) -{ - struct pthread *pthread; - void *data = NULL; - - /* Point to the running thread: */ - pthread = _get_curthread(); - - /* Check if there is specific data: */ - if (pthread->specific_data != NULL && - key >= 0 && key < PTHREAD_KEYS_MAX) { - /* Check if this key has been used before: */ - if (key_table[key].allocated) { - /* Return the value: */ - data = (void *)pthread->specific_data[key]; - } - } - - return (data); -} -#endif diff --git a/lib/libpthread/uthread/uthread_spinlock.c b/lib/libpthread/uthread/uthread_spinlock.c deleted file mode 100644 index 12742f5708a..00000000000 --- a/lib/libpthread/uthread/uthread_spinlock.c +++ /dev/null @@ -1,109 +0,0 @@ -/* $OpenBSD: uthread_spinlock.c,v 1.13 2003/01/31 04:46:17 marc Exp $ */ -/* - * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_spinlock.c,v 1.7 1999/08/28 00:03:52 peter Exp $ - * - */ - -#include <stdio.h> -#include <sched.h> -#include <unistd.h> -#include <pthread.h> -#include <string.h> -#include "pthread_private.h" - -extern char *__progname; - -/* - * Lock a location for the running thread. Yield to allow other - * threads to run if this thread is blocked because the lock is - * not available. - */ -void -_spinlock(spinlock_t *lck) -{ - struct pthread *curthread = _get_curthread(); - - /* - * Try to grab the lock and loop if another thread grabs - * it before we do. - */ - while(_atomic_lock(&lck->access_lock)) { - /* Block the thread until the lock. */ - curthread->data.spinlock = lck; - _thread_kern_sched_state(PS_SPINBLOCK, __FILE__, __LINE__); - } - - /* The running thread now owns the lock: */ - lck->lock_owner = curthread; -} - -/* - * Lock a location for the running thread. Yield to allow other - * threads to run if this thread is blocked because the lock is - * not available. Note that this function does not sleep. It - * assumes that the lock will be available very soon. - * - * This function checks if the running thread has already locked the - * location, warns if this occurs and creates a thread dump before - * returning. - */ -void -_spinlock_debug(spinlock_t *lck, const char *fname, int lineno) -{ - struct pthread *curthread = _get_curthread(); - int cnt = 0; - - /* - * Try to grab the lock and loop if another thread grabs - * it before we do. - */ - while(_atomic_lock(&lck->access_lock)) { - cnt++; - if (cnt > 100) { - char str[256]; - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); - _thread_sys_write(2,str,strlen(str)); - sleep(1); - cnt = 0; - } - - /* Block the thread until the lock. */ - curthread->data.spinlock = lck; - _thread_kern_sched_state(PS_SPINBLOCK, fname, lineno); - } - - /* The running thread now owns the lock: */ - lck->lock_owner = curthread; - lck->fname = fname; - lck->lineno = lineno; -} diff --git a/lib/libpthread/uthread/uthread_stack.c b/lib/libpthread/uthread/uthread_stack.c deleted file mode 100644 index 2212a0a87d2..00000000000 --- a/lib/libpthread/uthread/uthread_stack.c +++ /dev/null @@ -1,122 +0,0 @@ -/* $OpenBSD: uthread_stack.c,v 1.11 2008/12/18 09:30:32 guenther Exp $ */ -/* - * Copyright 1999, David Leonard. All rights reserved. - * <insert BSD-style license&disclaimer> - */ - -/* - * Thread stack allocation. - * - * If stack pointers grow down, towards the beginning of stack storage, - * the first page of the storage is protected using mprotect() so as - * to generate a SIGSEGV if a thread overflows its stack. Similarly, - * for stacks that grow up, the last page of the storage is protected. - */ - -#include <stddef.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/user.h> -#include <sys/mman.h> -#include <pthread.h> -#include <pthread_np.h> -#include "pthread_private.h" - -struct stack * -_thread_stack_alloc(void *base, size_t size, size_t guardsize) -{ - struct stack *stack; - size_t nbpg = (size_t)getpagesize(); - - /* Maintain a stack of default-sized stacks that we can re-use. */ - if (base == NULL && size == PTHREAD_STACK_DEFAULT - && guardsize == pthread_attr_default.guardsize_attr) { - if (pthread_mutex_lock(&_gc_mutex) != 0) - PANIC("Cannot lock gc mutex"); - - if ((stack = SLIST_FIRST(&_stackq)) != NULL) { - SLIST_REMOVE_HEAD(&_stackq, qe); - if (pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - return stack; - } - if (pthread_mutex_unlock(&_gc_mutex) != 0) - PANIC("Cannot unlock gc mutex"); - } - - /* Allocate some storage to hold information about the stack: */ - stack = (struct stack *)malloc(sizeof (struct stack)); - if (stack == NULL) - return NULL; - - if (base != NULL) { - /* Use the user's storage */ - stack->base = base; - stack->size = size; - stack->guardsize = 0; - stack->redzone = NULL; - stack->storage = NULL; - return stack; - } - - /* Round sizes up to closest page boundry */ - size = ((size + (nbpg - 1)) / nbpg) * nbpg; - guardsize = ((guardsize + (nbpg - 1)) / nbpg) * nbpg; - - /* overflow? */ - if (SIZE_MAX - size < guardsize) { - free(stack); - return NULL; - } - - /* mmap storage for the stack, possibly with page(s) for redzone */ - stack->storage = mmap(NULL, size + guardsize, PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, -1, 0); - if (stack->storage == MAP_FAILED) { - free(stack); - return NULL; - } - - /* - * Compute the location of the red zone. - */ -#if defined(MACHINE_STACK_GROWS_UP) - /* Red zone is the last page of the storage: */ - stack->redzone = (caddr_t)stack->storage + (ptrdiff_t)size; - stack->base = stack->storage; - stack->size = size; - stack->guardsize = guardsize; -#else - /* Red zone is the first page of the storage: */ - stack->redzone = stack->storage; - stack->base = (caddr_t)stack->redzone + (ptrdiff_t)guardsize; - stack->size = size; - stack->guardsize = guardsize; -#endif - if (!guardsize) - stack->redzone = NULL; - else if (mprotect(stack->redzone, guardsize, PROT_NONE) == -1) - PANIC("Cannot protect stack red zone"); - - return stack; -} - -void -_thread_stack_free(stack) - struct stack *stack; -{ - /* Cache allocated stacks of default size: */ - if (stack->storage != NULL && stack->size == PTHREAD_STACK_DEFAULT - && stack->guardsize == pthread_attr_default.guardsize_attr) - SLIST_INSERT_HEAD(&_stackq, stack, qe); - else { - /* unmap storage: */ - if (stack->storage) - munmap(stack->storage, stack->size + stack->guardsize); - - /* Free stack information storage: */ - free(stack); - } -} diff --git a/lib/libpthread/uthread/uthread_stackseg_np.c b/lib/libpthread/uthread/uthread_stackseg_np.c deleted file mode 100644 index c2a981c3a57..00000000000 --- a/lib/libpthread/uthread/uthread_stackseg_np.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: uthread_stackseg_np.c,v 1.6 2007/07/08 01:53:46 kurt Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/lock.h> -#include <sys/resource.h> -#include <sys/queue.h> - -#include <errno.h> -#include <pthread.h> -#include <pthread_np.h> -#include <stddef.h> -#include <unistd.h> - -#include <uvm/uvm_extern.h> - -#include "pthread_private.h" - -/* - * Return stack info from the given thread. Based upon the solaris - * thr_stksegment function. - */ - -int -pthread_stackseg_np(pthread_t thread, stack_t *sinfo) -{ - char *base; - size_t pgsz; - int ret; - struct rlimit rl; - - if (thread->stack) { - base = thread->stack->base; -#if !defined(MACHINE_STACK_GROWS_UP) - base += (ptrdiff_t)thread->stack->size; -#endif - sinfo->ss_sp = base; - sinfo->ss_size = thread->stack->size; - sinfo->ss_flags = 0; - ret = 0; - } else if (thread == _thread_initial) { - if (getrlimit(RLIMIT_STACK, &rl) != 0) - return (EAGAIN); - pgsz = (size_t)sysconf(_SC_PAGESIZE); - if (pgsz == (size_t)-1) - return (EAGAIN); - /* - * round_page() stack rlim_cur and - * trunc_page() USRSTACK to be consistent with - * the way the kernel sets up the stack. - */ - sinfo->ss_size = (size_t)rl.rlim_cur; - sinfo->ss_size += (pgsz - 1); - sinfo->ss_size &= ~(pgsz - 1); - sinfo->ss_sp = (caddr_t) (USRSTACK & ~(pgsz - 1)); - sinfo->ss_flags = 0; - ret = 0; - } else - ret = EAGAIN; - - return ret; -} diff --git a/lib/libpthread/uthread/uthread_suspend_np.c b/lib/libpthread/uthread/uthread_suspend_np.c deleted file mode 100644 index fe2a1adb941..00000000000 --- a/lib/libpthread/uthread/uthread_suspend_np.c +++ /dev/null @@ -1,205 +0,0 @@ -/* $OpenBSD: uthread_suspend_np.c,v 1.12 2011/10/07 08:59:43 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_suspend_np.c,v 1.7 1999/08/28 00:03:53 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -static void suspend_common(struct pthread *thread); -static void finish_suspension(struct pthread *); - -/* Suspend a thread: */ -int -pthread_suspend_np(pthread_t thread) -{ - int ret; - - /* Suspending the current thread doesn't make sense. */ - if (thread == _get_curthread()) - ret = EDEADLK; - - /* Find the thread in the list of active threads: */ - else if ((ret = _find_thread(thread)) == 0) { - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - suspend_common(thread); - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); - } - return(ret); -} - -void -pthread_suspend_all_np(void) -{ - struct pthread *curthread = _get_curthread(); - struct pthread *thread; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - - TAILQ_FOREACH(thread, &_thread_list, tle) { - if (thread != curthread) - suspend_common(thread); - } - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); -} - -static void -suspend_common(struct pthread *thread) -{ - switch (thread->state) { - case PS_RUNNING: - /* - * Remove the thread from the priority queue and - * set the state to suspended: - */ - PTHREAD_PRIOQ_REMOVE(thread); - PTHREAD_SET_STATE(thread, PS_SUSPENDED); - break; - - case PS_CONNECT_WAIT: - case PS_FDR_WAIT: - case PS_FDW_WAIT: - case PS_KEVENT_WAIT: - /* - * Remove these threads from the work queue - * and set the state to suspended: - */ - if ((thread->flags & PTHREAD_FLAGS_IN_WORKQ) != 0) - PTHREAD_WORKQ_REMOVE(thread); - PTHREAD_WAITQ_REMOVE(thread); - PTHREAD_SET_STATE(thread, PS_SUSPENDED); - break; - - case PS_SPINBLOCK: - case PS_POLL_WAIT: - case PS_SELECT_WAIT: - /* - * Remove these threads from the work queue - * and mark the operation as interrupted: - */ - if ((thread->flags & PTHREAD_FLAGS_IN_WORKQ) != 0) - PTHREAD_WORKQ_REMOVE(thread); - _thread_seterrno(thread, EINTR); - - /* FALLTHROUGH */ - case PS_SLEEP_WAIT: - thread->interrupted = 1; - - /* FALLTHROUGH */ - case PS_SIGTHREAD: - case PS_WAIT_WAIT: - case PS_SIGSUSPEND: - case PS_SIGWAIT: - /* - * Remove these threads from the waiting queue and - * set their state to suspended: - */ - PTHREAD_WAITQ_REMOVE(thread); - PTHREAD_SET_STATE(thread, PS_SUSPENDED); - break; - - case PS_MUTEX_WAIT: - /* Mark the thread as suspended and still in a queue. */ - thread->suspended = SUSP_MUTEX_WAIT; - - PTHREAD_SET_STATE(thread, PS_SUSPENDED); - break; - case PS_COND_WAIT: - /* Mark the thread as suspended and still in a queue. */ - thread->suspended = SUSP_COND_WAIT; - - PTHREAD_SET_STATE(thread, PS_SUSPENDED); - break; - case PS_JOIN: - /* Mark the thread as suspended and joining: */ - thread->suspended = SUSP_JOIN; - - PTHREAD_NEW_STATE(thread, PS_SUSPENDED); - break; - case PS_FDLR_WAIT: - case PS_FDLW_WAIT: - case PS_FILE_WAIT: - /* Mark the thread as suspended: */ - thread->suspended = SUSP_YES; - - /* - * Threads in these states may be in queues. - * In order to preserve queue integrity, the - * cancelled thread must remove itself from the - * queue. Mark the thread as interrupted and - * set the state to running. When the thread - * resumes, it will remove itself from the queue - * and call the suspension completion routine. - */ - thread->interrupted = 1; - _thread_seterrno(thread, EINTR); - PTHREAD_NEW_STATE(thread, PS_RUNNING); - thread->continuation = finish_suspension; - break; - - case PS_DEAD: - case PS_DEADLOCK: - case PS_STATE_MAX: - case PS_SUSPENDED: - /* Nothing needs to be done: */ - break; - } -} - -static void -finish_suspension(struct pthread *curthread) -{ - if (curthread->suspended != SUSP_NO) - _thread_kern_sched_state(PS_SUSPENDED, __FILE__, __LINE__); -} -#endif diff --git a/lib/libpthread/uthread/uthread_switch_np.c b/lib/libpthread/uthread/uthread_switch_np.c deleted file mode 100644 index 2e7351b9697..00000000000 --- a/lib/libpthread/uthread/uthread_switch_np.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $OpenBSD: uthread_switch_np.c,v 1.2 1999/11/25 07:01:46 d Exp $ */ -/* - * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Daniel Eischen. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_switch_np.c,v 1.3 1999/08/28 00:03:53 peter Exp $ - */ -#include <errno.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include <pthread_np.h> -#include "pthread_private.h" - - -int -pthread_switch_add_np(pthread_switch_routine_t routine) -{ - int ret = 0; - - if (routine == NULL) - /* Return an invalid argument error: */ - ret = EINVAL; - else - /* Shouldn't need a lock to protect this assigment. */ - _sched_switch_hook = routine; - - return(ret); -} - -int -pthread_switch_delete_np(pthread_switch_routine_t routine) -{ - int ret = 0; - - if (routine != _sched_switch_hook) - /* Return an invalid argument error: */ - ret = EINVAL; - else - /* Shouldn't need a lock to protect this assigment. */ - _sched_switch_hook = NULL; - - return(ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_vfork.c b/lib/libpthread/uthread/uthread_vfork.c deleted file mode 100644 index 3427191dcb6..00000000000 --- a/lib/libpthread/uthread/uthread_vfork.c +++ /dev/null @@ -1,31 +0,0 @@ -/* $OpenBSD: uthread_vfork.c,v 1.5 2008/10/02 23:27:24 deraadt Exp $ */ -/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ - -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -pid_t _dofork(int vfork); - -pid_t -vfork(void) -{ - pid_t pid; - - /* - * Defer signals to protect the scheduling queues from access - * by the signal handler: - */ - _thread_kern_sig_defer(); - - pid = _dofork(1); - - /* - * Undefer and handle pending signals, yielding if necessary: - */ - _thread_kern_sig_undefer(); - - return (pid); -} -#endif diff --git a/lib/libpthread/uthread/uthread_wait4.c b/lib/libpthread/uthread/uthread_wait4.c deleted file mode 100644 index 51534808d0c..00000000000 --- a/lib/libpthread/uthread/uthread_wait4.c +++ /dev/null @@ -1,91 +0,0 @@ -/* $OpenBSD: uthread_wait4.c,v 1.7 2001/11/09 00:20:26 marc Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_wait4.c,v 1.5 1999/08/28 00:03:53 peter Exp $ - */ -#include <errno.h> -#include <sys/wait.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -/* - * Note: a thread calling wait4 may have its state changed to waiting - * until awakened by a signal. Also note that system(3), for example, - * blocks SIGCHLD and calls waitpid (which calls wait4). If the process - * started by system(3) doesn't finish before this function is called the - * function will never awaken -- system(3) also ignores SIGINT and SIGQUIT. - * - * Thus always unmask SIGCHLD here. - */ -pid_t -wait4(pid_t pid, int *istat, int options, struct rusage * rusage) -{ - struct pthread *curthread = _get_curthread(); - pid_t ret; - sigset_t mask, omask; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - _thread_kern_sig_defer(); - - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - sigprocmask(SIG_UNBLOCK, &mask, &omask); - - /* Perform a non-blocking wait4 syscall: */ - while ((ret = _thread_sys_wait4(pid, istat, options | WNOHANG, rusage)) == 0 && (options & WNOHANG) == 0) { - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - - /* Schedule the next thread while this one waits: */ - _thread_kern_sched_state(PS_WAIT_WAIT, __FILE__, __LINE__); - - /* Check if this call was interrupted by a signal: */ - if (curthread->interrupted) { - errno = EINTR; - ret = -1; - break; - } - } - - sigprocmask(SIG_SETMASK, &omask, NULL); - - _thread_kern_sig_undefer(); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_write.c b/lib/libpthread/uthread/uthread_write.c deleted file mode 100644 index 642572022e9..00000000000 --- a/lib/libpthread/uthread/uthread_write.c +++ /dev/null @@ -1,174 +0,0 @@ -/* $OpenBSD: uthread_write.c,v 1.14 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_write.c,v 1.12 1999/08/28 00:03:54 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <stddef.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -write(int fd, const void *buf, size_t nbytes) -{ - struct pthread *curthread = _get_curthread(); - int blocking; - int type; - size_t num = 0; - ssize_t n; - ssize_t ret; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* POSIX says to do just this: */ - if (nbytes == 0) - ret = 0; - else if (nbytes > SSIZE_MAX) { - errno = EINVAL; - ret = -1; - /* Lock the file descriptor for write: */ - } else if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_table[fd]->status_flags->flags & O_ACCMODE; - - /* Check if the file is not open for write: */ - if (type != O_WRONLY && type != O_RDWR) { - /* File is not open for write: */ - errno = EBADF; - ret = -1; - } - - else { - /* Check if file operations are to block */ - blocking = ((_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) == 0); - - /* - * Loop while no error occurs and until the expected number - * of bytes are written if performing a blocking write: - */ - while (ret == 0) { - /* Perform a non-blocking write syscall: */ - n = _thread_sys_write(fd, (caddr_t)buf + (ptrdiff_t)num, - nbytes - num); - - /* Check if one or more bytes were written: */ - if (n > 0) - /* - * Keep a count of the number of bytes - * written: - */ - num += (size_t)n; - - /* - * If performing a blocking write, check if the - * write would have blocked or if some bytes - * were written but there are still more to - * write: - */ - if (blocking && ((n < 0 && (errno == EWOULDBLOCK || - errno == EAGAIN)) || (n > 0 && num < nbytes))) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(_FD_SNDTIMEO(fd)); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - - _thread_kern_sched_state(PS_FDW_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal - */ - if (curthread->interrupted || - curthread->closing_fd || - curthread->timeout) { - if (num > 0) { - /* Return partial success: */ - ret = (ssize_t)num; - } else { - /* Return an error: */ - if (curthread->closing_fd) - errno = EBADF; - else if (curthread->interrupted) - errno = EINTR; - else - errno = EWOULDBLOCK; - ret = -1; - } - } - - /* - * If performing a non-blocking write, - * just return whatever the write syscall did: - */ - } else if (!blocking) { - /* A non-blocking call might return zero: */ - ret = n; - break; - - /* - * If there was an error, return partial success - * (if any bytes were written) or else the error: - */ - } else if (n <= 0) { - if (num > 0) - ret = (ssize_t)num; - else - ret = n; - if (n == 0) - break; - - /* Check if the write has completed: */ - } else if (num >= nbytes) - /* Return the number of bytes written: */ - ret = (ssize_t)num; - } - } - _FD_UNLOCK(fd, FD_WRITE); - } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_writev.c b/lib/libpthread/uthread/uthread_writev.c deleted file mode 100644 index 6c3d41c14f4..00000000000 --- a/lib/libpthread/uthread/uthread_writev.c +++ /dev/null @@ -1,246 +0,0 @@ -/* $OpenBSD: uthread_writev.c,v 1.14 2010/01/03 23:05:35 fgsch Exp $ */ -/* - * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_writev.c,v 1.12 1999/08/28 00:03:55 peter Exp $ - * - */ -#include <sys/types.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <errno.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -ssize_t -writev(int fd, const struct iovec * iov, int iovcnt) -{ - struct pthread *curthread = _get_curthread(); - int blocking; - int idx = 0; - int type; - ssize_t num = 0; - size_t cnt; - ssize_t n; - ssize_t ret; - struct iovec liov[20]; - struct iovec *p_iov = liov; - - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); - - /* Check if the array size exceeds to compiled in size: */ - if (iovcnt > (int) (sizeof(liov) / sizeof(struct iovec))) { - /* Allocate memory for the local array: */ - if ((p_iov = (struct iovec *) - malloc((size_t)iovcnt * sizeof(struct iovec))) == NULL) { - /* Insufficient memory: */ - errno = ENOMEM; - _thread_leave_cancellation_point(); - return (-1); - } - } else if (iovcnt <= 0) { - errno = EINVAL; - _thread_leave_cancellation_point(); - return (-1); - } - - /* Copy the caller's array so that it can be modified locally: */ - memcpy(p_iov,iov,(size_t)iovcnt * sizeof(struct iovec)); - - /* Lock the file descriptor for write: */ - if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { - /* Get the read/write mode type: */ - type = _thread_fd_table[fd]->status_flags->flags & O_ACCMODE; - - /* Check if the file is not open for write: */ - if (type != O_WRONLY && type != O_RDWR) { - /* File is not open for write: */ - errno = EBADF; - _FD_UNLOCK(fd, FD_WRITE); - if (p_iov != liov) - free(p_iov); - _thread_leave_cancellation_point(); - return (-1); - } - - /* Check if file operations are to block */ - blocking = ((_thread_fd_table[fd]->status_flags->flags & O_NONBLOCK) == 0); - - /* - * Loop while no error occurs and until the expected number - * of bytes are written if performing a blocking write: - */ - while (ret == 0) { - /* Perform a non-blocking write syscall: */ - n = _thread_sys_writev(fd, &p_iov[idx], iovcnt - idx); - - /* Check if one or more bytes were written: */ - if (n > 0) { - /* - * Keep a count of the number of bytes - * written: - */ - num += n; - - /* - * Enter a loop to check if a short write - * occurred and move the index to the - * array entry where the short write - * ended: - */ - cnt = (size_t)n; - while (cnt > 0 && idx < iovcnt) { - /* - * If the residual count exceeds - * the size of this vector, then - * it was completely written: - */ - if (cnt >= p_iov[idx].iov_len) - /* - * Decrement the residual - * count and increment the - * index to the next array - * entry: - */ - cnt -= p_iov[idx++].iov_len; - else { - /* - * This entry was only - * partially written, so - * adjust it's length - * and base pointer ready - * for the next write: - */ - p_iov[idx].iov_len -= cnt; - p_iov[idx].iov_base = - (char *)p_iov[idx].iov_base - + (ptrdiff_t)cnt; - cnt = 0; - } - } - } else if (n == 0) { - /* - * Avoid an infinite loop if the last iov_len is - * 0. - */ - while (idx < iovcnt && p_iov[idx].iov_len == 0) - idx++; - - if (idx == iovcnt) { - ret = num; - break; - } - } - - /* - * If performing a blocking write, check if the - * write would have blocked or if some bytes - * were written but there are still more to - * write: - */ - if (blocking && ((n < 0 && (errno == EWOULDBLOCK || - errno == EAGAIN)) || (n >= 0 && idx < iovcnt))) { - curthread->data.fd.fd = fd; - _thread_kern_set_timeout(_FD_SNDTIMEO(fd)); - - /* Reset the interrupted operation flag: */ - curthread->interrupted = 0; - curthread->closing_fd = 0; - curthread->timeout = 0; - - _thread_kern_sched_state(PS_FDW_WAIT, - __FILE__, __LINE__); - - /* - * Check if the operation was - * interrupted by a signal - */ - if (curthread->interrupted || - curthread->closing_fd || - curthread->timeout) { - if (num > 0) { - /* Return partial success: */ - ret = num; - } else { - /* Return an error: */ - if (curthread->closing_fd) - errno = EBADF; - else if (curthread->interrupted) - errno = EINTR; - else - errno = EWOULDBLOCK; - ret = -1; - } - } - - /* - * If performing a non-blocking write, - * just return whatever the write syscall did: - */ - } else if (!blocking) { - /* A non-blocking call might return zero: */ - ret = n; - break; - - /* - * If there was an error, return partial success - * (if any bytes were written) or else the error: - */ - } else if (n < 0) { - if (num > 0) - ret = num; - else - ret = n; - - /* Check if the write has completed: */ - } else if (idx == iovcnt) - /* Return the number of bytes written: */ - ret = num; - } - _FD_UNLOCK(fd, FD_WRITE); - } - - /* If memory was allocated for the array, free it: */ - if (p_iov != liov) - free(p_iov); - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); - - return (ret); -} -#endif diff --git a/lib/libpthread/uthread/uthread_yield.c b/lib/libpthread/uthread/uthread_yield.c deleted file mode 100644 index 32852ee847a..00000000000 --- a/lib/libpthread/uthread/uthread_yield.c +++ /dev/null @@ -1,66 +0,0 @@ -/* $OpenBSD: uthread_yield.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */ -/* - * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: uthread_yield.c,v 1.4 1999/08/28 00:03:55 peter Exp $ - */ -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -int -sched_yield(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Reset the accumulated time slice value for the current thread: */ - curthread->slice_usec = -1; - - /* Schedule the next thread: */ - _thread_kern_sched(NULL); - - /* Always return no error. */ - return(0); -} - -/* Draft 4 yield */ -void -pthread_yield(void) -{ - struct pthread *curthread = _get_curthread(); - - /* Reset the accumulated time slice value for the current thread: */ - curthread->slice_usec = -1; - - /* Schedule the next thread: */ - _thread_kern_sched(NULL); -} -#endif |