diff options
Diffstat (limited to 'lib/libpthread/include')
| -rw-r--r-- | lib/libpthread/include/Makefile.inc | 30 | ||||
| -rw-r--r-- | lib/libpthread/include/cond.h | 89 | ||||
| -rw-r--r-- | lib/libpthread/include/engine.h | 86 | ||||
| -rw-r--r-- | lib/libpthread/include/fd.h | 104 | ||||
| -rw-r--r-- | lib/libpthread/include/fd_pipe.h | 52 | ||||
| -rw-r--r-- | lib/libpthread/include/kernel.h | 48 | ||||
| -rw-r--r-- | lib/libpthread/include/mutex.h | 91 | ||||
| -rw-r--r-- | lib/libpthread/include/posix.h | 19 | ||||
| -rw-r--r-- | lib/libpthread/include/pthread.h | 146 | ||||
| -rw-r--r-- | lib/libpthread/include/pthread_attr.h | 71 | ||||
| -rw-r--r-- | lib/libpthread/include/pthread_once.h | 51 | ||||
| -rw-r--r-- | lib/libpthread/include/queue.h | 65 | ||||
| -rw-r--r-- | lib/libpthread/include/stdio.h | 353 | ||||
| -rw-r--r-- | lib/libpthread/include/util.h | 87 |
14 files changed, 1292 insertions, 0 deletions
diff --git a/lib/libpthread/include/Makefile.inc b/lib/libpthread/include/Makefile.inc new file mode 100644 index 000000000000..8c1fe5140c3b --- /dev/null +++ b/lib/libpthread/include/Makefile.inc @@ -0,0 +1,30 @@ +# from: @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91 + +# Doing a make install builds /usr/include/pthread +# +# The ``rm -rf''s used below are safe because rm doesn't follow symbolic +# links. + + +FILES= cond.h engine.h fd.h fd_pipe.h kernel.h mutex.h posix.h \ + pthread.h pthread_attr.h queue.h stdio.h util.h + +# Machine dependent header file +MFILE= ${.CURDIR}/arch/${MACHINE}/machdep.h + +realinstall: + if [ ! -d ${DESTDIR}/usr/include/pthread ]; then \ + mkdir ${DESTDIR}/usr/include/pthread; \ + fi + @echo installing ${FILES} + @-for i in ${FILES}; do \ + cmp -s $$i ${DESTDIR}/usr/include/pthread/$$i || \ + install -c -m 644 $$i ${DESTDIR}/usr/include/$$i; \ + done + cmp -s ${MFILE} ${DESTDIR}/usr/include/pthread/machdep.h || \ + install -c -m 644 ${MFILE} ${DESTDIR}/usr/include/pthread/machdep.h + rm -rf ${DESTDIR}/usr/include/pthread.h + ln -s /usr/include/pthread/pthread.h ${DESTDIR}/usr/include/pthread.h + @chown -R ${BINOWN}:${BINGRP} ${DESTDIR}/usr/include/pthread + @chmod -R a-w ${DESTDIR}/usr/include/pthread + diff --git a/lib/libpthread/include/cond.h b/lib/libpthread/include/cond.h new file mode 100644 index 000000000000..82c064eac028 --- /dev/null +++ b/lib/libpthread/include/cond.h @@ -0,0 +1,89 @@ +/* ==== cond.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : mutex header. + * + * 1.00 93/10/30 proven + * -Started coding this file. + */ + +/* + * New cond structures + */ +enum pthread_cond_type { + COND_TYPE_FAST, + COND_TYPE_STATIC_FAST, + COND_TYPE_METERED, + COND_TYPE_DEBUG, /* Debug conds will have lots of options */ + COND_TYPE_MAX +}; + +typedef struct pthread_cond { + enum pthread_cond_type c_type; + struct pthread_queue c_queue; + semaphore c_lock; + void * c_data; + long c_flags; +} pthread_cond_t; + +typedef struct pthread_cond_attr { + enum pthread_cond_type c_type; + long c_flags; +} pthread_condattr_t; + +/* + * Flags for conds. + */ +#define COND_FLAGS_PRIVATE 0x01 +#define COND_FLAGS_INITED 0x02 +#define COND_FLAGS_BUSY 0x04 + +/* + * Static cond initialization values. + */ +#define PTHREAD_COND_INITIALIZER \ +{ COND_TYPE_STATIC_FAST, PTHREAD_QUEUE_INITIALIZER, \ + NULL, SEMAPHORE_CLEAR, COND_FLAGS_INITED } + +/* + * New functions + */ + +__BEGIN_DECLS + +int pthread_cond_init __P((pthread_cond_t *, pthread_condattr_t *)); +int pthread_cond_wait __P((pthread_cond_t *, pthread_mutex_t *)); +int pthread_cond_signal __P((pthread_cond_t *)); +int pthread_cond_broadcast __P((pthread_cond_t *)); +int pthread_cond_destroy __P((pthread_cond_t *)); + +__END_DECLS + diff --git a/lib/libpthread/include/engine.h b/lib/libpthread/include/engine.h new file mode 100644 index 000000000000..3539686755cb --- /dev/null +++ b/lib/libpthread/include/engine.h @@ -0,0 +1,86 @@ +/* ==== engine.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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 <setjmp.h> +#include <sys/time.h> + +#if defined(PTHREAD_KERNEL) +#include "machdep.h" +#endif + +/* + * New types + */ +typedef long semaphore; + +#define SIGMAX 31 + +/* + * New Strutures + */ +struct machdep_pthread { + void *(*start_routine)(void *); + void *start_argument; + void *machdep_stack; + struct itimerval machdep_timer; + jmp_buf machdep_state; +}; + +/* + * Static machdep_pthread initialization values. + * For initial thread only. + */ +#define MACHDEP_PTHREAD_INIT \ +{ NULL, NULL, NULL, { { 0, 0 }, { 0, 0 } }, 0 } + +/* + * Some fd flag defines that are necessary to distinguish between posix + * behavior and bsd4.3 behavior. + */ +#define __FD_NONBLOCK O_NONBLOCK + +/* + * New functions + */ + +__BEGIN_DECLS + +#if defined(PTHREAD_KERNEL) + +int semaphore_text_and_set __P((semaphore *)); +int machdep_save_state __P((void)); + +#endif + +__END_DECLS diff --git a/lib/libpthread/include/fd.h b/lib/libpthread/include/fd.h new file mode 100644 index 000000000000..408f101e9aeb --- /dev/null +++ b/lib/libpthread/include/fd.h @@ -0,0 +1,104 @@ +/* ==== fd.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : Basic fd header. + * + * 1.00 93/08/14 proven + * -Started coding this file. + * + * 1.01 93/11/13 proven + * -The functions readv() and writev() added + */ + +/* + * New pthread types. + */ +enum fd_type { + FD_NT, /* Not tested */ + FD_NIU, /* Known to be not in use */ + FD_HALF_DUPLEX, /* Files, and seeking devices */ + FD_FULL_DUPLEX /* pipes, sockets, drivers, ... */ +}; + + +#define FD_READ 0x1 +#define FD_WRITE 0x2 +#define FD_RDWR (FD_READ | FD_WRITE) + +struct fd_ops { + int (*write)(); + int (*read)(); + int (*close)(); + int (*fcntl)(); + int (*writev)(); + int (*readv)(); + int (*seek)(); +}; + +union fd_data { + void *ptr; + int i; +}; + +struct fd_table_entry { + struct pthread_queue r_queue; + struct pthread_queue w_queue; + struct pthread *r_owner; + struct pthread *w_owner; + semaphore lock; + struct fd_table_entry *next; + struct fd_ops *ops; + enum fd_type type; + int lockcount; /* Count for FILE locks */ + int count; + + /* data that needs to be passed to the type dependent fd */ + int flags; + union fd_data fd; +}; + +/* + * Important data structure + */ +extern struct fd_table_entry *fd_table[]; +extern int dtablesize; + +/* + * New functions + */ + +__BEGIN_DECLS + +#if defined(PTHREAD_KERNEL) + +#endif + +__END_DECLS diff --git a/lib/libpthread/include/fd_pipe.h b/lib/libpthread/include/fd_pipe.h new file mode 100644 index 000000000000..1ac1471d1a82 --- /dev/null +++ b/lib/libpthread/include/fd_pipe.h @@ -0,0 +1,52 @@ +/* ==== fd_pipe.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : The new fast ITC pipe header. + * + * 1.00 93/08/14 proven + * -Started coding this file. + */ + +struct __pipe { + semaphore lock; + char * buf; + int size; + int flags; + int count; + int offset; + struct pthread * wait; + char * wait_buf; + size_t wait_size; +}; + +#define RD_CLOSED 0x01 +#define WR_CLOSED 0x02 + diff --git a/lib/libpthread/include/kernel.h b/lib/libpthread/include/kernel.h new file mode 100644 index 000000000000..53e104e07e65 --- /dev/null +++ b/lib/libpthread/include/kernel.h @@ -0,0 +1,48 @@ +/* ==== kernel.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : mutex header. + * + * 1.00 93/07/22 proven + * -Started coding this file. + */ + +/* + * Defines only for the pthread user kernel. + */ +#if defined(PTHREAD_KERNEL) + +#define PANIC() abort() + +/* Time each rr thread gets */ +#define PTHREAD_RR_TIMEOUT 100000000 + +#endif diff --git a/lib/libpthread/include/mutex.h b/lib/libpthread/include/mutex.h new file mode 100644 index 000000000000..2afc727219d0 --- /dev/null +++ b/lib/libpthread/include/mutex.h @@ -0,0 +1,91 @@ +/* ==== mutex.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : mutex header. + * + * 1.00 93/07/20 proven + * -Started coding this file. + */ + +/* + * New mutex structures + */ +enum pthread_mutex_type { + MUTEX_TYPE_FAST, + MUTEX_TYPE_STATIC_FAST, + MUTEX_TYPE_RECURSIVE, + MUTEX_TYPE_METERED, + MUTEX_TYPE_DEBUG, /* Debug mutexes will have lots of options */ + MUTEX_TYPE_MAX +}; + +typedef struct pthread_mutex { + enum pthread_mutex_type m_type; + struct pthread_queue m_queue; + struct pthread *m_owner; + semaphore m_lock; + void *m_data; + long m_flags; +} pthread_mutex_t; + +typedef struct pthread_mutex_attr { + enum pthread_mutex_type m_type; + long m_flags; +} pthread_mutexattr_t; + +/* + * 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_INITIALIZER \ +{ MUTEX_TYPE_STATIC_FAST, PTHREAD_QUEUE_INITIALIZER, \ + NULL, SEMAPHORE_CLEAR, NULL, MUTEX_FLAGS_INITED } + +/* + * New functions + */ + +__BEGIN_DECLS + +int pthread_mutex_init __P((pthread_mutex_t *, pthread_mutexattr_t *)); +int pthread_mutex_lock __P((pthread_mutex_t *)); +int pthread_mutex_unlock __P((pthread_mutex_t *)); +int pthread_mutex_trylock __P((pthread_mutex_t *)); +int pthread_mutex_destroy __P((pthread_mutex_t *)); + +__END_DECLS + diff --git a/lib/libpthread/include/posix.h b/lib/libpthread/include/posix.h new file mode 100644 index 000000000000..cc440bb9e7ef --- /dev/null +++ b/lib/libpthread/include/posix.h @@ -0,0 +1,19 @@ +/* ==== posix.h ============================================================ + * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu + * + * Description : Convert an Ultrix-4.2 system to a more or less POSIX system. + * + * 1.00 93/07/20 proven + * -Started coding this file. + */ + +#ifndef _PTHREAD_POSIX_H_ +#define _PTHREAD_POSIX_H_ + +#include <sys/cdefs.h> + +/* Make sure we have size_t defined */ +#include <stdlib.h> +#include <stdarg.h> + +#endif diff --git a/lib/libpthread/include/pthread.h b/lib/libpthread/include/pthread.h new file mode 100644 index 000000000000..d8c8c9d1d1f2 --- /dev/null +++ b/lib/libpthread/include/pthread.h @@ -0,0 +1,146 @@ +/* ==== pthread.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : Basic pthread header. + * + * 1.00 93/07/20 proven + * -Started coding this file. + */ + +#include <pthread/engine.h> +#include <pthread/kernel.h> +#include <pthread/queue.h> +#include <pthread/mutex.h> +#include <pthread/cond.h> +#include <pthread/fd.h> + +#include <pthread/util.h> +#include <errno.h> + +/* More includes */ +#include <pthread/pthread_once.h> + +/* More includes, that need size_t */ +#include <pthread/pthread_attr.h> + +enum pthread_state { + PS_RUNNING, + PS_MUTEX_WAIT, + PS_COND_WAIT, + PS_FDLR_WAIT, + PS_FDLW_WAIT, + PS_FDR_WAIT, + PS_FDW_WAIT, + PS_SLEEP_WAIT, + PS_JOIN, + PS_DEAD +}; + +#define PF_DETACHED 0x00000001 + +struct pthread { + struct machdep_pthread machdep_data; + enum pthread_state state; + pthread_attr_t attr; + + /* Other flags */ + int flags; + + /* Time until timeout */ + int time_sec; + int time_usec; + + /* Join queue for waiting threads */ + struct pthread_queue join_queue; + + /* Queue thread is waiting on, (mutexes, cond. etc.) */ + struct pthread_queue *queue; + + /* + * Thread implementations are just multiple queue type implemenations, + * Below are the various link lists currently necessary + * It is possible for a thread to be on multiple, or even all the + * queues at once, much care must be taken during queue manipulation. + * + * The pthread structure must be locked before you can even look at + * the link lists. + */ + + struct pthread *pll; /* ALL threads, in any state */ + /* struct pthread *rll; Current run queue, before resced */ + struct pthread *sll; /* For sleeping threads */ + struct pthread *next; /* Standard for mutexes, etc ... */ + /* struct pthread *fd_next; For kernel fd operations */ + + int fd; /* Used when thread waiting on fd */ + + semaphore lock; + void *ret; + int error; +}; + +typedef struct pthread* pthread_t; + +/* + * Globals + */ +extern struct pthread *pthread_run; +extern struct pthread *pthread_initial; +extern struct pthread *pthread_link_list; +extern pthread_attr_t pthread_default_attr; +extern struct pthread_queue pthread_current_queue; +extern struct fd_table_entry *fd_table[]; + +/* + * New functions + */ + +__BEGIN_DECLS + +void pthread_init __P((void)); +int pthread_create __P((pthread_t *, const pthread_attr_t *, + void * (*start_routine)(void *), void *)); +void pthread_exit __P((void *)); +pthread_t pthread_self __P((void)); +int pthread_equal __P((pthread_t, pthread_t)); +int pthread_join __P((pthread_t, void **)); +int pthread_detach __P((pthread_t)); + +#if defined(PTHREAD_KERNEL) + +void pthread_yield __P((void)); + +/* Not valid, but I can't spell so this will be caught at compile time */ +#define pthread_yeild(notvalid) + +#endif + +__END_DECLS diff --git a/lib/libpthread/include/pthread_attr.h b/lib/libpthread/include/pthread_attr.h new file mode 100644 index 000000000000..ba64d25f3255 --- /dev/null +++ b/lib/libpthread/include/pthread_attr.h @@ -0,0 +1,71 @@ +/* ==== pthread_attr.h ======================================================== + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : Basic pthread attributes header. + * + * 1.00 93/11/03 proven + * -Started coding this file. + */ + +#define _POSIX_THREAD_ATTR_STACKSIZE + +#define PTHREAD_STACK_DEFAULT 65536 + +/* + * New pthread attribute types. + */ +enum pthread_sched_attr { + SCHED_RR, + SCHED_IO, + SCHED_FIFO, + SCHED_OTHER, +}; + +typedef struct pthread_attr { + enum pthread_sched_attr sched_attr; + void * stackaddr_attr; + size_t stacksize_attr; +} pthread_attr_t; + +/* + * New functions + */ + +__BEGIN_DECLS + +int pthread_attr_init __P((pthread_attr_t *)); +int pthread_attr_destroy __P((pthread_attr_t *)); +int pthread_attr_setstacksize __P((pthread_attr_t *, size_t)); +int pthread_attr_getstacksize __P((pthread_attr_t *, size_t *)); +int pthread_attr_setstackaddr __P((pthread_attr_t *, void *)); +int pthread_attr_getstackaddr __P((pthread_attr_t *, void **)); + +__END_DECLS diff --git a/lib/libpthread/include/pthread_once.h b/lib/libpthread/include/pthread_once.h new file mode 100644 index 000000000000..5967080ac0b3 --- /dev/null +++ b/lib/libpthread/include/pthread_once.h @@ -0,0 +1,51 @@ +/* ==== pthread_once.h ======================================================== + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : mutex header. + * + * 1.00 93/12/12 proven + * -Started coding this file. + */ + +/* New pthread_once structures */ +typedef int pthread_once_t; + +/* Static pthread_once_t initialization value. */ +#define PTHREAD_ONCE_INIT 0 + +/* New functions */ + +__BEGIN_DECLS + +int pthread_once __P((pthread_once_t *, void (*init_routine)(void))); + +__END_DECLS + diff --git a/lib/libpthread/include/queue.h b/lib/libpthread/include/queue.h new file mode 100644 index 000000000000..687df4907124 --- /dev/null +++ b/lib/libpthread/include/queue.h @@ -0,0 +1,65 @@ +/* ==== queue.h ============================================================ + * Copyright (c) 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : mutex header. + * + * 1.00 93/07/20 proven + * -Started coding this file. + */ + +/* + * New queue structures + */ +struct pthread_queue { + struct pthread *q_next; + struct pthread *q_last; + void *q_data; +}; + +/* + * Static queue initialization values. + */ +#define PTHREAD_QUEUE_INITIALIZER { NULL, NULL, NULL } + +/* + * New functions + * Should make pthread_queue_get a macro + */ + +__BEGIN_DECLS + +void pthread_queue_init __P((struct pthread_queue *)); +void pthread_queue_enq __P((struct pthread_queue *, struct pthread *)); +void pthread_queue_remove __P((struct pthread_queue *, struct pthread *)); +struct pthread *pthread_queue_get __P((struct pthread_queue *)); +struct pthread *pthread_queue_deq __P((struct pthread_queue *)); + +__END_DECLS diff --git a/lib/libpthread/include/stdio.h b/lib/libpthread/include/stdio.h new file mode 100644 index 000000000000..70a4265ae2ab --- /dev/null +++ b/lib/libpthread/include/stdio.h @@ -0,0 +1,353 @@ +/* ==== stdio.h ============================================================ + * Copyright (c) 1990 The Regents of the University of California. + * Copyright (c) 1993 by Chris Provenzano, proven@mit.edu + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * from: @(#)stdio.h 5.17 (Berkeley) 6/3/91 + * $Id: stdio.h,v 1.1 1994/01/30 04:22:49 proven Exp $ + */ + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include <pthread/posix.h> + +#ifndef NULL +#define NULL 0 +#endif + +typedef long fpos_t; /* Must match off_t <sys/types.h> */ + +#define _FSTDIO /* Define for new stdio with functions. */ + +/* + * NB: to fit things in six character monocase externals, the stdio + * code uses the prefix `__s' for stdio objects, typically followed + * by a three-character attempt at a mnemonic. + */ + +/* stdio buffers */ +struct __sbuf { + unsigned char *_base; + int _size; +}; + +/* + * stdio state variables. + * + * The following always hold: + * + * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), + * _lbfsize is -_bf._size, else _lbfsize is 0 + * if _flags&__SRD, _w is 0 + * if _flags&__SWR, _r is 0 + * + * This ensures that the getc and putc macros (or inline functions) never + * try to write or read from a file that is in `read' or `write' mode. + * (Moreover, they can, and do, automatically switch from read mode to + * write mode, and back, on "r+" and "w+" files.) + * + * _lbfsize is used only to make the inline line-buffered output stream + * code as compact as possible. + * + * _ub, _up, and _ur are used when ungetc() pushes back more characters + * than fit in the current _bf, or when ungetc() pushes back a character + * that does not match the previous one in _bf. When this happens, + * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff + * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. + */ +typedef struct __sFILE { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + + /* separate buffer for long sequences of ungetc() */ + struct __sbuf _ub; /* ungetc buffer */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + int _ur; /* saved _r when _r is counting ungetc data */ + + /* tricks to meet minimum requirements even when malloc() fails */ + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + /* separate buffer for fgetline() when line crosses buffer boundary */ + struct __sbuf _lb; /* buffer for fgetline() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + int _offset; /* current lseek offset */ +} FILE; + +__BEGIN_DECLS +extern FILE __sF[]; +__END_DECLS + +#define __SLBF 0x0001 /* line buffered */ +#define __SNBF 0x0002 /* unbuffered */ +#define __SRD 0x0004 /* OK to read */ +#define __SWR 0x0008 /* OK to write */ + /* RD and WR are never simultaneously asserted */ +#define __SRW 0x0010 /* open for reading & writing */ +#define __SEOF 0x0020 /* found EOF */ +#define __SERR 0x0040 /* found error */ +#define __SMBF 0x0080 /* _buf is from malloc */ +#define __SAPP 0x0100 /* fdopen()ed in append mode */ +#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ +#define __SOPT 0x0400 /* do fseek() optimisation */ +#define __SNPT 0x0800 /* do not do fseek() optimisation */ +#define __SOFF 0x1000 /* set iff _offset is in fact correct */ +#define __SMOD 0x2000 /* true => fgetline modified _p text */ + +/* + * The following three definitions are for ANSI C, which took them + * from System V, which brilliantly took internal interface macros and + * made them official arguments to setvbuf(), without renaming them. + * Hence, these ugly _IOxxx names are *supposed* to appear in user code. + * + * Although numbered as their counterparts above, the implementation + * does not rely on this. + */ +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ + +#define BUFSIZ 1024 /* size of buffer used by setbuf */ +#define EOF (-1) + +/* + * FOPEN_MAX is a minimum maximum, and should be the number of descriptors + * that the kernel can provide without allocation of a resource that can + * fail without the process sleeping. Do not use this for anything. + */ +#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ +#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ + +/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ +#ifndef _ANSI_SOURCE +#define P_tmpdir "/var/tmp/" +#endif +#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ +#ifndef TMP_MAX +#define TMP_MAX 308915776 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#define stdin (&__sF[0]) +#define stdout (&__sF[1]) +#define stderr (&__sF[2]) + +/* + * Functions defined in ANSI C standard. + */ +__BEGIN_DECLS +void clearerr __P((FILE *)); +int fclose __P((FILE *)); +int feof __P((FILE *)); +int ferror __P((FILE *)); +int fflush __P((FILE *)); +int fgetc __P((FILE *)); +int fgetpos __P((FILE *, fpos_t *)); +char * fgets __P((char *, size_t, FILE *)); +FILE * fopen __P((const char *, const char *)); +int fprintf __P((FILE *, const char *, ...)); +int fputc __P((int, FILE *)); +int fputs __P((const char *, FILE *)); +size_t fread __P((void *, size_t, size_t, FILE *)); +FILE * freopen __P((const char *, const char *, FILE *)); +int fscanf __P((FILE *, const char *, ...)); +int fseek __P((FILE *, long, int)); +int fsetpos __P((FILE *, const fpos_t *)); +long ftell __P((const FILE *)); +size_t fwrite __P((const void *, size_t, size_t, FILE *)); +int getc __P((FILE *)); +int getchar __P((void)); +char * gets __P((char *)); + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +extern int sys_nerr; /* perror(3) external variables */ +extern char *sys_errlist[]; +#endif + +void perror __P((const char *)); +int printf __P((const char *, ...)); +int putc __P((int, FILE *)); +int putchar __P((int)); +int puts __P((const char *)); +int remove __P((const char *)); +int rename __P((const char *, const char *)); +void rewind __P((FILE *)); +int scanf __P((const char *, ...)); +void setbuf __P((FILE *, char *)); +int setvbuf __P((FILE *, char *, int, size_t)); +int sprintf __P((char *, const char *, ...)); +int sscanf __P((const char *, const char *, ...)); +FILE *tmpfile __P((void)); +char *tmpnam __P((char *)); +int ungetc __P((int, FILE *)); +int vfprintf __P((FILE *, const char *, va_list)); +int vprintf __P((const char *, va_list)); +int vsprintf __P((char *, const char *, va_list)); +__END_DECLS + +/* + * Functions defined in POSIX 1003.1. + */ +#ifndef _ANSI_SOURCE +#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */ +#define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */ + +__BEGIN_DECLS +char *ctermid __P((char *)); +char *cuserid __P((char *)); +FILE *fdopen __P((int, const char *)); +int fileno __P((FILE *)); +__END_DECLS +#endif /* not ANSI */ + +/* + * Routines that are purely local. + */ +#if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +__BEGIN_DECLS +char *fgetline __P((FILE *, size_t *)); +int fpurge __P((FILE *)); +int getw __P((FILE *)); +int pclose __P((FILE *)); +FILE *popen __P((const char *, const char *)); +int putw __P((int, FILE *)); +void setbuffer __P((FILE *, char *, int)); +int setlinebuf __P((FILE *)); +char *tempnam __P((const char *, const char *)); +int snprintf __P((char *, size_t, const char *, ...)); +int vsnprintf __P((char *, size_t, const char *, va_list)); +int vscanf __P((const char *, va_list)); +int vsscanf __P((const char *, const char *, va_list)); +__END_DECLS + +/* + * This is a #define because the function is used internally and + * (unlike vfscanf) the name __svfscanf is guaranteed not to collide + * with a user function when _ANSI_SOURCE or _POSIX_SOURCE is defined. + */ +#define vfscanf __svfscanf + +/* + * Stdio function-access interface. + */ +__BEGIN_DECLS +FILE *funopen __P((const void *, + int (*)(void *, char *, int), + int (*)(void *, const char *, int), + fpos_t (*)(void *, fpos_t, int), + int (*)(void *))); +__END_DECLS +#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) +#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) +#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ + +/* + * Functions internal to the implementation. + */ +__BEGIN_DECLS +int __srget __P((FILE *)); +int __svfscanf __P((FILE *, const char *, va_list)); +int __swbuf __P((int, FILE *)); +__END_DECLS + +/* + * The __sfoo macros are here so that we can + * define function versions in the C library. + */ +#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) +static __inline int __getc(FILE *_p) +{ + int ret; + flockfile(_p); + ret = __sgetc(_p); + funlockfile(_p); + return(ret); +} + +#define getc(fp) __gets(fp) +#define getchar() getc(stdin) +#define getc_unlocked(fp) __sgetc(fp) +#define getchar_unlocked() getc_unlocked(stdin) + +static __inline int __sputc(int _c, FILE *_p) +{ + if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) + return (*_p->_p++ = _c); + else + return (__swbuf(_c, _p)); +} + +static __inline int __putc(int _c, FILE *_p) +{ + int ret; + flockfile(_p); + ret = __sputc(_c, _p); + funlockfile(_p); + return(ret); +} + +#define putc(x, fp) __putc(x, fp); +#define putchar(x) putc(x, stdout) +#define putc_unlocked(x, fp) __sputc(x, fp) +#define putchar_unlocked(x) putc_unlocked(x, stdout) + +#define __sfeof(p) (((p)->_flags & __SEOF) != 0) +#define __sferror(p) (((p)->_flags & __SERR) != 0) +#define __sfileno(p) ((p)->_file) + +#define feof(p) __sfeof(p) +#define ferror(p) __sferror(p) + +#ifndef _ANSI_SOURCE +#define fileno(p) __sfileno(p) +#endif + +#endif diff --git a/lib/libpthread/include/util.h b/lib/libpthread/include/util.h new file mode 100644 index 000000000000..91d094c2856b --- /dev/null +++ b/lib/libpthread/include/util.h @@ -0,0 +1,87 @@ +/* ==== util.h ============================================================ + * Copyright (c) 1991, 1992, 1993 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * Description : Header file for generic utility functions. + * + * 91/08/31 proven - Added exchange. + * Exchange any two objects of any size in any table. + * + * 91/10/06 proven - Cleaned out all the old junk. + * + * 91/03/06 proven - Added getint. + */ + +#ifndef _PTHREAD_UTIL_H +#define _PTHREAD_UTIL_H + +#ifndef NULL +#define NULL 0 +#endif + +/* Stuff only pthread internals really uses */ +#if defined(PTHREAD_KERNEL) + +#undef FALSE +#undef TRUE + +typedef enum Boolean { + FALSE, + TRUE, +} Boolean; + +#define OK 0 +#define NUL '\0' +#define NOTOK -1 + +#if ! defined(min) +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) +#endif + +/* Alingn the size to the next multiple of 4 bytes */ +#define ALIGN4(size) ((size + 3) & ~3) +#define ALIGN8(size) ((size + 7) & ~7) + +#ifdef DEBUG +#define DEBUG0(s) printf(s) +#define DEBUG1(s,a) printf(s,a) +#define DEBUG2(s,a,b) printf(s,a,b) +#define DEBUG3(s,a,b,c) printf(s,a,b,c) +#else +#define DEBUG0(s) +#define DEBUG1(s) +#define DEBUG2(s) +#define DEBUG3(s) +#endif + +#endif + +#endif |
