summaryrefslogtreecommitdiff
path: root/lib/libpthread/include
diff options
context:
space:
mode:
authorproven <proven@NetBSD.org>1993-11-14 22:06:22 +0000
committerproven <proven@NetBSD.org>1993-11-14 22:06:22 +0000
commit89fc7bac0859332dbb6b0fd0833e74557beadc29 (patch)
tree86e4d7e252c6c2d1986520949df2e3190a767e77 /lib/libpthread/include
parent08322f94235c9fdbef8dc69c9699e836b6caf9d4 (diff)
Initial release of the POSIX 1003.4a Draft 7 thread implementation.
Diffstat (limited to 'lib/libpthread/include')
-rw-r--r--lib/libpthread/include/Makefile.inc30
-rw-r--r--lib/libpthread/include/cond.h61
-rw-r--r--lib/libpthread/include/copyright.h32
-rw-r--r--lib/libpthread/include/fd.h76
-rw-r--r--lib/libpthread/include/fd_pipe.h24
-rw-r--r--lib/libpthread/include/kernel.h20
-rw-r--r--lib/libpthread/include/mutex.h64
-rw-r--r--lib/libpthread/include/posix.h28
-rw-r--r--lib/libpthread/include/pthread.h93
-rw-r--r--lib/libpthread/include/pthread_attr.h45
-rw-r--r--lib/libpthread/include/queue.h39
-rw-r--r--lib/libpthread/include/util.h51
12 files changed, 563 insertions, 0 deletions
diff --git a/lib/libpthread/include/Makefile.inc b/lib/libpthread/include/Makefile.inc
new file mode 100644
index 00000000000..b7fe59d5f0d
--- /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 copyright.h fd.h fd_pipe.h kernel.h mutex.h posix.h \
+ pthread.h pthread_attr.h queue.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 00000000000..f267b914447
--- /dev/null
+++ b/lib/libpthread/include/cond.h
@@ -0,0 +1,61 @@
+/* ==== cond.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * 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/copyright.h b/lib/libpthread/include/copyright.h
new file mode 100644
index 00000000000..887676b888f
--- /dev/null
+++ b/lib/libpthread/include/copyright.h
@@ -0,0 +1,32 @@
+/* ==== copyright.h ==========================================================
+ * Copyright (c) 1993 by Chris Provenzano and contributors, 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,
+ * the University of California, Berkeley, and contributors.
+ * 4. Neither the name of Chris Provenzano, the University, nor the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO 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 CHRIS PROVENZANO, 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.
+ */
diff --git a/lib/libpthread/include/fd.h b/lib/libpthread/include/fd.h
new file mode 100644
index 00000000000..e4dd63be578
--- /dev/null
+++ b/lib/libpthread/include/fd.h
@@ -0,0 +1,76 @@
+/* ==== fd.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * 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)();
+};
+
+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 00000000000..1ca14536408
--- /dev/null
+++ b/lib/libpthread/include/fd_pipe.h
@@ -0,0 +1,24 @@
+/* ==== fd_pipe.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * 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 00000000000..5659b29543b
--- /dev/null
+++ b/lib/libpthread/include/kernel.h
@@ -0,0 +1,20 @@
+/* ==== kernel.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * 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 00000000000..a7c729b5334
--- /dev/null
+++ b/lib/libpthread/include/mutex.h
@@ -0,0 +1,64 @@
+/* ==== mutex.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * Description : mutex header.
+ *
+ * 1.00 93/07/20 proven
+ * -Started coding this file.
+ */
+
+#include <pthread/copyright.h>
+/*
+ * 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 00000000000..9c791be890a
--- /dev/null
+++ b/lib/libpthread/include/posix.h
@@ -0,0 +1,28 @@
+/* ==== posix.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * Description : Convert a system to a more or less POSIX system.
+ *
+ * 1.00 93/07/20 proven
+ * -Started coding this file.
+ */
+
+#include <pthread/copyright.h>
+
+#ifndef O_NONBLOCK
+#ifdef FNDELAY
+#define O_NONBLOCK FNDELAY
+#endif
+#endif
+
+#ifndef O_ACCMODE
+#define O_ACCMODE (O_RDONLY|O_RDWR|O_WRONLY)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(x) ((x & S_IFMT) == S_IFREG)
+#endif
+
+#ifndef __ibm032__
+#include <stdlib.h>
+#endif
diff --git a/lib/libpthread/include/pthread.h b/lib/libpthread/include/pthread.h
new file mode 100644
index 00000000000..4a5fbd6d250
--- /dev/null
+++ b/lib/libpthread/include/pthread.h
@@ -0,0 +1,93 @@
+/* ==== pthread.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * Description : Basic pthread header.
+ *
+ * 1.00 93/07/20 proven
+ * -Started coding this file.
+ */
+
+#include <pthread/copyright.h>
+#include <pthread/machdep.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 <pthread/stdio.h> Because I'm a moron -- proven */
+#include <errno.h>
+
+/* More includes, that need size_t or NULL */
+#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_DEAD
+};
+
+struct pthread {
+ struct machdep_pthread machdep_data;
+ struct pthread_queue *queue;
+ enum pthread_state state;
+ pthread_attr_t attr;
+
+ /*
+ * 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.
+ */
+ struct pthread *pll; /* ALL threads, in any state */
+ /* struct pthread *rll; /* Current run queue, before resced */
+ struct pthread *next; /* Standard for mutexes, etc ... */
+ struct pthread *s_next; /* For sleeping threads */
+ /* struct pthread *fd_next; /* For kernel fd operations */
+
+ int fd; /* Used when thread waiting on fd */
+
+ semaphore lock;
+ 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
+
+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));
+
+#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 00000000000..7d58c52422c
--- /dev/null
+++ b/lib/libpthread/include/pthread_attr.h
@@ -0,0 +1,45 @@
+/* ==== pthread_attr.h ========================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * Description : Basic pthread attributes header.
+ *
+ * 1.00 93/11/03 proven
+ * -Started coding this file.
+ */
+
+#include <pthread/copyright.h>
+
+#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/queue.h b/lib/libpthread/include/queue.h
new file mode 100644
index 00000000000..0a06d79842f
--- /dev/null
+++ b/lib/libpthread/include/queue.h
@@ -0,0 +1,39 @@
+/* ==== queue.h ============================================================
+ * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * Description : mutex header.
+ *
+ * 1.00 93/07/20 proven
+ * -Started coding this file.
+ */
+
+#include <pthread/copyright.h>
+
+/*
+ * 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/util.h b/lib/libpthread/include/util.h
new file mode 100644
index 00000000000..0da50e9df23
--- /dev/null
+++ b/lib/libpthread/include/util.h
@@ -0,0 +1,51 @@
+/* ==== util.h ============================================================
+ * Copyright (c) 1991, 1992, 1993 by Chris Provenzano, proven@athena.mit.edu
+ *
+ * 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.
+ */
+
+#include <pthread/copyright.h>
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#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