summaryrefslogtreecommitdiff
path: root/mit-pthreads/patches
diff options
context:
space:
mode:
authorbk@work.mysql.com <>2000-07-31 21:29:14 +0200
committerbk@work.mysql.com <>2000-07-31 21:29:14 +0200
commitf4c589ff6c653d1d2a09c26e46ead3c8a15655d8 (patch)
treed253a359142dfc1ed247d5d4365d86972ea31109 /mit-pthreads/patches
parent7eec25e393727b16bb916b50d82b0aa3084e065c (diff)
downloadmariadb-git-f4c589ff6c653d1d2a09c26e46ead3c8a15655d8.tar.gz
Import changeset
Diffstat (limited to 'mit-pthreads/patches')
-rwxr-xr-xmit-pthreads/patches/Streepy.html2873
-rwxr-xr-xmit-pthreads/patches/Streepy2.html93
-rwxr-xr-xmit-pthreads/patches/bill_lear70
-rwxr-xr-xmit-pthreads/patches/chris_demetriou149
-rwxr-xr-xmit-pthreads/patches/mevans642
-rwxr-xr-xmit-pthreads/patches/p15390
-rwxr-xr-xmit-pthreads/patches/p15596
7 files changed, 4013 insertions, 0 deletions
diff --git a/mit-pthreads/patches/Streepy.html b/mit-pthreads/patches/Streepy.html
new file mode 100755
index 00000000000..a3b4faa815f
--- /dev/null
+++ b/mit-pthreads/patches/Streepy.html
@@ -0,0 +1,2873 @@
+diff -c -r1.1.1.1 pthread.h
+*** pthread.h 1996/03/13 04:30:57 1.1.1.1
+--- pthread.h 1996/10/02 17:52:47
+***************
+*** 35,40 ****
+--- 35,43 ----
+ *
+ * 1.00 93/07/20 proven
+ * -Started coding this file.
++ *
++ * 93/9/28 streepy - Added support for pthread cancel
++ *
+ */
+
+ #ifndef _PTHREAD_H_
+***************
+*** 65,70 ****
+--- 68,82 ----
+ /* More includes, that need size_t */
+ #include <pthread/pthread_attr.h>
+
++ /* Constants for use with pthread_setcancelstate and pthread_setcanceltype */
++ #define PTHREAD_CANCEL_DISABLE 0
++ #define PTHREAD_CANCEL_ENABLE 1
++ #define PTHREAD_CANCEL_DEFERRED 0
++ #define PTHREAD_CANCEL_ASYNCHRONOUS 1
++
++ #define PTHREAD_CANCELLED (void *)1 /* Exit status of a cancelled thread */
++
++
+ #ifdef PTHREAD_KERNEL
+
+ #include <signal.h> /* for sigset_t */
+***************
+*** 78,120 ****
+ PS_STATE_MAX
+ };
+
+- #define PF_WAIT_EVENT 0x01
+- #define PF_DONE_EVENT 0x02
+-
+ /* Put PANIC inside an expression that evaluates to non-void type, to
+ make it easier to combine it in expressions. */
+! #define DO_PANIC() (PANIC (), 0)
+! #define PANICIF(x) ((x) ? DO_PANIC () : 0)
+
+! #define SET_PF_DONE_EVENT(x) \
+! ( !(x->flags & PF_DONE_EVENT) \
+! ? ( (x->flags & PF_WAIT_EVENT) \
+! ? (x->flags = PF_DONE_EVENT, OK) \
+! : DO_PANIC ()) \
+ : NOTOK )
+
+! #define SET_PF_WAIT_EVENT(x) \
+! ( PANICIF (x->flags & (PF_WAIT_EVENT | PF_DONE_EVENT)), \
+! (x->flags = PF_WAIT_EVENT), 0)
+!
+! #define CLEAR_PF_DONE_EVENT(x) \
+! ( PANICIF (!(x->flags & PF_DONE_EVENT)), \
+! x->flags = 0 )
+
+ struct pthread_select_data {
+! int nfds;
+! fd_set readfds;
+! fd_set writefds;
+! fd_set exceptfds;
+ };
+
+ union pthread_wait_data {
+! pthread_mutex_t * mutex;
+! pthread_cond_t * cond;
+! const sigset_t * sigwait; /* Waiting on a signal in sigwait */
+ struct {
+! short fd; /* Used when thread waiting on fd */
+! short branch; /* line number, for debugging */
+ } fd;
+ struct pthread_select_data * select_data;
+ };
+--- 90,185 ----
+ PS_STATE_MAX
+ };
+
+ /* Put PANIC inside an expression that evaluates to non-void type, to
+ make it easier to combine it in expressions. */
+! #define DO_PANIC() (PANIC (), 0)
+! #define PANICIF(x) ((x) ? DO_PANIC () : 0)
+!
+! /* In the thread flag field, we use a series of bit flags. Flags can
+! * organized into "groups" of mutually exclusive flags. Other flags
+! * are unrelated and can be set and cleared with a single bit operation.
+! */
+
+! #define PF_WAIT_EVENT 0x01
+! #define PF_DONE_EVENT 0x02
+! #define PF_EVENT_GROUP 0x03 /* All event bits */
+!
+! #define PF_CANCEL_STATE 0x04 /* cancellability state */
+! #define PF_CANCEL_TYPE 0x08 /* cancellability type */
+! #define PF_THREAD_CANCELLED 0x10 /* thread has been cancelled */
+! #define PF_RUNNING_TO_CANCEL 0x20 /* Thread is running so it can cancel*/
+! #define PF_AT_CANCEL_POINT 0x40 /* Thread is at a cancel point */
+!
+! /* Flag operations */
+!
+! #define SET_PF_FLAG(x,f) ( (x)->flags |= (f) )
+! #define TEST_PF_FLAG(x,f) ( (x)->flags & (f) )
+! #define CLEAR_PF_FLAG(x,f) ( (x)->flags &= ~(f) )
+! #define CLEAR_PF_GROUP(x,g) ( (x)->flags &= ~(g) )
+! #define SET_PF_FLAG_IN_GROUP(x,g,f) ( CLEAR_PF_GROUP(x,g),SET_PF_FLAG(x,f))
+! #define TEST_PF_GROUP(x,g) ( (x)->flags & (g) )
+!
+! #define SET_PF_DONE_EVENT(x) \
+! ( !TEST_PF_FLAG(x,PF_DONE_EVENT) \
+! ? ( TEST_PF_FLAG(x,PF_WAIT_EVENT) \
+! ? (SET_PF_FLAG_IN_GROUP(x,PF_EVENT_GROUP,PF_DONE_EVENT), OK) \
+! : DO_PANIC ()) \
+ : NOTOK )
+
+! #define SET_PF_WAIT_EVENT(x) \
+! ( PANICIF (TEST_PF_GROUP(x,PF_EVENT_GROUP) ), \
+! SET_PF_FLAG_IN_GROUP(x,PF_EVENT_GROUP,PF_WAIT_EVENT), 0)
+!
+! #define CLEAR_PF_DONE_EVENT(x) \
+! ( PANICIF (!TEST_PF_FLAG(x,PF_DONE_EVENT)), \
+! CLEAR_PF_GROUP(x,PF_EVENT_GROUP) )
+!
+! #define SET_PF_CANCELLED(x) ( SET_PF_FLAG(x,PF_THREAD_CANCELLED) )
+! #define TEST_PF_CANCELLED(x) ( TEST_PF_FLAG(x,PF_THREAD_CANCELLED) )
+!
+! #define SET_PF_RUNNING_TO_CANCEL(x) ( SET_PF_FLAG(x,PF_RUNNING_TO_CANCEL) )
+! #define CLEAR_PF_RUNNING_TO_CANCEL(x)( CLEAR_PF_FLAG(x,PF_RUNNING_TO_CANCEL) )
+! #define TEST_PF_RUNNING_TO_CANCEL(x)( TEST_PF_FLAG(x,PF_RUNNING_TO_CANCEL) )
+!
+! #define SET_PF_AT_CANCEL_POINT(x) ( SET_PF_FLAG(x,PF_AT_CANCEL_POINT) )
+! #define CLEAR_PF_AT_CANCEL_POINT(x) ( CLEAR_PF_FLAG(x,PF_AT_CANCEL_POINT) )
+! #define TEST_PF_AT_CANCEL_POINT(x) ( TEST_PF_FLAG(x,PF_AT_CANCEL_POINT) )
+!
+! #define SET_PF_CANCEL_STATE(x,f) \
+! ( (f) ? SET_PF_FLAG(x,PF_CANCEL_STATE) : CLEAR_PF_FLAG(x,PF_CANCEL_STATE) )
+! #define TEST_PF_CANCEL_STATE(x) \
+! ( (TEST_PF_FLAG(x,PF_CANCEL_STATE)) ? PTHREAD_CANCEL_ENABLE \
+! : PTHREAD_CANCEL_DISABLE )
+!
+! #define SET_PF_CANCEL_TYPE(x,f) \
+! ( (f) ? SET_PF_FLAG(x,PF_CANCEL_TYPE) : CLEAR_PF_FLAG(x,PF_CANCEL_TYPE) )
+! #define TEST_PF_CANCEL_TYPE(x) \
+! ( (TEST_PF_FLAG(x,PF_CANCEL_TYPE)) ? PTHREAD_CANCEL_ASYNCHRONOUS \
+! : PTHREAD_CANCEL_DEFERRED )
+!
+! /* See if a thread is in a state that it can be cancelled */
+! #define TEST_PTHREAD_IS_CANCELLABLE(x) \
+! ( (TEST_PF_CANCEL_STATE(x) == PTHREAD_CANCEL_ENABLE && TEST_PF_CANCELLED(x)) \
+! ? ((TEST_PF_CANCEL_TYPE(x) == PTHREAD_CANCEL_ASYNCHRONOUS) \
+! ? 1 \
+! : TEST_PF_AT_CANCEL_POINT(x)) \
+! : 0 )
+!
+
+ struct pthread_select_data {
+! int nfds;
+! fd_set readfds;
+! fd_set writefds;
+! fd_set exceptfds;
+ };
+
+ union pthread_wait_data {
+! pthread_mutex_t * mutex;
+! pthread_cond_t * cond;
+! const sigset_t * sigwait; /* Waiting on a signal in sigwait */
+ struct {
+! short fd; /* Used when thread waiting on fd */
+! short branch; /* line number, for debugging */
+ } fd;
+ struct pthread_select_data * select_data;
+ };
+***************
+*** 122,143 ****
+ #define PTT_USER_THREAD 0x0001
+
+ struct pthread {
+! int thread_type;
+ struct machdep_pthread machdep_data;
+! pthread_attr_t attr;
+
+ /* Signal interface */
+! sigset_t sigmask;
+! sigset_t sigpending;
+! int sigcount; /* Number of signals pending */
+
+ /* Timeout time */
+! struct timespec wakeup_time;
+
+ /* Join queue for waiting threads */
+ struct pthread_queue join_queue;
+
+-
+ /*
+ * Thread implementations are just multiple queue type implemenations,
+ * Below are the various link lists currently necessary
+--- 187,207 ----
+ #define PTT_USER_THREAD 0x0001
+
+ struct pthread {
+! int thread_type;
+ struct machdep_pthread machdep_data;
+! pthread_attr_t attr;
+
+ /* Signal interface */
+! sigset_t sigmask;
+! sigset_t sigpending;
+! int sigcount; /* Number of signals pending */
+
+ /* Timeout time */
+! struct timespec wakeup_time;
+
+ /* Join queue for waiting threads */
+ struct pthread_queue join_queue;
+
+ /*
+ * Thread implementations are just multiple queue type implemenations,
+ * Below are the various link lists currently necessary
+***************
+*** 152,165 ****
+ * ALL threads, in any state.
+ * Must lock kernel lock before manipulating.
+ */
+! struct pthread * pll;
+
+ /*
+ * Standard link list for running threads, mutexes, etc ...
+ * It can't be on both a running link list and a wait queue.
+ * Must lock kernel lock before manipulating.
+ */
+! struct pthread * next;
+ union pthread_wait_data data;
+
+ /*
+--- 216,229 ----
+ * ALL threads, in any state.
+ * Must lock kernel lock before manipulating.
+ */
+! struct pthread * pll;
+
+ /*
+ * Standard link list for running threads, mutexes, etc ...
+ * It can't be on both a running link list and a wait queue.
+ * Must lock kernel lock before manipulating.
+ */
+! struct pthread * next;
+ union pthread_wait_data data;
+
+ /*
+***************
+*** 167,197 ****
+ * (Note: "priority" is a reserved word in Concurrent C, please
+ * don't use it. --KR)
+ */
+! struct pthread_queue * queue;
+! enum pthread_state state;
+! char flags;
+! char pthread_priority;
+
+ /*
+ * Sleep queue, this is different from the standard link list
+ * because it is possible to be on both (pthread_cond_timedwait();
+ * Must lock sleep mutex before manipulating
+ */
+! struct pthread *sll; /* For sleeping threads */
+
+ /*
+ * Data that doesn't need to be locked
+! * Mostly it's because only the thread owning the data can manipulate it
+ */
+! void * ret;
+! int error;
+! int * error_p;
+! const void ** specific_data;
+! int specific_data_count;
+
+ /* Cleanup handlers Link List */
+ struct pthread_cleanup *cleanup;
+-
+ };
+
+ #else /* not PTHREAD_KERNEL */
+--- 231,261 ----
+ * (Note: "priority" is a reserved word in Concurrent C, please
+ * don't use it. --KR)
+ */
+! struct pthread_queue * queue;
+! enum pthread_state state;
+! enum pthread_state old_state; /* Used when cancelled */
+! char flags;
+! char pthread_priority;
+
+ /*
+ * Sleep queue, this is different from the standard link list
+ * because it is possible to be on both (pthread_cond_timedwait();
+ * Must lock sleep mutex before manipulating
+ */
+! struct pthread *sll; /* For sleeping threads */
+
+ /*
+ * Data that doesn't need to be locked
+! * Mostly because only the thread owning the data can manipulate it
+ */
+! void * ret;
+! int error;
+! int * error_p;
+! const void ** specific_data;
+! int specific_data_count;
+
+ /* Cleanup handlers Link List */
+ struct pthread_cleanup *cleanup;
+ };
+
+ #else /* not PTHREAD_KERNEL */
+***************
+*** 200,223 ****
+
+ #endif
+
+! typedef struct pthread * pthread_t;
+
+ /*
+ * Globals
+ */
+ #ifdef PTHREAD_KERNEL
+
+! extern struct pthread * pthread_run;
+! extern struct pthread * pthread_initial;
+! extern struct pthread * pthread_link_list;
+ extern struct pthread_queue pthread_dead_queue;
+ extern struct pthread_queue pthread_alloc_queue;
+
+! extern pthread_attr_t pthread_attr_default;
+! extern volatile int fork_lock;
+! extern pthread_size_t pthread_pagesize;
+!
+! extern sigset_t * uthread_sigmask;
+
+ #endif
+
+--- 264,293 ----
+
+ #endif
+
+! typedef struct pthread *pthread_t;
+
+ /*
+ * Globals
+ */
+ #ifdef PTHREAD_KERNEL
+
+! extern struct pthread * pthread_run;
+! extern struct pthread * pthread_initial;
+! extern struct pthread * pthread_link_list;
+ extern struct pthread_queue pthread_dead_queue;
+ extern struct pthread_queue pthread_alloc_queue;
+
+! extern pthread_attr_t pthread_attr_default;
+! extern volatile int fork_lock;
+! extern pthread_size_t pthread_pagesize;
+!
+! extern sigset_t * uthread_sigmask;
+!
+! /* Kernel global functions */
+! extern void pthread_sched_prevent(void);
+! extern void pthread_sched_resume(void);
+! extern int __pthread_is_valid( pthread_t );
+! extern void pthread_cancel_internal( int freelocks );
+
+ #endif
+
+***************
+*** 229,271 ****
+
+ #if defined(DCE_COMPAT)
+
+! typedef void * (*pthread_startroutine_t)(void *)
+! typedef void * pthread_addr_t
+
+! int pthread_create __P((pthread_t *, pthread_attr_t,
+! pthread_startroutine_t,
+! pthread_addr_t));
+! void pthread_exit __P((pthread_addr_t));
+! int pthread_join __P((pthread_t, pthread_addr_t *));
+
+ #else
+
+! 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));
+! void pthread_yield __P((void));
+!
+! int pthread_setschedparam __P((pthread_t pthread, int policy,
+! struct sched_param * param));
+! int pthread_getschedparam __P((pthread_t pthread, int * policy,
+! struct sched_param * param));
+!
+! int pthread_kill __P((struct pthread *, int));
+! int pthread_signal __P((int, void (*)(int)));
+
+ #endif
+
+ #if defined(PTHREAD_KERNEL)
+
+ /* Not valid, but I can't spell so this will be caught at compile time */
+! #define pthread_yeild(notvalid)
+
+ #endif
+
+--- 299,343 ----
+
+ #if defined(DCE_COMPAT)
+
+! typedef void * (*pthread_startroutine_t)(void *);
+! typedef void * pthread_addr_t;
+
+! int pthread_create __P((pthread_t *, pthread_attr_t,
+! pthread_startroutine_t, pthread_addr_t));
+! void pthread_exit __P((pthread_addr_t));
+! int pthread_join __P((pthread_t, pthread_addr_t *));
+
+ #else
+
+! 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));
+! void pthread_yield __P((void));
+!
+! int pthread_setschedparam __P((pthread_t pthread, int policy,
+! struct sched_param * param));
+! int pthread_getschedparam __P((pthread_t pthread, int * policy,
+! struct sched_param * param));
+!
+! int pthread_kill __P((struct pthread *, int));
+! int pthread_signal __P((int, void (*)(int)));
+!
+! int pthread_cancel __P(( pthread_t pthread ));
+! int pthread_setcancelstate __P(( int state, int *oldstate ));
+! int pthread_setcanceltype __P(( int type, int *oldtype ));
+! void pthread_testcancel __P(( void ));
+
+ #endif
+
+ #if defined(PTHREAD_KERNEL)
+
+ /* Not valid, but I can't spell so this will be caught at compile time */
+! #define pthread_yeild(notvalid)
+
+ #endif
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/include/signal.h,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 signal.h
+*** signal.h 1995/12/25 03:03:09 1.1.1.1
+--- signal.h 1996/09/26 21:46:04
+***************
+*** 43,48 ****
+--- 43,49 ----
+ __BEGIN_DECLS
+
+ int raise __P((int));
++ __sighandler_t signal __P((int __sig, __sighandler_t));
+
+ #ifndef _ANSI_SOURCE
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/include/pthread/kernel.h,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 kernel.h
+*** kernel.h 1994/12/13 07:09:01 1.1.1.1
+--- kernel.h 1996/10/02 19:08:41
+***************
+*** 42,48 ****
+ */
+ #if defined(PTHREAD_KERNEL)
+
+! #define PANIC() abort()
+
+ /* Time each rr thread gets */
+ #define PTHREAD_RR_TIMEOUT 100000000
+--- 42,54 ----
+ */
+ #if defined(PTHREAD_KERNEL)
+
+! #ifdef __GNUC__
+! #include <assert.h>
+! #define PANIC() panic_kernel( __FILE__, __LINE__, __ASSERT_FUNCTION )
+! #else
+! #define PANIC() panic_kernel( __FILE__, __LINE__, (const char *)0 )
+! #endif
+!
+
+ /* Time each rr thread gets */
+ #define PTHREAD_RR_TIMEOUT 100000000
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/machdep/syscall-i386-linux-1.0.S,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 syscall-i386-linux-1.0.S
+*** syscall-i386-linux-1.0.S 1995/09/27 04:38:55 1.1.1.1
+--- syscall-i386-linux-1.0.S 1996/06/04 19:20:17
+***************
+*** 147,154 ****
+
+ /* =========================================================================
+ * exit 1 select 82
+! * fork 2 socketcall 102
+! * read 3
+ * write 4
+ * open 5
+ * creat 8
+--- 147,154 ----
+
+ /* =========================================================================
+ * exit 1 select 82
+! * fork 2 fstatfs 100
+! * read 3 socketcall 102
+ * write 4
+ * open 5
+ * creat 8
+***************
+*** 160,166 ****
+ * chown 16
+ * lseek 19
+ * rename 38
+! * dup 41
+ * pipe 42
+ * ioctl 54
+ * fcntl 55
+--- 160,166 ----
+ * chown 16
+ * lseek 19
+ * rename 38
+! * dup 41
+ * pipe 42
+ * ioctl 54
+ * fcntl 55
+***************
+*** 302,314 ****
+ #endif
+
+ /* ==========================================================================
+! * machdep_sys_fstat()
+ */
+ #ifdef __ELF__
+ STATCALL2(lstat)
+ #else
+ SYSCALL2(lstat)
+ #endif
+
+ /* ==========================================================================
+ * machdep_sys_ftruncate()
+--- 302,320 ----
+ #endif
+
+ /* ==========================================================================
+! * machdep_sys_lstat()
+ */
+ #ifdef __ELF__
+ STATCALL2(lstat)
+ #else
+ SYSCALL2(lstat)
+ #endif
++
++ /* ==========================================================================
++ * machdep_sys_fstatfs()
++ */
++ SYSCALL2(fstatfs)
++
+
+ /* ==========================================================================
+ * machdep_sys_ftruncate()
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/machdep/linux-1.0/socket.h,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 socket.h
+*** socket.h 1995/12/26 02:28:03 1.1.1.1
+--- socket.h 1996/09/27 18:12:45
+***************
+*** 26,32 ****
+
+ #endif
+
+! /* #include <asm/socket.h> /* arch-dependent defines */
+ #include <linux/sockios.h> /* the SIOCxxx I/O controls */
+ #include <pthread/posix.h>
+
+--- 26,32 ----
+
+ #endif
+
+! /* #include <asm/socket.h> arch-dependent defines */
+ #include <linux/sockios.h> /* the SIOCxxx I/O controls */
+ #include <pthread/posix.h>
+
+***************
+*** 161,166 ****
+--- 161,188 ----
+ int connect __P((int, const struct sockaddr *, int));
+ int listen __P((int, int));
+ int socket __P((int, int, int));
++
++ int getsockopt __P ((int __s, int __level, int __optname,
++ void *__optval, int *__optlen));
++ int setsockopt __P ((int __s, int __level, int __optname,
++ __const void *__optval, int optlen));
++ int getsockname __P ((int __sockfd, struct sockaddr *__addr,
++ int *__paddrlen));
++ int getpeername __P ((int __sockfd, struct sockaddr *__peer,
++ int *__paddrlen));
++ ssize_t send __P ((int __sockfd, __const void *__buff, size_t __len, int __flags));
++ ssize_t recv __P ((int __sockfd, void *__buff, size_t __len, int __flags));
++ ssize_t sendto __P ((int __sockfd, __const void *__buff, size_t __len,
++ int __flags, __const struct sockaddr *__to,
++ int __tolen));
++ ssize_t recvfrom __P ((int __sockfd, void *__buff, size_t __len,
++ int __flags, struct sockaddr *__from,
++ int *__fromlen));
++ extern ssize_t sendmsg __P ((int __fd, __const struct msghdr *__message,
++ int __flags));
++ extern ssize_t recvmsg __P ((int __fd, struct msghdr *__message,
++ int __flags));
++ int shutdown __P ((int __sockfd, int __how));
+
+ __END_DECLS
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/machdep/linux-1.0/timers.h,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 timers.h
+*** timers.h 1996/03/05 08:28:36 1.1.1.1
+--- timers.h 1996/05/25 21:30:08
+***************
+*** 43,52 ****
+--- 43,54 ----
+ #include <sys/types.h>
+ #include <time.h>
+
++ #ifndef _LINUX_TIME_H
+ struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+ };
++ #endif /* _LINUX_TIME_H */
+
+ #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
+ (ts)->tv_sec = (tv)->tv_sec; \
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/net/getprotoent.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 getprotoent.c
+*** getprotoent.c 1996/02/09 05:39:41 1.1.1.1
+--- getprotoent.c 1996/05/27 01:11:27
+***************
+*** 128,135 ****
+ if (p != NULL)
+ *p++ = '\0';
+ }
+! if (p && *p);
+! break;
+ }
+ *alias = NULL;
+ pthread_mutex_unlock(&proto_file_lock);
+--- 128,135 ----
+ if (p != NULL)
+ *p++ = '\0';
+ }
+! if (p && *p)
+! break;
+ }
+ *alias = NULL;
+ pthread_mutex_unlock(&proto_file_lock);
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/net/proto_internal.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 proto_internal.c
+*** proto_internal.c 1996/02/09 05:39:49 1.1.1.1
+--- proto_internal.c 1996/06/04 16:25:57
+***************
+*** 49,55 ****
+ static int init_status;
+
+ /* Performs global initialization. */
+! char *_proto_init()
+ {
+ char *buf;
+
+--- 49,55 ----
+ static int init_status;
+
+ /* Performs global initialization. */
+! char *_proto_buf()
+ {
+ char *buf;
+
+***************
+*** 75,78 ****
+ {
+ init_status = pthread_key_create(&key, free);
+ }
+-
+--- 75,77 ----
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/net/res_internal.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 res_internal.c
+*** res_internal.c 1996/02/09 05:39:53 1.1.1.1
+--- res_internal.c 1996/09/25 23:31:11
+***************
+*** 144,149 ****
+--- 144,150 ----
+ break;
+ cp += n;
+ result->h_name = bp;
++ bp += strlen(bp) + 1;
+ iquery_done = 1;
+ break;
+ }
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/GNUmakefile.inc,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 GNUmakefile.inc
+*** GNUmakefile.inc 1995/08/30 22:27:04 1.1.1.1
+--- GNUmakefile.inc 1996/10/02 19:04:29
+***************
+*** 8,14 ****
+ syscall.S pthread_join.c pthread_detach.c pthread_once.c sleep.c \
+ specific.c process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \
+ pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \
+! dump_state.c pthread_kill.c stat.c readv.c writev.c condattr.c $(SRCS)
+
+ ifeq ($(HAVE_SYSCALL_TEMPLATE),yes)
+ SYSCALL_FILTER_RULE= for s in $(AVAILABLE_SYSCALLS) ; do \
+--- 8,15 ----
+ syscall.S pthread_join.c pthread_detach.c pthread_once.c sleep.c \
+ specific.c process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \
+ pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \
+! dump_state.c pthread_kill.c stat.c readv.c writev.c condattr.c \
+! pthread_cancel.c panic.c $(SRCS)
+
+ ifeq ($(HAVE_SYSCALL_TEMPLATE),yes)
+ SYSCALL_FILTER_RULE= for s in $(AVAILABLE_SYSCALLS) ; do \
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/Makefile.inc,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 Makefile.inc
+*** Makefile.inc 1995/08/22 22:09:07 1.1.1.1
+--- Makefile.inc 1996/10/02 19:04:38
+***************
+*** 8,14 ****
+ pthread_join.c pthread_detach.c pthread_once.c sleep.c specific.c \
+ process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \
+ pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \
+! dump_state.c pthread_kill.c condattr.c
+
+ .if $(HAVE_SYSCALL_TEMPLATE) == yes
+ OBJS+= syscalls.o
+--- 8,14 ----
+ pthread_join.c pthread_detach.c pthread_once.c sleep.c specific.c \
+ process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \
+ pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \
+! dump_state.c pthread_kill.c condattr.c pthread_cancel.c panic.c
+
+ .if $(HAVE_SYSCALL_TEMPLATE) == yes
+ OBJS+= syscalls.o
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/cond.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 cond.c
+*** cond.c 1996/03/05 08:29:12 1.1.1.1
+--- cond.c 1996/10/03 18:19:04
+***************
+*** 188,197 ****
+--- 188,204 ----
+ pthread_queue_enq(&cond->c_queue, pthread_run);
+ pthread_mutex_unlock(mutex);
+
++ pthread_run->data.mutex = mutex;
++
+ SET_PF_WAIT_EVENT(pthread_run);
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ /* Reschedule will unlock pthread_run */
+ pthread_resched_resume(PS_COND_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
+ CLEAR_PF_DONE_EVENT(pthread_run);
++
++ pthread_run->data.mutex = NULL;
++
+ rval = pthread_mutex_lock(mutex);
+ return(rval);
+ break;
+***************
+*** 203,212 ****
+--- 210,226 ----
+ pthread_mutex_unlock(mutex);
+ mutex->m_data.m_count = 1;
+
++ pthread_run->data.mutex = mutex;
++
+ SET_PF_WAIT_EVENT(pthread_run);
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ /* Reschedule will unlock pthread_run */
+ pthread_resched_resume(PS_COND_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
+ CLEAR_PF_DONE_EVENT(pthread_run);
++
++ pthread_run->data.mutex = NULL;
++
+ rval = pthread_mutex_lock(mutex);
+ mutex->m_data.m_count = count;
+ return(rval);
+***************
+*** 258,265 ****
+--- 272,285 ----
+ SET_PF_WAIT_EVENT(pthread_run);
+ pthread_mutex_unlock(mutex);
+
++ pthread_run->data.mutex = mutex;
++
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ /* Reschedule will unlock pthread_run */
+ pthread_resched_resume(PS_COND_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
++
++ pthread_run->data.mutex = NULL;
+
+ /* Remove ourselves from sleep queue. If we fail then we timedout */
+ if (sleep_cancel(pthread_run) == NOTOK) {
+***************
+*** 285,292 ****
+--- 305,318 ----
+ SET_PF_WAIT_EVENT(pthread_run);
+ pthread_mutex_unlock(mutex);
+
++ pthread_run->data.mutex = mutex;
++
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ /* Reschedule will unlock pthread_run */
+ pthread_resched_resume(PS_COND_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
++
++ pthread_run->data.mutex = NULL;
+
+ /* Remove ourselves from sleep queue. If we fail then we timedout */
+ if (sleep_cancel(pthread_run) == NOTOK) {
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/fd.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 fd.c
+*** fd.c 1996/02/09 02:54:19 1.1.1.1
+--- fd.c 1996/10/03 01:33:03
+***************
+*** 48,54 ****
+--- 48,59 ----
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/uio.h>
++ #include <sys/ioctl.h>
++ #if __STDC__
+ #include <stdarg.h>
++ #else
++ #include <varargs.h>
++ #endif
+ #include <fcntl.h>
+ #include <errno.h>
+ #include <pthread/posix.h>
+***************
+*** 62,67 ****
+--- 67,74 ----
+ static const int dtablecount = 4096/sizeof(struct fd_table_entry);
+ int dtablesize;
+
++ static int fd_get_pthread_fd_from_kernel_fd( int );
++
+ /* ==========================================================================
+ * Allocate dtablecount entries at once and populate the fd_table.
+ *
+***************
+*** 199,204 ****
+--- 206,244 ----
+ return(NOTOK);
+ }
+
++ /*----------------------------------------------------------------------
++ * Function: fd_get_pthread_fd_from_kernel_fd
++ * Purpose: get the fd_table index of a kernel fd
++ * Args: fd = kernel fd to convert
++ * Returns: fd_table index, -1 if not found
++ * Notes:
++ *----------------------------------------------------------------------*/
++ static int
++ fd_get_pthread_fd_from_kernel_fd( int kfd )
++ {
++ int j;
++
++ /* This is *SICK*, but unless there is a faster way to
++ * turn a kernel fd into an fd_table index, this has to do.
++ */
++ for( j=0; j < dtablesize; j++ ) {
++ if( fd_table[j] &&
++ fd_table[j]->type != FD_NT &&
++ fd_table[j]->type != FD_NIU &&
++ fd_table[j]->fd.i == kfd ) {
++ return j;
++ }
++ }
++
++ /* Not listed byfd, Check for kernel fd == pthread fd */
++ if( fd_table[kfd] == NULL || fd_table[kfd]->type == FD_NT ) {
++ /* Assume that the kernel fd is the same */
++ return kfd;
++ }
++
++ return NOTOK; /* Not found */
++ }
++
+ /* ==========================================================================
+ * fd_basic_basic_unlock()
+ *
+***************
+*** 288,293 ****
+--- 328,334 ----
+ switch (fd_table[fd]->type) {
+ case FD_NIU:
+ /* If not in use return EBADF error */
++ SET_ERRNO(EBADF);
+ return(NOTOK);
+ break;
+ case FD_NT:
+***************
+*** 297,302 ****
+--- 338,344 ----
+ */
+ fd_kern_init(fd);
+ if (fd_table[fd]->type == FD_NIU) {
++ SET_ERRNO(EBADF);
+ return(NOTOK);
+ }
+ break;
+***************
+*** 409,414 ****
+--- 451,545 ----
+ return(OK);
+ }
+
++ /*----------------------------------------------------------------------
++ * Function: fd_unlock_for_cancel
++ * Purpose: Unlock all fd locks held prior to being cancelled
++ * Args: void
++ * Returns:
++ * OK or NOTOK
++ * Notes:
++ * Assumes the kernel is locked on entry
++ *----------------------------------------------------------------------*/
++ int
++ fd_unlock_for_cancel( void )
++ {
++ int i, fd;
++ struct pthread_select_data *data;
++ int rdlk, wrlk, lktype;
++ int found;
++
++ /* What we do depends on the previous state of the thread */
++ switch( pthread_run->old_state ) {
++ case PS_RUNNING:
++ case PS_JOIN:
++ case PS_SLEEP_WAIT:
++ case PS_WAIT_WAIT:
++ case PS_SIGWAIT:
++ case PS_FDLR_WAIT:
++ case PS_FDLW_WAIT:
++ case PS_DEAD:
++ case PS_UNALLOCED:
++ break; /* Nothing to do */
++
++ case PS_COND_WAIT:
++ CLEAR_PF_GROUP( pthread_run, PF_EVENT_GROUP );
++ /* Must reaquire the mutex according to the standard */
++ if( pthread_run->data.mutex == NULL ) {
++ PANIC();
++ }
++ pthread_mutex_lock( pthread_run->data.mutex );
++ break;
++
++ case PS_FDR_WAIT:
++ CLEAR_PF_GROUP( pthread_run, PF_EVENT_GROUP);
++ /* Free the lock on the fd being used */
++ fd = fd_get_pthread_fd_from_kernel_fd( pthread_run->data.fd.fd );
++ if( fd == NOTOK ) {
++ PANIC(); /* Can't find fd */
++ }
++ fd_unlock( fd, FD_READ );
++ break;
++
++ case PS_FDW_WAIT: /* Waiting on i/o */
++ CLEAR_PF_GROUP( pthread_run, PF_EVENT_GROUP);
++ /* Free the lock on the fd being used */
++ fd = fd_get_pthread_fd_from_kernel_fd( pthread_run->data.fd.fd );
++ if( fd == NOTOK ) {
++ PANIC(); /* Can't find fd */
++ }
++ fd_unlock( fd, FD_WRITE );
++ break;
++
++ case PS_SELECT_WAIT:
++ data = pthread_run->data.select_data;
++
++ CLEAR_PF_GROUP( pthread_run, PF_EVENT_GROUP);
++
++ for( i = 0; i < data->nfds; i++) {
++ rdlk =(FD_ISSET(i,&data->readfds)
++ || FD_ISSET(i,&data->exceptfds));
++ wrlk = FD_ISSET(i, &data->writefds);
++ lktype = rdlk ? (wrlk ? FD_RDWR : FD_READ) : FD_WRITE;
++
++ if( ! (rdlk || wrlk) )
++ continue; /* No locks, no unlock */
++
++ if( (fd = fd_get_pthread_fd_from_kernel_fd( i )) == NOTOK ) {
++ PANIC(); /* Can't find fd */
++ }
++
++ fd_unlock( fd, lktype );
++ }
++ break;
++
++ case PS_MUTEX_WAIT:
++ PANIC(); /* Should never cancel a mutex wait */
++
++ default:
++ PANIC(); /* Unknown thread status */
++ }
++ }
++
+ /* ==========================================================================
+ * fd_lock()
+ */
+***************
+*** 476,481 ****
+--- 607,616 ----
+ ret = fd_table[fd]->ops->read(fd_table[fd]->fd,
+ fd_table[fd]->flags, buf, nbytes, timeout);
+ fd_unlock(fd, FD_READ);
++ if( ret < 0 ) {
++ SET_ERRNO(-ret);
++ ret = NOTOK;
++ }
+ }
+ return(ret);
+ }
+***************
+*** 500,505 ****
+--- 635,644 ----
+ ret = fd_table[fd]->ops->readv(fd_table[fd]->fd,
+ fd_table[fd]->flags, iov, iovcnt, timeout);
+ fd_unlock(fd, FD_READ);
++ if( ret < 0 ) {
++ SET_ERRNO(-ret);
++ ret = NOTOK;
++ }
+ }
+ return(ret);
+ }
+***************
+*** 524,529 ****
+--- 663,672 ----
+ ret = fd_table[fd]->ops->write(fd_table[fd]->fd,
+ fd_table[fd]->flags, buf, nbytes, timeout);
+ fd_unlock(fd, FD_WRITE);
++ if( ret < 0 ) {
++ SET_ERRNO(-ret);
++ ret = NOTOK;
++ }
+ }
+ return(ret);
+ }
+***************
+*** 548,553 ****
+--- 691,700 ----
+ ret = fd_table[fd]->ops->writev(fd_table[fd]->fd,
+ fd_table[fd]->flags, iov, iovcnt, timeout);
+ fd_unlock(fd, FD_WRITE);
++ if( ret < 0 ) {
++ SET_ERRNO(-ret);
++ ret = NOTOK;
++ }
+ }
+ return(ret);
+ }
+***************
+*** 599,677 ****
+ union fd_data realfd;
+ int ret, flags;
+
+ /* Need to lock the newfd by hand */
+! if (fd < dtablesize) {
+! pthread_mutex_lock(&fd_table_mutex);
+! if (fd_table[fd]) {
+! pthread_mutex_unlock(&fd_table_mutex);
+! mutex = &(fd_table[fd]->mutex);
+! pthread_mutex_lock(mutex);
+
+! /*
+! * XXX Gross hack ... because of fork(), any fd closed by the
+! * parent should not change the fd of the child, unless it owns it.
+ */
+! switch(fd_table[fd]->type) {
+! case FD_NIU:
+! pthread_mutex_unlock(mutex);
+! ret = -EINVAL;
+! break;
+! case FD_NT:
+! /*
+! * If it's not tested then the only valid possibility is it's
+! * kernel fd.
+! */
+! ret = machdep_sys_close(fd);
+! fd_table[fd]->type = FD_NIU;
+! pthread_mutex_unlock(mutex);
+! break;
+! case FD_TEST_FULL_DUPLEX:
+! case FD_TEST_HALF_DUPLEX:
+ realfd = fd_table[fd]->fd;
+ flags = fd_table[fd]->flags;
+ if ((entry = fd_free(fd)) == NULL) {
+! ret = fd_table[fd]->ops->close(realfd, flags);
+ } else {
+! /* There can't be any others waiting for fd. */
+ pthread_mutex_unlock(&entry->mutex);
+ /* Note: entry->mutex = mutex */
+- mutex = &(fd_table[fd]->mutex);
+ }
+ pthread_mutex_unlock(mutex);
+- break;
+- default:
+- ret = fd_basic_lock(fd, FD_RDWR, mutex, NULL);
+- if (ret == OK) {
+- realfd = fd_table[fd]->fd;
+- flags = fd_table[fd]->flags;
+- pthread_mutex_unlock(mutex);
+- if ((entry = fd_free(fd)) == NULL) {
+- ret = fd_table[fd]->ops->close(realfd, flags);
+- } else {
+- fd_basic_basic_unlock(entry, FD_RDWR);
+- pthread_mutex_unlock(&entry->mutex);
+- /* Note: entry->mutex = mutex */
+- }
+- fd_unlock(fd, FD_RDWR);
+- } else {
+- pthread_mutex_unlock(mutex);
+- }
+- break;
+ }
+! } else {
+! /* Don't bother creating a table entry */
+! pthread_mutex_unlock(&fd_table_mutex);
+! ret = machdep_sys_close(fd);
+ }
+! return(ret);
+ }
+! return(-EINVAL);
+ }
+
+ /* ==========================================================================
+ * fd_basic_dup()
+ *
+ * Might need to do more than just what's below.
+ */
+ static inline void fd_basic_dup(int fd, int newfd)
+ {
+--- 746,836 ----
+ union fd_data realfd;
+ int ret, flags;
+
++ if( fd < 0 || fd >= dtablesize ) {
++ SET_ERRNO(EBADF);
++ return -1;
++ }
++
+ /* Need to lock the newfd by hand */
+! pthread_mutex_lock(&fd_table_mutex);
+! if (fd_table[fd]) {
+! pthread_mutex_unlock(&fd_table_mutex);
+! mutex = &(fd_table[fd]->mutex);
+! pthread_mutex_lock(mutex);
+
+! /*
+! * XXX Gross hack ... because of fork(), any fd closed by the
+! * parent should not change the fd of the child, unless it owns it.
+! */
+! switch(fd_table[fd]->type) {
+! case FD_NIU:
+! pthread_mutex_unlock(mutex);
+! ret = -EBADF;
+! break;
+! case FD_NT:
+! /*
+! * If it's not tested then the only valid possibility is it's
+! * kernel fd.
+ */
+! ret = machdep_sys_close(fd);
+! fd_table[fd]->type = FD_NIU;
+! pthread_mutex_unlock(mutex);
+! break;
+! case FD_TEST_FULL_DUPLEX:
+! case FD_TEST_HALF_DUPLEX:
+! realfd = fd_table[fd]->fd;
+! flags = fd_table[fd]->flags;
+! if ((entry = fd_free(fd)) == NULL) {
+! ret = fd_table[fd]->ops->close(realfd, flags);
+! } else {
+! /* There can't be any others waiting for fd. */
+! pthread_mutex_unlock(&entry->mutex);
+! /* Note: entry->mutex = mutex */
+! mutex = &(fd_table[fd]->mutex);
+! }
+! pthread_mutex_unlock(mutex);
+! break;
+! default:
+! ret = fd_basic_lock(fd, FD_RDWR, mutex, NULL);
+! if (ret == OK) {
+ realfd = fd_table[fd]->fd;
+ flags = fd_table[fd]->flags;
++ pthread_mutex_unlock(mutex);
+ if ((entry = fd_free(fd)) == NULL) {
+! ret = fd_table[fd]->ops->close(realfd, flags);
+ } else {
+! fd_basic_basic_unlock(entry, FD_RDWR);
+ pthread_mutex_unlock(&entry->mutex);
+ /* Note: entry->mutex = mutex */
+ }
++ fd_unlock(fd, FD_RDWR);
++ } else {
+ pthread_mutex_unlock(mutex);
+ }
+! break;
+ }
+! } else {
+! /* Don't bother creating a table entry */
+! pthread_mutex_unlock(&fd_table_mutex);
+! ret = machdep_sys_close(fd);
+! }
+!
+! if( ret < 0 ) {
+! SET_ERRNO(-ret);
+! ret = -1;
+ }
+!
+! return ret;
+ }
+
+ /* ==========================================================================
+ * fd_basic_dup()
+ *
+ * Might need to do more than just what's below.
++ *
++ * This is a MAJOR guess!! I don't know if the mutext unlock is valid
++ * in the BIG picture. But it seems to be needed to avoid deadlocking
++ * with ourselves when we try to close the duped file descriptor.
+ */
+ static inline void fd_basic_dup(int fd, int newfd)
+ {
+***************
+*** 679,684 ****
+--- 838,845 ----
+ fd_table[fd]->next = fd_table[newfd];
+ fd_table[newfd] = fd_table[fd];
+ fd_table[fd]->count++;
++ pthread_mutex_unlock(&fd_table[newfd]->next->mutex);
++
+ }
+
+ /* ==========================================================================
+***************
+*** 896,904 ****
+ * ala select()... --SNL
+ */
+ int
+! ioctl(int fd, unsigned long request, caddr_t arg)
+ {
+ int ret;
+
+ if (fd < 0 || fd >= dtablesize)
+ ret = NOTOK;
+--- 1057,1071 ----
+ * ala select()... --SNL
+ */
+ int
+! ioctl(int fd, int request, ...)
+ {
+ int ret;
++ pthread_va_list ap;
++ caddr_t arg;
++
++ va_start( ap, request ); /* Get the arg */
++ arg = va_arg(ap,caddr_t);
++ va_end( ap );
+
+ if (fd < 0 || fd >= dtablesize)
+ ret = NOTOK;
+***************
+*** 906,911 ****
+--- 1073,1086 ----
+ ret = machdep_sys_ioctl(fd, request, arg);
+ else if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+ ret = machdep_sys_ioctl(fd_table[fd]->fd.i, request, arg);
++ if( ret == 0 && request == FIONBIO ) {
++ /* Properly set NONBLOCK flag */
++ int v = *(int *)arg;
++ if( v )
++ fd_table[fd]->flags |= __FD_NONBLOCK;
++ else
++ fd_table[fd]->flags &= ~__FD_NONBLOCK;
++ }
+ fd_unlock(fd, FD_RDWR);
+ }
+ return ret;
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/fd_kern.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 fd_kern.c
+*** fd_kern.c 1996/02/12 00:58:30 1.1.1.1
+--- fd_kern.c 1996/10/03 01:54:15
+***************
+*** 128,134 ****
+
+
+ if ((count = machdep_sys_select(dtablesize, &fd_set_read,
+! &fd_set_write, NULL, &__fd_kern_poll_timeout)) < OK) {
+ if (count == -EINTR) {
+ return;
+ }
+--- 128,134 ----
+
+
+ if ((count = machdep_sys_select(dtablesize, &fd_set_read,
+! &fd_set_write, &fd_set_except, &__fd_kern_poll_timeout)) < OK) {
+ if (count == -EINTR) {
+ return;
+ }
+***************
+*** 167,200 ****
+
+ for (pthread = fd_wait_select.q_next; count && pthread; ) {
+ int found_one = 0;
+
+ for (i = 0; i < pthread->data.select_data->nfds; i++) {
+ int count_dec = 0;
+
+! if ((FD_ISSET(i, &pthread->data.select_data->exceptfds) &&
+! ! FD_ISSET(i, &fd_set_except))) {
+! FD_CLR(i, &pthread->data.select_data->exceptfds);
+! } else {
+! count_dec++;
+ }
+! if ((FD_ISSET(i, &pthread->data.select_data->writefds) &&
+! ! FD_ISSET(i, &fd_set_write))) {
+! FD_CLR(i, &pthread->data.select_data->writefds);
+! } else {
+! count_dec++;
+ }
+! if ((FD_ISSET(i, &pthread->data.select_data->readfds) &&
+! ! FD_ISSET(i, &fd_set_read))) {
+! FD_CLR(i, &pthread->data.select_data->readfds);
+! } else {
+! count_dec++;
+ }
+ if (count_dec) {
+ found_one++;
+ count--;
+ }
+ }
+ if (found_one) {
+ deq = pthread;
+ pthread = pthread->next;
+ pthread_queue_remove(&fd_wait_select, deq);
+--- 167,223 ----
+
+ for (pthread = fd_wait_select.q_next; count && pthread; ) {
+ int found_one = 0;
++ fd_set tmp_readfds, tmp_writefds, tmp_exceptfds;
++
++ memcpy(&tmp_readfds, &pthread->data.select_data->readfds,
++ sizeof(fd_set));
++ memcpy(&tmp_writefds, &pthread->data.select_data->writefds,
++ sizeof(fd_set));
++ memcpy(&tmp_exceptfds, &pthread->data.select_data->exceptfds,
++ sizeof(fd_set));
+
+ for (i = 0; i < pthread->data.select_data->nfds; i++) {
+ int count_dec = 0;
+
+! if( (FD_ISSET(i, &tmp_exceptfds)) ) {
+! if( FD_ISSET(i, &fd_set_except) ) {
+! count_dec++; /* got a hit */
+! } else {
+! FD_CLR(i, &tmp_exceptfds);
+! }
+ }
+!
+! if( (FD_ISSET(i, &tmp_writefds)) ) {
+! if( FD_ISSET(i, &fd_set_write) ) {
+! count_dec++; /* got a hit */
+! } else {
+! FD_CLR(i, &tmp_writefds);
+! }
+ }
+!
+! if( (FD_ISSET(i, &tmp_readfds)) ) {
+! if( FD_ISSET(i, &fd_set_read) ) {
+! count_dec++; /* got a hit */
+! } else {
+! FD_CLR(i, &tmp_readfds);
+! }
+ }
++
+ if (count_dec) {
+ found_one++;
+ count--;
+ }
+ }
++
+ if (found_one) {
++ /* Update the threads saved select data fd sets */
++ memcpy(&pthread->data.select_data->readfds, &tmp_readfds,
++ sizeof(fd_set));
++ memcpy(&pthread->data.select_data->writefds, &tmp_writefds,
++ sizeof(fd_set));
++ memcpy(&pthread->data.select_data->exceptfds, &tmp_exceptfds,
++ sizeof(fd_set));
++
+ deq = pthread;
+ pthread = pthread->next;
+ pthread_queue_remove(&fd_wait_select, deq);
+***************
+*** 266,272 ****
+ */
+
+ while ((count = machdep_sys_select(dtablesize, &fd_set_read,
+! &fd_set_write, NULL, &__fd_kern_wait_timeout)) < OK) {
+ if (count == -EINTR) {
+ return;
+ }
+--- 289,295 ----
+ */
+
+ while ((count = machdep_sys_select(dtablesize, &fd_set_read,
+! &fd_set_write, &fd_set_except, &__fd_kern_wait_timeout)) < OK) {
+ if (count == -EINTR) {
+ return;
+ }
+***************
+*** 305,338 ****
+
+ for (pthread = fd_wait_select.q_next; count && pthread; ) {
+ int found_one = 0;
+
+ for (i = 0; i < pthread->data.select_data->nfds; i++) {
+ int count_dec = 0;
+
+! if ((FD_ISSET(i, &pthread->data.select_data->exceptfds) &&
+! ! FD_ISSET(i, &fd_set_except))) {
+! FD_CLR(i, &pthread->data.select_data->exceptfds);
+! } else {
+! count_dec++;
+ }
+! if ((FD_ISSET(i, &pthread->data.select_data->writefds) &&
+! ! FD_ISSET(i, &fd_set_write))) {
+! FD_CLR(i, &pthread->data.select_data->writefds);
+! } else {
+! count_dec++;
+ }
+! if ((FD_ISSET(i, &pthread->data.select_data->readfds) &&
+! ! FD_ISSET(i, &fd_set_read))) {
+! FD_CLR(i, &pthread->data.select_data->readfds);
+! } else {
+! count_dec++;
+ }
+ if (count_dec) {
+ found_one++;
+ count--;
+ }
+ }
+ if (found_one) {
+ deq = pthread;
+ pthread = pthread->next;
+ pthread_queue_remove(&fd_wait_select, deq);
+--- 328,383 ----
+
+ for (pthread = fd_wait_select.q_next; count && pthread; ) {
+ int found_one = 0;
++ fd_set tmp_readfds, tmp_writefds, tmp_exceptfds;
++
++ memcpy(&tmp_readfds, &pthread->data.select_data->readfds,
++ sizeof(fd_set));
++ memcpy(&tmp_writefds, &pthread->data.select_data->writefds,
++ sizeof(fd_set));
++ memcpy(&tmp_exceptfds, &pthread->data.select_data->exceptfds,
++ sizeof(fd_set));
+
+ for (i = 0; i < pthread->data.select_data->nfds; i++) {
+ int count_dec = 0;
+
+! if( (FD_ISSET(i, &tmp_exceptfds)) ) {
+! if( FD_ISSET(i, &fd_set_except) ) {
+! count_dec++; /* got a hit */
+! } else {
+! FD_CLR(i, &tmp_exceptfds);
+! }
+ }
+!
+! if( (FD_ISSET(i, &tmp_writefds)) ) {
+! if( FD_ISSET(i, &fd_set_write) ) {
+! count_dec++; /* got a hit */
+! } else {
+! FD_CLR(i, &tmp_writefds);
+! }
+ }
+!
+! if( (FD_ISSET(i, &tmp_readfds)) ) {
+! if( FD_ISSET(i, &fd_set_read) ) {
+! count_dec++; /* got a hit */
+! } else {
+! FD_CLR(i, &tmp_readfds);
+! }
+ }
++
+ if (count_dec) {
+ found_one++;
+ count--;
+ }
+ }
+ if (found_one) {
++ /* Update the threads saved select data fd sets */
++ memcpy(&pthread->data.select_data->readfds, &tmp_readfds,
++ sizeof(fd_set));
++ memcpy(&pthread->data.select_data->writefds, &tmp_writefds,
++ sizeof(fd_set));
++ memcpy(&pthread->data.select_data->exceptfds, &tmp_exceptfds,
++ sizeof(fd_set));
++
+ deq = pthread;
+ pthread = pthread->next;
+ pthread_queue_remove(&fd_wait_select, deq);
+***************
+*** 380,404 ****
+ machdep_gettimeofday(&current_time);
+ sleep_schedule(&current_time, timeout);
+
+ pthread_resched_resume(PS_FDR_WAIT);
+
+ /* We're awake */
+ pthread_sched_prevent();
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+- SET_ERRNO(ETIMEDOUT);
+ ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+ } else {
+ pthread_resched_resume(PS_FDR_WAIT);
+ }
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+- SET_ERRNO(-ret);
+- ret = NOTOK;
+ break;
+ }
+ }
+--- 425,450 ----
+ machdep_gettimeofday(&current_time);
+ sleep_schedule(&current_time, timeout);
+
++ SET_PF_AT_CANCEL_POINT(pthread_run);
+ pthread_resched_resume(PS_FDR_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run);
+
+ /* We're awake */
+ pthread_sched_prevent();
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+ } else {
++ SET_PF_AT_CANCEL_POINT(pthread_run);
+ pthread_resched_resume(PS_FDR_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run);
+ }
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+ break;
+ }
+ }
+***************
+*** 437,443 ****
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+- SET_ERRNO(ETIMEDOUT);
+ ret = -ETIMEDOUT;
+ break;
+ }
+--- 483,488 ----
+***************
+*** 447,454 ****
+ }
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+- SET_ERRNO(-ret);
+- ret = NOTOK;
+ break;
+ }
+ }
+--- 492,497 ----
+***************
+*** 480,504 ****
+ machdep_gettimeofday(&current_time);
+ sleep_schedule(&current_time, timeout);
+
+ pthread_resched_resume(PS_FDW_WAIT);
+
+ /* We're awake */
+ pthread_sched_prevent();
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+- SET_ERRNO(ETIMEDOUT);
+ ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+ } else {
+ pthread_resched_resume(PS_FDW_WAIT);
+ }
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+- SET_ERRNO(-ret);
+- ret = NOTOK;
+ break;
+ }
+ }
+--- 523,548 ----
+ machdep_gettimeofday(&current_time);
+ sleep_schedule(&current_time, timeout);
+
++ SET_PF_AT_CANCEL_POINT(pthread_run);
+ pthread_resched_resume(PS_FDW_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run);
+
+ /* We're awake */
+ pthread_sched_prevent();
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+ } else {
++ SET_PF_AT_CANCEL_POINT(pthread_run);
+ pthread_resched_resume(PS_FDW_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run);
+ }
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+ break;
+ }
+ }
+***************
+*** 537,543 ****
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+- SET_ERRNO(ETIMEDOUT);
+ ret = -ETIMEDOUT;
+ break;
+ }
+--- 581,586 ----
+***************
+*** 547,554 ****
+ }
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+- SET_ERRNO(-ret);
+- ret = NOTOK;
+ break;
+ }
+ }
+--- 590,595 ----
+***************
+*** 662,668 ****
+ */
+ int create(const char *path, mode_t mode)
+ {
+! return creat (path, mode);
+ }
+
+ /* ==========================================================================
+--- 703,709 ----
+ */
+ int create(const char *path, mode_t mode)
+ {
+! return creat (path, mode);
+ }
+
+ /* ==========================================================================
+***************
+*** 672,678 ****
+
+ int creat(const char *path, mode_t mode)
+ {
+! return open (path, O_CREAT | O_TRUNC | O_WRONLY, mode);
+ }
+
+ /* ==========================================================================
+--- 713,719 ----
+
+ int creat(const char *path, mode_t mode)
+ {
+! return open (path, O_CREAT | O_TRUNC | O_WRONLY, mode);
+ }
+
+ /* ==========================================================================
+***************
+*** 1079,1090 ****
+ int bind(int fd, const struct sockaddr *name, int namelen)
+ {
+ /* Not much to do in bind */
+- semaphore *plock;
+ int ret;
+
+ if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+ if ((ret = machdep_sys_bind(fd_table[fd]->fd.i, name, namelen)) < OK) {
+ SET_ERRNO(-ret);
+ }
+ fd_unlock(fd, FD_RDWR);
+ }
+--- 1120,1131 ----
+ int bind(int fd, const struct sockaddr *name, int namelen)
+ {
+ /* Not much to do in bind */
+ int ret;
+
+ if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+ if ((ret = machdep_sys_bind(fd_table[fd]->fd.i, name, namelen)) < OK) {
+ SET_ERRNO(-ret);
++ ret = NOTOK;
+ }
+ fd_unlock(fd, FD_RDWR);
+ }
+***************
+*** 1100,1113 ****
+ */
+ int connect(int fd, const struct sockaddr *name, int namelen)
+ {
+! struct sockaddr tmpname;
+! int ret, tmpnamelen;
+
+! if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+ if ((ret = machdep_sys_connect(fd_table[fd]->fd.i, name, namelen)) < OK) {
+ if (!(fd_table[fd]->flags & __FD_NONBLOCK) &&
+! ((ret == -EWOULDBLOCK) || (ret == -EINPROGRESS) ||
+! (ret == -EALREADY) || (ret == -EAGAIN))) {
+ pthread_sched_prevent();
+
+ /* queue pthread for a FDW_WAIT */
+--- 1141,1154 ----
+ */
+ int connect(int fd, const struct sockaddr *name, int namelen)
+ {
+! struct sockaddr tmpname;
+! int ret, tmpnamelen;
+
+! if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+ if ((ret = machdep_sys_connect(fd_table[fd]->fd.i, name, namelen)) < OK) {
+ if (!(fd_table[fd]->flags & __FD_NONBLOCK) &&
+! ((ret == -EWOULDBLOCK) || (ret == -EINPROGRESS) ||
+! (ret == -EALREADY) || (ret == -EAGAIN))) {
+ pthread_sched_prevent();
+
+ /* queue pthread for a FDW_WAIT */
+***************
+*** 1121,1131 ****
+ tmpnamelen = sizeof(tmpname);
+ /* OK now lets see if it really worked */
+ if (((ret = machdep_sys_getpeername(fd_table[fd]->fd.i,
+! &tmpname, &tmpnamelen)) < OK) && (ret == -ENOTCONN)) {
+
+ /* Get the error, this function should not fail */
+ machdep_sys_getsockopt(fd_table[fd]->fd.i, SOL_SOCKET,
+! SO_ERROR, &pthread_run->error, &tmpnamelen);
+ }
+ } else {
+ SET_ERRNO(-ret);
+--- 1162,1180 ----
+ tmpnamelen = sizeof(tmpname);
+ /* OK now lets see if it really worked */
+ if (((ret = machdep_sys_getpeername(fd_table[fd]->fd.i,
+! &tmpname, &tmpnamelen)) < OK)
+! && (ret == -ENOTCONN)) {
+
+ /* Get the error, this function should not fail */
+ machdep_sys_getsockopt(fd_table[fd]->fd.i, SOL_SOCKET,
+! SO_ERROR, &ret, &tmpnamelen);
+! SET_ERRNO(-ret);
+! ret = NOTOK;
+! } else {
+! if( ret < 0 ) {
+! SET_ERRNO(-ret);
+! ret = NOTOK;
+! }
+ }
+ } else {
+ SET_ERRNO(-ret);
+***************
+*** 1133,1140 ****
+ }
+ }
+ fd_unlock(fd, FD_RDWR);
+! }
+! return(ret);
+ }
+
+ #endif
+--- 1182,1189 ----
+ }
+ }
+ fd_unlock(fd, FD_RDWR);
+! }
+! return(ret);
+ }
+
+ #endif
+***************
+*** 1164,1170 ****
+ } else {
+ fd_unlock(fd, FD_RDWR);
+ SET_ERRNO(-fd_kern);
+! return(fd_kern);
+ }
+ }
+ fd_unlock(fd, FD_RDWR);
+--- 1213,1219 ----
+ } else {
+ fd_unlock(fd, FD_RDWR);
+ SET_ERRNO(-fd_kern);
+! return(NOTOK);
+ }
+ }
+ fd_unlock(fd, FD_RDWR);
+***************
+*** 1198,1205 ****
+ int ret;
+
+ if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+! ret = machdep_sys_listen(fd_table[fd]->fd.i, backlog);
+! if ((ret = machdep_sys_listen(fd_table[fd]->fd.i, backlog)) < OK) {
+ SET_ERRNO(-ret);
+ ret = NOTOK;
+ }
+--- 1247,1253 ----
+ int ret;
+
+ if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
+! if ((ret = machdep_sys_listen(fd_table[fd]->fd.i, backlog)) < OK) {
+ SET_ERRNO(-ret);
+ ret = NOTOK;
+ }
+***************
+*** 1246,1252 ****
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+--- 1294,1300 ----
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = NOTOK;
+ break;
+ }
+ pthread_sched_resume();
+***************
+*** 1311,1317 ****
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+--- 1359,1365 ----
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = NOTOK;
+ break;
+ }
+ pthread_sched_resume();
+***************
+*** 1405,1411 ****
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+--- 1453,1459 ----
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = NOTOK;
+ break;
+ }
+ pthread_sched_resume();
+***************
+*** 1471,1477 ****
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+--- 1519,1525 ----
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = NOTOK;
+ break;
+ }
+ pthread_sched_resume();
+***************
+*** 1536,1542 ****
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+--- 1584,1590 ----
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = NOTOK;
+ break;
+ }
+ pthread_sched_resume();
+***************
+*** 1603,1609 ****
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = -ETIMEDOUT;
+ break;
+ }
+ pthread_sched_resume();
+--- 1651,1657 ----
+ CLEAR_PF_DONE_EVENT(pthread_run);
+ pthread_sched_resume();
+ SET_ERRNO(ETIMEDOUT);
+! ret = NOTOK;
+ break;
+ }
+ pthread_sched_resume();
+***************
+*** 1734,1744 ****
+ */
+ int getsockopt(int fd, int level, int optname, void * optval, int * optlen)
+ {
+! int ret;
+
+! if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
+ if ((ret = machdep_sys_getsockopt(fd_table[fd]->fd.i, level,
+! optname, optval, optlen)) < OK) {
+ SET_ERRNO(-ret);
+ ret = NOTOK;
+ }
+--- 1782,1792 ----
+ */
+ int getsockopt(int fd, int level, int optname, void * optval, int * optlen)
+ {
+! int ret;
+
+! if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
+ if ((ret = machdep_sys_getsockopt(fd_table[fd]->fd.i, level,
+! optname, optval, optlen)) < OK) {
+ SET_ERRNO(-ret);
+ ret = NOTOK;
+ }
+***************
+*** 1756,1772 ****
+ */
+ int getsockname(int fd, struct sockaddr * name, int * naddrlen)
+ {
+! int ret;
+
+! if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
+! if ((ret = machdep_sys_getsockname(fd_table[fd]->fd.i,
+! name, naddrlen)) < OK) {
+! SET_ERRNO(-ret);
+! ret = NOTOK;
+! }
+! fd_unlock(fd, FD_RDWR);
+! }
+! return ret;
+ }
+
+ #endif
+--- 1804,1820 ----
+ */
+ int getsockname(int fd, struct sockaddr * name, int * naddrlen)
+ {
+! int ret;
+
+! if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
+! if ((ret = machdep_sys_getsockname(fd_table[fd]->fd.i,
+! name, naddrlen)) < OK) {
+! SET_ERRNO(-ret);
+! ret = NOTOK;
+! }
+! fd_unlock(fd, FD_RDWR);
+! }
+! return ret;
+ }
+
+ #endif
+***************
+*** 1778,1793 ****
+ */
+ int getpeername(int fd, struct sockaddr * peer, int * paddrlen)
+ {
+! int ret;
+
+! if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
+! if ((ret = machdep_sys_getpeername(fd_table[fd]->fd.i,
+! peer, paddrlen)) < OK) {
+ SET_ERRNO(-ret);
+ ret = NOTOK;
+! }
+! fd_unlock(fd, FD_READ);
+! }
+ return ret;
+ }
+
+--- 1826,1841 ----
+ */
+ int getpeername(int fd, struct sockaddr * peer, int * paddrlen)
+ {
+! int ret;
+
+! if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
+! if ((ret = machdep_sys_getpeername(fd_table[fd]->fd.i,
+! peer, paddrlen)) < OK) {
+ SET_ERRNO(-ret);
+ ret = NOTOK;
+! }
+! fd_unlock(fd, FD_READ);
+! }
+ return ret;
+ }
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/pthread.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 pthread.c
+*** pthread.c 1995/12/13 05:53:01 1.1.1.1
+--- pthread.c 1996/10/01 21:42:01
+***************
+*** 129,134 ****
+--- 129,160 ----
+
+ }
+
++ /*----------------------------------------------------------------------
++ * Function: __pthread_is_valid
++ * Purpose: Scan the list of threads to see if a specified thread exists
++ * Args:
++ * pthread = The thread to scan for
++ * Returns:
++ * int = 1 if found, 0 if not
++ * Notes:
++ * The kernel is assumed to be locked
++ *----------------------------------------------------------------------*/
++ int
++ __pthread_is_valid( pthread_t pthread )
++ {
++ int rtn = 0; /* Assume not found */
++ pthread_t t;
++
++ for( t = pthread_link_list; t; t = t->pll ) {
++ if( t == pthread ) {
++ rtn = 1; /* Found it */
++ break;
++ }
++ }
++
++ return rtn;
++ }
++
+ /* ==========================================================================
+ * __pthread_free()
+ */
+***************
+*** 242,247 ****
+--- 268,277 ----
+ new_thread->next = NULL;
+ new_thread->flags = 0;
+
++ /* PTHREADS spec says we start with cancellability on and deferred */
++ SET_PF_CANCEL_STATE(new_thread, PTHREAD_CANCEL_ENABLE);
++ SET_PF_CANCEL_TYPE(new_thread, PTHREAD_CANCEL_DEFERRED);
++
+ new_thread->error_p = NULL;
+ new_thread->sll = NULL;
+
+***************
+*** 261,269 ****
+ }
+ return(retval);
+ }
+-
+- /* ==========================================================================
+- * pthread_cancel()
+- *
+- * This routine will also require a sig_prevent/sig_check_and_resume()
+- */
+--- 291,293 ----
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/pthread_init.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 pthread_init.c
+*** pthread_init.c 1996/03/13 04:33:10 1.1.1.1
+--- pthread_init.c 1996/10/01 21:43:59
+***************
+*** 92,99 ****
+ pthread_initial->next = NULL;
+ pthread_initial->flags = 0;
+ pthread_initial->pll = NULL;
+- pthread_initial->flags = 0;
+ pthread_initial->sll = NULL;
+
+ /* Ugly errno hack */
+ pthread_initial->error_p = &errno;
+--- 92,103 ----
+ pthread_initial->next = NULL;
+ pthread_initial->flags = 0;
+ pthread_initial->pll = NULL;
+ pthread_initial->sll = NULL;
++
++ /* PTHREADS spec says we start with cancellability on and deferred */
++ SET_PF_CANCEL_STATE(pthread_initial, PTHREAD_CANCEL_ENABLE);
++ SET_PF_CANCEL_TYPE(pthread_initial, PTHREAD_CANCEL_DEFERRED);
++
+
+ /* Ugly errno hack */
+ pthread_initial->error_p = &errno;
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/pthread_join.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 pthread_join.c
+*** pthread_join.c 1995/12/13 05:53:07 1.1.1.1
+--- pthread_join.c 1996/10/02 16:54:36
+***************
+*** 42,47 ****
+--- 42,49 ----
+ #include <pthread.h>
+ #include <errno.h>
+
++ static int testDeadlock( struct pthread_queue *queue, pthread_t target );
++
+ /* ==========================================================================
+ * pthread_join()
+ */
+***************
+*** 51,56 ****
+--- 53,64 ----
+
+ pthread_sched_prevent();
+
++ /* Ensure they gave us a legal pthread pointer */
++ if( ! __pthread_is_valid( pthread ) ) {
++ pthread_sched_resume();
++ return(EINVAL);
++ }
++
+ /* Check that thread isn't detached already */
+ if (pthread->attr.flags & PTHREAD_DETACHED) {
+ pthread_sched_resume();
+***************
+*** 62,81 ****
+ * Note: This must happen after checking detached state.
+ */
+ if (pthread_queue_remove(&pthread_dead_queue, pthread) != OK) {
+! pthread_queue_enq(&(pthread->join_queue), pthread_run);
+! pthread_resched_resume(PS_JOIN);
+! pthread_sched_prevent();
+!
+! if (pthread_queue_remove(&pthread_dead_queue, pthread) == OK) {
+! pthread_queue_enq(&pthread_alloc_queue, pthread);
+! pthread->attr.flags |= PTHREAD_DETACHED;
+! pthread->state = PS_UNALLOCED;
+! if (thread_return) {
+! *thread_return = pthread->ret;
+! }
+! ret = OK;
+ } else {
+! ret = ESRCH;
+ }
+ } else {
+ /* Just get the return value and detach the thread */
+--- 70,98 ----
+ * Note: This must happen after checking detached state.
+ */
+ if (pthread_queue_remove(&pthread_dead_queue, pthread) != OK) {
+!
+! /* Before we pend on the join, ensure there is no dead lock */
+!
+! if( testDeadlock( &pthread_run->join_queue, pthread ) == NOTOK ) {
+! ret = EDEADLK;
+ } else {
+! pthread_queue_enq(&(pthread->join_queue), pthread_run);
+! SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+! pthread_resched_resume(PS_JOIN);
+! CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
+! pthread_sched_prevent();
+!
+! if (pthread_queue_remove(&pthread_dead_queue, pthread) == OK) {
+! pthread_queue_enq(&pthread_alloc_queue, pthread);
+! pthread->attr.flags |= PTHREAD_DETACHED;
+! pthread->state = PS_UNALLOCED;
+! if (thread_return) {
+! *thread_return = pthread->ret;
+! }
+! ret = OK;
+! } else {
+! ret = ESRCH;
+! }
+ }
+ } else {
+ /* Just get the return value and detach the thread */
+***************
+*** 89,92 ****
+--- 106,139 ----
+ }
+ pthread_sched_resume();
+ return(ret);
++ }
++
++ /*----------------------------------------------------------------------
++ * Function: testDeadlock
++ * Purpose: recursive queue walk to check for deadlocks
++ * Args:
++ * queue = the queue to walk
++ * pthread = target to scan for
++ * Returns:
++ * OK = no deadlock, NOTOK = deadlock
++ * Notes:
++ *----------------------------------------------------------------------*/
++ static int
++ testDeadlock( struct pthread_queue *queue, pthread_t target )
++ {
++ pthread_t t;
++
++ if( queue == NULL )
++ return OK; /* Empty queue, obviously ok */
++
++ for( t = queue->q_next; t; t = t->next ) {
++ if( t == target )
++ return NOTOK; /* bang, your dead */
++
++ if( testDeadlock( &t->join_queue, target ) == NOTOK ) {
++ return NOTOK;
++ }
++ }
++
++ return OK; /* No deadlock */
+ }
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/select.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 select.c
+*** select.c 1996/03/05 08:29:14 1.1.1.1
+--- select.c 1996/10/02 16:56:27
+***************
+*** 56,220 ****
+ int select(int numfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
+ {
+! fd_set real_exceptfds, real_readfds, real_writefds; /* mapped fd_sets */
+! fd_set * real_readfds_p, * real_writefds_p, * real_exceptfds_p;
+! fd_set read_locks, write_locks, rdwr_locks;
+! struct timespec timeout_time, current_time;
+! struct timeval zero_timeout = { 0, 0 };
+! int i, j, ret = 0, got_all_locks = 1;
+! struct pthread_select_data data;
+!
+! if (numfds > dtablesize) {
+! numfds = dtablesize;
+! }
+!
+! data.nfds = 0;
+! FD_ZERO(&data.readfds);
+! FD_ZERO(&data.writefds);
+! FD_ZERO(&data.exceptfds);
+
+! /* Do this first */
+! if (timeout) {
+ machdep_gettimeofday(&current_time);
+! timeout_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
+! if ((timeout_time.tv_nsec = current_time.tv_nsec +
+! (timeout->tv_usec * 1000)) > 1000000000) {
+! timeout_time.tv_nsec -= 1000000000;
+! timeout_time.tv_sec++;
+! }
+! }
+!
+! FD_ZERO(&read_locks);
+! FD_ZERO(&write_locks);
+! FD_ZERO(&rdwr_locks);
+! FD_ZERO(&real_readfds);
+! FD_ZERO(&real_writefds);
+! FD_ZERO(&real_exceptfds);
+!
+! /* lock readfds */
+! if (readfds || writefds || exceptfds) {
+! for (i = 0; i < numfds; i++) {
+! if ((readfds && (FD_ISSET(i, readfds))) ||
+! (exceptfds && FD_ISSET(i, exceptfds))) {
+! if (writefds && FD_ISSET(i ,writefds)) {
+! if ((ret = fd_lock(i, FD_RDWR, NULL)) != OK) {
+! got_all_locks = 0;
+! break;
+! }
+! FD_SET(i, &rdwr_locks);
+! FD_SET(fd_table[i]->fd.i,&real_writefds);
+! } else {
+! if ((ret = fd_lock(i, FD_READ, NULL)) != OK) {
+! got_all_locks = 0;
+! break;
+! }
+! FD_SET(i, &read_locks);
+! }
+! if (readfds && FD_ISSET(i,readfds)) {
+! FD_SET(fd_table[i]->fd.i, &real_readfds);
+! }
+! if (exceptfds && FD_ISSET(i,exceptfds)) {
+! FD_SET(fd_table[i]->fd.i, &real_exceptfds);
+! }
+! if (fd_table[i]->fd.i >= data.nfds) {
+! data.nfds = fd_table[i]->fd.i + 1;
+! }
+! } else {
+! if (writefds && FD_ISSET(i, writefds)) {
+! if ((ret = fd_lock(i, FD_WRITE, NULL)) != OK) {
+! got_all_locks = 0;
+! break;
+! }
+! FD_SET(i, &write_locks);
+! FD_SET(fd_table[i]->fd.i,&real_writefds);
+! }
+! if (fd_table[i]->fd.i >= data.nfds) {
+! data.nfds = fd_table[i]->fd.i + 1;
+! }
+! }
+! }
+! }
+!
+! if (got_all_locks) {
+!
+! memcpy(&data.readfds,&real_readfds,sizeof(fd_set));
+! memcpy(&data.writefds,&real_writefds,sizeof(fd_set));
+! memcpy(&data.exceptfds,&real_exceptfds,sizeof(fd_set));
+!
+! real_readfds_p = (readfds == NULL) ? NULL : &real_readfds;
+! real_writefds_p = (writefds == NULL) ? NULL : &real_writefds;
+! real_exceptfds_p = (exceptfds == NULL) ? NULL : &real_exceptfds;
+!
+! if ((ret = machdep_sys_select(data.nfds, real_readfds_p,
+! real_writefds_p, real_exceptfds_p, &zero_timeout)) == OK) {
+!
+! pthread_sched_prevent();
+!
+! real_exceptfds_p = (exceptfds == NULL) ? NULL : &data.exceptfds;
+! real_writefds_p = (writefds == NULL) ? NULL : &data.writefds;
+! real_readfds_p = (readfds == NULL) ? NULL : &data.readfds;
+!
+! pthread_queue_enq(&fd_wait_select, pthread_run);
+! pthread_run->data.select_data = &data;
+! SET_PF_WAIT_EVENT(pthread_run);
+!
+! if (timeout) {
+! machdep_gettimeofday(&current_time);
+! sleep_schedule(&current_time, &timeout_time);
+!
+! pthread_resched_resume(PS_SELECT_WAIT);
+!
+! /* We're awake */
+! CLEAR_PF_DONE_EVENT(pthread_run);
+! if (sleep_cancel(pthread_run) == NOTOK) {
+! ret = OK;
+! } else {
+! ret = data.nfds;
+! }
+! } else {
+! pthread_resched_resume(PS_SELECT_WAIT);
+! CLEAR_PF_DONE_EVENT(pthread_run);
+! ret = data.nfds; /* XXX ??? snl */
+! }
+! } else if (ret < 0) {
+! SET_ERRNO(-ret);
+! ret = NOTOK;
+! }
+! }
+!
+! /* clean up the locks */
+! for (i = 0; i < numfds; i++)
+! if (FD_ISSET(i,&read_locks)) fd_unlock(i,FD_READ);
+! for (i = 0; i < numfds; i++)
+! if (FD_ISSET(i,&rdwr_locks)) fd_unlock(i,FD_RDWR);
+! for (i = 0; i < numfds; i++)
+! if (FD_ISSET(i,&write_locks)) fd_unlock(i,FD_WRITE);
+!
+! if (ret > 0) {
+! if (readfds != NULL) {
+! for (i = 0; i < numfds; i++) {
+! if (! (FD_ISSET(i,readfds) &&
+! FD_ISSET(fd_table[i]->fd.i,real_readfds_p)))
+! FD_CLR(i,readfds);
+! }
+! }
+! if (writefds != NULL) {
+! for (i = 0; i < numfds; i++)
+! if (! (FD_ISSET(i,writefds) &&
+! FD_ISSET(fd_table[i]->fd.i,real_writefds_p)))
+! FD_CLR(i,writefds);
+! }
+! if (exceptfds != NULL) {
+! for (i = 0; i < numfds; i++)
+! if (! (FD_ISSET(i,exceptfds) &&
+! FD_ISSET(fd_table[i]->fd.i,real_exceptfds_p)))
+! FD_CLR(i,exceptfds);
+! }
+! } else {
+! if (exceptfds != NULL) FD_ZERO(exceptfds);
+! if (writefds != NULL) FD_ZERO(writefds);
+! if (readfds != NULL) FD_ZERO(readfds);
+ }
+
+! return(ret);
+ }
+--- 56,223 ----
+ int select(int numfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
+ {
+! fd_set real_exceptfds, real_readfds, real_writefds; /* mapped fd_sets */
+! fd_set * real_readfds_p, * real_writefds_p, * real_exceptfds_p;
+! fd_set read_locks, write_locks, rdwr_locks;
+! struct timespec timeout_time, current_time;
+! struct timeval zero_timeout = { 0, 0 };
+! int i, j, ret = 0, got_all_locks = 1;
+! struct pthread_select_data data;
+!
+! if (numfds > dtablesize) {
+! numfds = dtablesize;
+! }
+!
+! data.nfds = 0;
+! FD_ZERO(&data.readfds);
+! FD_ZERO(&data.writefds);
+! FD_ZERO(&data.exceptfds);
+!
+! /* Do this first */
+! if (timeout) {
+! machdep_gettimeofday(&current_time);
+! timeout_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
+! if ((timeout_time.tv_nsec = current_time.tv_nsec +
+! (timeout->tv_usec * 1000)) > 1000000000) {
+! timeout_time.tv_nsec -= 1000000000;
+! timeout_time.tv_sec++;
+! }
+! }
+!
+! FD_ZERO(&read_locks);
+! FD_ZERO(&write_locks);
+! FD_ZERO(&rdwr_locks);
+! FD_ZERO(&real_readfds);
+! FD_ZERO(&real_writefds);
+! FD_ZERO(&real_exceptfds);
+!
+! /* lock readfds */
+! if (readfds || writefds || exceptfds) {
+! for (i = 0; i < numfds; i++) {
+! if ((readfds && (FD_ISSET(i, readfds))) ||
+! (exceptfds && FD_ISSET(i, exceptfds))) {
+! if (writefds && FD_ISSET(i ,writefds)) {
+! if ((ret = fd_lock(i, FD_RDWR, NULL)) != OK) {
+! got_all_locks = 0;
+! break;
+! }
+! FD_SET(i, &rdwr_locks);
+! FD_SET(fd_table[i]->fd.i,&real_writefds);
+! } else {
+! if ((ret = fd_lock(i, FD_READ, NULL)) != OK) {
+! got_all_locks = 0;
+! break;
+! }
+! FD_SET(i, &read_locks);
+! }
+! if (readfds && FD_ISSET(i,readfds)) {
+! FD_SET(fd_table[i]->fd.i, &real_readfds);
+! }
+! if (exceptfds && FD_ISSET(i,exceptfds)) {
+! FD_SET(fd_table[i]->fd.i, &real_exceptfds);
+! }
+! if (fd_table[i]->fd.i >= data.nfds) {
+! data.nfds = fd_table[i]->fd.i + 1;
+! }
+! } else {
+! if (writefds && FD_ISSET(i, writefds)) {
+! if ((ret = fd_lock(i, FD_WRITE, NULL)) != OK) {
+! got_all_locks = 0;
+! break;
+! }
+! FD_SET(i, &write_locks);
+! FD_SET(fd_table[i]->fd.i,&real_writefds);
+! if (fd_table[i]->fd.i >= data.nfds) {
+! data.nfds = fd_table[i]->fd.i + 1;
+! }
+! }
+! }
+! }
+! }
+!
+! if (got_all_locks) {
+! memcpy(&data.readfds,&real_readfds,sizeof(fd_set));
+! memcpy(&data.writefds,&real_writefds,sizeof(fd_set));
+! memcpy(&data.exceptfds,&real_exceptfds,sizeof(fd_set));
+!
+! real_readfds_p = (readfds == NULL) ? NULL : &real_readfds;
+! real_writefds_p = (writefds == NULL) ? NULL : &real_writefds;
+! real_exceptfds_p = (exceptfds == NULL) ? NULL : &real_exceptfds;
+!
+! if ((ret = machdep_sys_select(data.nfds, real_readfds_p,
+! real_writefds_p, real_exceptfds_p,
+! &zero_timeout)) == OK) {
+! pthread_sched_prevent();
+!
+! real_exceptfds_p = (exceptfds == NULL) ? NULL : &data.exceptfds;
+! real_writefds_p = (writefds == NULL) ? NULL : &data.writefds;
+! real_readfds_p = (readfds == NULL) ? NULL : &data.readfds;
+!
+! pthread_queue_enq(&fd_wait_select, pthread_run);
+! pthread_run->data.select_data = &data;
+! SET_PF_WAIT_EVENT(pthread_run);
+
+! if (timeout) {
+ machdep_gettimeofday(&current_time);
+! sleep_schedule(&current_time, &timeout_time);
+!
+! SET_PF_AT_CANCEL_POINT(pthread_run);
+! pthread_resched_resume(PS_SELECT_WAIT);
+! CLEAR_PF_AT_CANCEL_POINT(pthread_run);
+!
+! /* We're awake */
+! CLEAR_PF_DONE_EVENT(pthread_run);
+! if (sleep_cancel(pthread_run) == NOTOK) {
+! ret = OK;
+! } else {
+! ret = data.nfds;
+! }
+! } else {
+! SET_PF_AT_CANCEL_POINT(pthread_run);
+! pthread_resched_resume(PS_SELECT_WAIT);
+! CLEAR_PF_AT_CANCEL_POINT(pthread_run);
+! CLEAR_PF_DONE_EVENT(pthread_run);
+! ret = data.nfds; /* XXX ??? snl */
+! }
+! } else if (ret < 0) {
+! SET_ERRNO(-ret);
+! ret = NOTOK;
+! }
+! }
+!
+! /* clean up the locks */
+! for (i = 0; i < numfds; i++)
+! if (FD_ISSET(i,&read_locks)) fd_unlock(i,FD_READ);
+! for (i = 0; i < numfds; i++)
+! if (FD_ISSET(i,&rdwr_locks)) fd_unlock(i,FD_RDWR);
+! for (i = 0; i < numfds; i++)
+! if (FD_ISSET(i,&write_locks)) fd_unlock(i,FD_WRITE);
+!
+! if (ret > 0) {
+! if (readfds != NULL) {
+! for (i = 0; i < numfds; i++) {
+! if (! (FD_ISSET(i,readfds) &&
+! FD_ISSET(fd_table[i]->fd.i,real_readfds_p)))
+! FD_CLR(i,readfds);
+! }
+! }
+! if (writefds != NULL) {
+! for (i = 0; i < numfds; i++)
+! if (! (FD_ISSET(i,writefds) &&
+! FD_ISSET(fd_table[i]->fd.i,real_writefds_p)))
+! FD_CLR(i,writefds);
+! }
+! if (exceptfds != NULL) {
+! for (i = 0; i < numfds; i++)
+! if (! (FD_ISSET(i,exceptfds) &&
+! FD_ISSET(fd_table[i]->fd.i,real_exceptfds_p)))
+! FD_CLR(i,exceptfds);
+ }
++ } else {
++ if (exceptfds != NULL) FD_ZERO(exceptfds);
++ if (writefds != NULL) FD_ZERO(writefds);
++ if (readfds != NULL) FD_ZERO(readfds);
++ }
+
+! return(ret);
+ }
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/sig.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 sig.c
+*** sig.c 1996/03/13 04:33:13 1.1.1.1
+--- sig.c 1996/10/03 01:07:54
+***************
+*** 301,307 ****
+--- 301,310 ----
+ pthread_run->data.sigwait = set;
+ pthread_run->ret = sig;
+
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ pthread_resched_resume(PS_SIGWAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
++
+ return(OK);
+ }
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/signal.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 signal.c
+*** signal.c 1996/03/13 04:33:17 1.1.1.1
+--- signal.c 1996/10/03 17:30:16
+***************
+*** 72,77 ****
+--- 72,78 ----
+
+ static void sig_handler(int signal);
+ static void set_thread_timer();
++ static void __cleanup_after_resume( void );
+ void sig_prevent(void);
+ void sig_resume(void);
+
+***************
+*** 482,502 ****
+ }
+ }
+
+! /* Only bother if we are truly unlocking the kernel */
+! while (!(--pthread_kernel_lock)) {
+! if (sig_to_process) {
+! /* if (SIG_ANY(sig_to_process)) { */
+! pthread_kernel_lock++;
+! sig_handler(0);
+! continue;
+! }
+! if (pthread_run && pthread_run->sigcount) {
+! pthread_kernel_lock++;
+! pthread_sig_process();
+! continue;
+! }
+! break;
+! }
+ }
+
+ /* ==========================================================================
+--- 483,489 ----
+ }
+ }
+
+! __cleanup_after_resume();
+ }
+
+ /* ==========================================================================
+***************
+*** 508,530 ****
+ void pthread_resched_resume(enum pthread_state state)
+ {
+ pthread_run->state = state;
+- sig_handler(SIGVTALRM);
+
+! /* Only bother if we are truely unlocking the kernel */
+! while (!(--pthread_kernel_lock)) {
+! if (sig_to_process) {
+! /* if (SIG_ANY(sig_to_process)) { */
+! pthread_kernel_lock++;
+! sig_handler(0);
+! continue;
+! }
+! if (pthread_run && pthread_run->sigcount) {
+! pthread_kernel_lock++;
+! pthread_sig_process();
+! continue;
+! }
+! break;
+ }
+ }
+
+ /* ==========================================================================
+--- 495,523 ----
+ void pthread_resched_resume(enum pthread_state state)
+ {
+ pthread_run->state = state;
+
+! /* Since we are about to block this thread, lets see if we are
+! * at a cancel point and if we've been cancelled.
+! * Avoid cancelling dead or unalloced threads.
+! */
+! if( ! TEST_PF_RUNNING_TO_CANCEL(pthread_run) &&
+! TEST_PTHREAD_IS_CANCELLABLE(pthread_run) &&
+! state != PS_DEAD && state != PS_UNALLOCED ) {
+!
+! /* Set this flag to avoid recursively calling pthread_exit */
+! /* We have to set this flag here because we will unlock the
+! * kernel prior to calling pthread_cancel_internal.
+! */
+! SET_PF_RUNNING_TO_CANCEL(pthread_run);
+!
+! pthread_run->old_state = state; /* unlock needs this data */
+! pthread_sched_resume(); /* Unlock kernel before cancel */
+! pthread_cancel_internal( 1 ); /* free locks and exit */
+ }
++
++ sig_handler(SIGVTALRM);
++
++ __cleanup_after_resume();
+ }
+
+ /* ==========================================================================
+***************
+*** 532,537 ****
+--- 525,543 ----
+ */
+ void pthread_sched_resume()
+ {
++ __cleanup_after_resume();
++ }
++
++ /*----------------------------------------------------------------------
++ * Function: __cleanup_after_resume
++ * Purpose: cleanup kernel locks after a resume
++ * Args: void
++ * Returns: void
++ * Notes:
++ *----------------------------------------------------------------------*/
++ static void
++ __cleanup_after_resume( void )
++ {
+ /* Only bother if we are truely unlocking the kernel */
+ while (!(--pthread_kernel_lock)) {
+ /* if (SIG_ANY(sig_to_process)) { */
+***************
+*** 546,551 ****
+--- 552,568 ----
+ continue;
+ }
+ break;
++ }
++
++ if( pthread_run == NULL )
++ return; /* Must be during init processing */
++
++ /* Test for cancel that should be handled now */
++
++ if( ! TEST_PF_RUNNING_TO_CANCEL(pthread_run) &&
++ TEST_PTHREAD_IS_CANCELLABLE(pthread_run) ) {
++ /* Kernel is already unlocked */
++ pthread_cancel_internal( 1 ); /* free locks and exit */
+ }
+ }
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/sleep.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 sleep.c
+*** sleep.c 1996/03/11 08:33:32 1.1.1.1
+--- sleep.c 1996/10/03 01:14:58
+***************
+*** 249,255 ****
+--- 249,257 ----
+
+ /* Reschedule thread */
+ SET_PF_WAIT_EVENT(pthread_run);
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ pthread_resched_resume(PS_SLEEP_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
+ CLEAR_PF_DONE_EVENT(pthread_run);
+
+ /* Return actual time slept */
+***************
+*** 332,338 ****
+ current_time.tv_sec++;
+ }
+ machdep_start_timer(&(current_time),
+! &(pthread_sleep->wakeup_time));
+ }
+ } else {
+ for (pthread_last = pthread_sleep; pthread_last;
+--- 334,340 ----
+ current_time.tv_sec++;
+ }
+ machdep_start_timer(&(current_time),
+! &(pthread_sleep->wakeup_time));
+ }
+ } else {
+ for (pthread_last = pthread_sleep; pthread_last;
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/stat.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 stat.c
+*** stat.c 1995/09/21 02:36:05 1.1.1.1
+--- stat.c 1996/06/04 19:17:33
+***************
+*** 43,48 ****
+--- 43,49 ----
+ #include <errno.h>
+
+ struct stat;
++ struct statfs;
+
+ /* ==========================================================================
+ * fstat()
+***************
+*** 91,95 ****
+--- 92,115 ----
+ }
+ return(ret);
+
++ }
++
++ /* ==========================================================================
++ * fstatfs()
++ *
++ * Might want to indirect this.
++ */
++ int fstatfs(int fd, struct statfs *buf)
++ {
++ int ret;
++
++ if ((ret = fd_lock(fd, FD_READ, NULL)) == OK) {
++ if ((ret = machdep_sys_fstatfs(fd_table[fd]->fd.i, buf)) < OK) {
++ SET_ERRNO(-ret);
++ ret = NOTOK;
++ }
++ fd_unlock(fd, FD_READ);
++ }
++ return(ret);
+ }
+
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/wait.c,v retrieving revision 1.1.1.1
+diff -c -r1.1.1.1 wait.c
+*** wait.c 1995/02/21 08:07:24 1.1.1.1
+--- wait.c 1996/10/03 01:20:02
+***************
+*** 103,109 ****
+--- 103,111 ----
+ pthread_queue_enq(&wait_queue, pthread_run);
+
+ /* reschedule unlocks scheduler */
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ pthread_resched_resume(PS_WAIT_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
+
+ pthread_sched_prevent();
+ }
+***************
+*** 126,132 ****
+--- 128,136 ----
+ pthread_queue_enq(&wait_queue, pthread_run);
+
+ /* reschedule unlocks scheduler */
++ SET_PF_AT_CANCEL_POINT(pthread_run); /* This is a cancel point */
+ pthread_resched_resume(PS_WAIT_WAIT);
++ CLEAR_PF_AT_CANCEL_POINT(pthread_run); /* No longer at cancel point */
+
+ pthread_sched_prevent();
+ }
+<pre><font size=-1>
diff --git a/mit-pthreads/patches/Streepy2.html b/mit-pthreads/patches/Streepy2.html
new file mode 100755
index 00000000000..80d44d6440c
--- /dev/null
+++ b/mit-pthreads/patches/Streepy2.html
@@ -0,0 +1,93 @@
+<html>
+<head>
+ <title>Diffs on diffs :-) by Larry V. Streepy, Jr.</title>
+ <base target=_top>
+ <meta name="GENERATOR" content="FindMail Communications">
+ <meta name="Date" content="Monday, October 07, 1996 02:03 PM PST">
+ <meta name="Author" content="Larry V. Streepy, Jr.">
+</head>
+<body background="/gifs/betafm.gif" bgcolor="#ffffff" text="#000000" link="#0000ee" vlink="#ff0000" alink="#000099">
+<h3>Diffs on diffs :-)</h3>
+Larry V. Streepy, Jr. (<a href="mailto.html?mid=2079859748&num=398" target="_top">@healthcare.com</a>)<br>Monday, October 07, 1996 02:03 PM PST<br>
+<p>
+This is a multi-part message in MIME format.<p>
+--------------65BE18E23639BCDD7BE55F7F <br>
+Content-Type: text/plain; charset=us-ascii <br>
+Content-Transfer-Encoding: 7bit<p>
+Unfortunately, there are a couple of bugs in my pthread_cancel support (no, say it isn't so :-)<p>
+Oh well, I cam across a couple of cases that I missed in my testing last week. Here are the bugs:<p>
+1. If a thread calls pthread_testcancel during it's cleanup processing after being cancelled, the pthread kernel would hang.<p>
+2. I didn't realize that threads in PS_SLEEP_WAIT state are *NOT* on any queue, they are handled using a linked list. So, when cancelling a thread that was sleeping, a PANIC() I put in possiblymakeRunnable would go off.<p>
+Both of these are fixed. The diffs are attached.<br>
+-- <br>
+Larry V. Streepy, Jr. <br>
+Chief Technical Officer, Healthcare Communications, Inc. mailto:<a href="mailto.html?mid=2079859748&num=398" target="_top">@healthcare.com</a> <br>
+(214) 851-7033 (Dallas Main #) <br>
+(970) 626-5028 (My office #) (970) 626-4425 (Fax)<p>
+--------------65BE18E23639BCDD7BE55F7F <br>
+Content-Type: text/plain; charset=us-ascii; name=&#34;cancel.diffs&#34; Content-Transfer-Encoding: 7bit <br>
+Content-Disposition: inline; filename=&#34;cancel.diffs&#34;<p>
+Index: pthread_cancel.c<br>
+=================================================================== RCS file: /usr/cvssrc/pthreads-1_60_beta5/pthreads/pthread_cancel.c,v retrieving revision 1.1 <br>
+diff -c -r1.1 pthread_cancel.c<br>
+*** pthread_cancel.c 1996/10/06 00:31:27 1.1<br>
+--- pthread_cancel.c 1996/10/07 18:33:27<br>
+***************<br>
+*** 187,192 ****<br>
+--- 187,197 ----<br>
+ return; /* Can't be cancelled */<br>
+ }<br>
+ <br>
++ /* Ensure that we aren't in the process of exiting already */<br>
++ if( TEST_PF_RUNNING_TO_CANCEL(pthread_run) ) {<br>
++ return;<br>
++ }<br>
++ <br>
+ /* See if we have been cancelled */<br>
+ if( TEST_PF_CANCELLED(pthread_run) ) {<br>
+ /* Set this flag to avoid recursively calling pthread_exit */<br>
+***************<br>
+*** 266,277 ****<br>
+ if( pthread-&gt;state == PS_RUNNING )<br>
+ return; /* will happen at context switch */<br>
+ <br>
+! /* Otherwise, we need to take it off the queue and make it runnable */<br>
+! if( pthread-&gt;queue == NULL ) {<br>
+! PANIC(); /* Must be on a queue */<br>
+! }<br>
+ <br>
+- pthread_queue_remove(pthread-&gt;queue, pthread);<br>
+ pthread_prio_queue_enq(pthread_current_prio_queue, pthread);<br>
+ pthread-&gt;old_state = pthread-&gt;state;<br>
+ pthread-&gt;state = PS_RUNNING;<br>
+--- 271,291 ----<br>
+ if( pthread-&gt;state == PS_RUNNING )<br>
+ return; /* will happen at context switch */<br>
+ <br>
+! /* If the thread is sleeping, the it isn't on a queue. */<br>
+! if( pthread-&gt;state == PS_SLEEP_WAIT ) {<br>
+! sleep_cancel( pthread ); /* Remove from sleep list */<br>
+! } else {<br>
+! /* Otherwise, we need to take it off the queue and make it runnable */<br>
+! <br>
+! if( pthread-&gt;queue == NULL ) {<br>
+! PANIC(); /* Must be on a queue */<br>
+! }<br>
+! <br>
+! pthread_queue_remove(pthread-&gt;queue, pthread);<br>
+! }<br>
+! <br>
+! /* And make it runnable */<br>
+ <br>
+ pthread_prio_queue_enq(pthread_current_prio_queue, pthread);<br>
+ pthread-&gt;old_state = pthread-&gt;state;<br>
+ pthread-&gt;state = PS_RUNNING;<p>
+<pre><font size=-1>
+--------------65BE18E23639BCDD7BE55F7F--
+
+</pre><p></pre>
+<hr>
+<a href="http://www.findmail.com/" target="_top"><font size=-1>Powered by FindMail Communications</font><br></a>
+<br>Please email comments and suggestions to:<a href="/cgi-bin/comments.py" target="_top">comments@findmail.com</a>
+<br><font size=-3 color="#ffffff">xmlarchive</font>
+</body></html> \ No newline at end of file
diff --git a/mit-pthreads/patches/bill_lear b/mit-pthreads/patches/bill_lear
new file mode 100755
index 00000000000..f49b79c4272
--- /dev/null
+++ b/mit-pthreads/patches/bill_lear
@@ -0,0 +1,70 @@
+From rael@dejanews.com Wed Jan 29 06:06:14 1997
+X-VM-v5-Data: ([nil nil nil t nil nil nil nil nil]
+ ["1497" "Tue" "28" "January" "1997" "21:52:57" "-0600" "William S. Lear" "rael@dejanews.com" "<199701290352.VAA08678@homer.dejanews.com>" "53" "Patches for linux2.0" "^From:" nil nil "1" "1997012903:52:57" "Patches for linux2.0" nil nil]
+ nil)
+Received: from MIT.EDU (PACIFIC-CARRIER-ANNEX.MIT.EDU [18.69.0.28])
+ by analytik.analytikerna.se (8.8.4/8.8.4) with SMTP
+ id GAA23245 for <monty@analytikerna.se>; Wed, 29 Jan 1997 06:06:12 +0100 (MET)
+Received: from host-205-238-143-2.dejanews.com by MIT.EDU with SMTP
+ id AA25254; Tue, 28 Jan 97 22:53:08 EST
+Received: (from rael@localhost) by homer.dejanews.com (8.7.6/8.6.12) id VAA08678 for pthreads@mit.edu; Tue, 28 Jan 1997 21:52:57 -0600 (CST)
+Message-Id: <199701290352.VAA08678@homer.dejanews.com>
+Content-Length: 1496
+From: "William S. Lear" <rael@dejanews.com>
+To: pthreads@MIT.EDU
+Subject: Patches for linux2.0
+Date: Tue, 28 Jan 1997 21:52:57 -0600 (CST)
+
+
+The following are some patches I found necessary to run smoothly
+under linux2.0. The PTEST directory below refers to the original
+pthreads 1.60 beta 6 release. Of course, the '-O2' "fix" is not strictly
+needed.
+
+#============================================================
+# < pthreads-1_60beta6/config/configure
+# > PTEST/pthreads-1_60beta6/config/configure
+#------------------------------------------------------------
+642c642
+< CFLAGS="-g -O2"
+---
+> CFLAGS="-g -O"
+1104,1106d1103
+< cat >> confdefs.h <<EOF
+< #define BSD_TM 1
+< EOF
+
+# Diff for:
+#============================================================
+# < pthreads-1_60beta6/config/config.h.in
+# > PTEST/pthreads-1_60beta6/config/config.h.in
+#------------------------------------------------------------
+3,8d2
+< /* Does the OS have tm needing bsd'ish initialization? */
+< #undef BSD_TM
+<
+< /* Does the OS already support struct timespec */
+< #undef _OS_HAS_TIMESPEC
+<
+
+# Diff for:
+#============================================================
+# < pthreads-1_60beta6/gen/ctime.c
+# > PTEST/pthreads-1_60beta6/gen/ctime.c
+#------------------------------------------------------------
+49c49
+< #include "config.h"
+---
+>
+
+# Diff for:
+#============================================================
+# < pthreads-1_60beta6/include/math.h
+# > PTEST/pthreads-1_60beta6/include/math.h
+#------------------------------------------------------------
+54d53
+< double hypot __P((double, double));
+
+
+Bill Lear (rael@dejanews.com)
+
diff --git a/mit-pthreads/patches/chris_demetriou b/mit-pthreads/patches/chris_demetriou
new file mode 100755
index 00000000000..283d6c1999c
--- /dev/null
+++ b/mit-pthreads/patches/chris_demetriou
@@ -0,0 +1,149 @@
+From cgd@pa.dec.com Fri Aug 15 04:22:21 1997
+X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
+ ["3982" "Thu" "14" "August" "1997" "18:57:55" "-0700" "Chris G. Demetriou" "cgd@pa.dec.com" "<15218.871610275@dnaunix.pa.dec.com>" "126" "patches to get 1.60 beta6 to build on ELF NetBSD/alpha systems" "^From:" nil nil "8" "1997081501:57:55" "patches to get 1.60 beta6 to build on ELF NetBSD/alpha systems" nil nil]
+ nil)
+Received: from MIT.EDU (PACIFIC-CARRIER-ANNEX.MIT.EDU [18.69.0.28])
+ by analytik.analytikerna.se (8.8.4/8.8.4) with SMTP
+ id EAA10207 for <monty@analytikerna.se>; Fri, 15 Aug 1997 04:22:19 +0200 (MET DST)
+Received: from mail2.digital.com by MIT.EDU with SMTP
+ id AA13470; Thu, 14 Aug 97 22:01:37 EDT
+Received: from dnaunix.pa.dec.com (dnaunix.pa.dec.com [16.4.208.21])
+ by mail2.digital.com (8.7.5/UNX 1.5/1.0/WV) with SMTP id SAA15366;
+ Thu, 14 Aug 1997 18:58:16 -0700 (PDT)
+Received: by dnaunix.pa.dec.com; id AA15044; Thu, 14 Aug 1997 18:57:56 -0700
+Message-Id: <15218.871610275@dnaunix.pa.dec.com>
+X-Mts: smtp
+Content-Length: 3981
+From: "Chris G. Demetriou" <cgd@pa.dec.com>
+Sender: cgd@pa.dec.com
+To: pthreads-bugs@MIT.EDU
+Cc: "Chris G. Demetriou" <cgd@pa.dec.com>, pthreads@MIT.EDU
+Subject: patches to get 1.60 beta6 to build on ELF NetBSD/alpha systems
+Date: Thu, 14 Aug 97 18:57:55 -0700
+
+Enclosed below are patches to pthreads 1.60 beta6 to build on
+current NetBSD/alpha systems (which use ELF). With these patches,
+pthreads passes 'make check.'
+
+As an aside, the test_switch test generates _340k_ of output ("a"
+for a while, then "ab" for a while) when run one the machine I was
+testing on. In my opinion, that's a ... bit excessive, especially
+since 'make check' has to be run interactively!
+
+
+
+chris
+============================================================================
+diff -rc pthreads-1_60_beta6.orig/config/Makefile.in pthreads-1_60_beta6/config/Makefile.in
+*** pthreads-1_60_beta6.orig/config/Makefile.in Thu Mar 21 20:29:54 1996
+--- pthreads-1_60_beta6/config/Makefile.in Thu Aug 14 17:56:55 1997
+***************
+*** 29,35 ****
+ # pathname for srcdir here, and live with it.
+ srcdir = $(srctop)
+
+! beforeinstall:: install-dirs
+
+ .include "${srcdir}/pthreads/Makefile.inc"
+ .include "${srcdir}/stdlib/Makefile.inc"
+--- 29,35 ----
+ # pathname for srcdir here, and live with it.
+ srcdir = $(srctop)
+
+! beforeinstall: install-dirs
+
+ .include "${srcdir}/pthreads/Makefile.inc"
+ .include "${srcdir}/stdlib/Makefile.inc"
+diff -rc pthreads-1_60_beta6.orig/machdep/syscall-alpha-netbsd-1.1.S pthreads-1_60_beta6/machdep/syscall-alpha-netbsd-1.1.S
+*** pthreads-1_60_beta6.orig/machdep/syscall-alpha-netbsd-1.1.S Wed Nov 13 13:03:28 1996
+--- pthreads-1_60_beta6/machdep/syscall-alpha-netbsd-1.1.S Thu Aug 14 18:03:27 1997
+***************
+*** 35,54 ****
+ .frame sp,0,ra ;\
+ ldiq v0, CONCAT(SYS_,x) ;\
+ CHMK() ;\
+! beq a3, 2f ;\
+! br gp, 1f ;\
+! 1: ;\
+ /* Load gp so we can find cerror to jump to. */;\
+ ldgp gp, 0(gp) ;\
+! jmp zero, machdep_cerror ;\
+! 2:
+
+ #define XSYSCALL(x) SYSCALL(x) ; RET ; .end CONCAT(machdep_sys_,x)
+
+ .globl machdep_cerror
+ machdep_cerror:
+! br t0, 1f
+! 1:
+ ldgp gp, 0(t0)
+ stl v0, errno
+ #if 0
+--- 35,54 ----
+ .frame sp,0,ra ;\
+ ldiq v0, CONCAT(SYS_,x) ;\
+ CHMK() ;\
+! beq a3, CONCAT(Lsys_noerr_,x) ;\
+! br gp, CONCAT(Lsys_err_,x) ;\
+! CONCAT(Lsys_err_,x): ;\
+ /* Load gp so we can find cerror to jump to. */;\
+ ldgp gp, 0(gp) ;\
+! jmp zero, machdep_cerror ;\
+! CONCAT(Lsys_noerr_,x):
+
+ #define XSYSCALL(x) SYSCALL(x) ; RET ; .end CONCAT(machdep_sys_,x)
+
+ .globl machdep_cerror
+ machdep_cerror:
+! br t0, Lmachdep_cerror_setgp
+! Lmachdep_cerror_setgp:
+ ldgp gp, 0(t0)
+ stl v0, errno
+ #if 0
+diff -rc pthreads-1_60_beta6.orig/machdep/syscall-template-alpha-netbsd-1.1.S pthreads-1_60_beta6/machdep/syscall-template-alpha-netbsd-1.1.S
+*** pthreads-1_60_beta6.orig/machdep/syscall-template-alpha-netbsd-1.1.S Mon Apr 22 23:15:42 1996
+--- pthreads-1_60_beta6/machdep/syscall-template-alpha-netbsd-1.1.S Thu Aug 14 17:58:14 1997
+***************
+*** 31,43 ****
+ .frame sp,0,ra ;\
+ ldiq v0, SYS_##x ;\
+ CHMK() ;\
+! beq a3, 2f ;\
+! br gp, 1f ;\
+! 1: ;\
+ /* Load gp so we can find cerror to jump to. */;\
+ ldgp gp, 0(gp) ;\
+! jmp zero, machdep_cerror ;\
+! 2:
+
+ #define SIMPLE_SYSCALL(x) SYSCALL(x) ; ret ; .end machdep_sys_##x
+
+--- 31,43 ----
+ .frame sp,0,ra ;\
+ ldiq v0, SYS_##x ;\
+ CHMK() ;\
+! beq a3, Lsys_noerr_##x ;\
+! br gp, Lsys_err_##x ;\
+! Lsys_err_##x: ;\
+ /* Load gp so we can find cerror to jump to. */;\
+ ldgp gp, 0(gp) ;\
+! jmp zero, machdep_cerror ;\
+! Lsys_noerr_##x:
+
+ #define SIMPLE_SYSCALL(x) SYSCALL(x) ; ret ; .end machdep_sys_##x
+
+diff -rc pthreads-1_60_beta6.orig/pthreads/process.c pthreads-1_60_beta6/pthreads/process.c
+*** pthreads-1_60_beta6.orig/pthreads/process.c Tue Nov 12 05:45:16 1996
+--- pthreads-1_60_beta6/pthreads/process.c Thu Aug 14 18:12:49 1997
+***************
+*** 40,45 ****
+--- 40,47 ----
+ #include <stdarg.h>
+ #include <unistd.h>
+
++ extern void *alloca();
++
+ #ifndef lint
+ static const char rcsid[] = "$Id$";
+ #endif
+
diff --git a/mit-pthreads/patches/mevans b/mit-pthreads/patches/mevans
new file mode 100755
index 00000000000..d5ff2f27610
--- /dev/null
+++ b/mit-pthreads/patches/mevans
@@ -0,0 +1,642 @@
+=A0
+Attached are several patches for pthreads-1_60_beta6. The patches fall
+into 3 catagories:
+
+ 1. Crashes and hangs.
+ 2. Missing functionality (namely flock())
+ 3. Use of POSIX reentrant safe routines.
+
+Most of the patches contain a comment as to why the change was made.
+The one major exception is to fd_kern.c at line 257 (unpatched). The
+change to that line is to fix a "hang" that prevents threads for
+scheduling for an hour if there is no external I/O event.
+
+I also include patches that modify several functions to use POSIX
+reentrant safe routines. I know that MIT pthreads implements routine
+like gethostbyname in a thread safe manner, but we're pretty, um, anal
+about trying to keep our code as portable as possible. By excluding
+using routines that are not reentrant safe according to the PTHREAD
+safe, it's easy for us to stub out the unsafe routines and catch
+non-compliant code. I almost left these patches out, but I'm hoping
+they'll be adopted. :-)
+
+WARNING: None of the MIT pthreads routines that convert floats/doubles
+between their native forms and strings are thread safe! (i.e printf,
+sprintf, fprintf, atod, strtod, etc) I have replacements, but I need to
+check with the author of the replacements and my employer.
+
+Mark Evans
+
+------------69CDAAF52A3566916F8ED01A0
+Content-Disposition: inline; filename="pthreads-1_60_beta6.patch"
+Content-Type: text/plain; charset=us-ascii; name="pthreads-1_60_beta6.patch"
+Content-Transfer-Encoding: 7bit
+
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/config/config.h.in pthreads-1_60_beta6+/config/config.h.in
+*** pthreads-1_60_beta6/config/config.h.in Thu Mar 21 21:30:04 1996
+--- pthreads-1_60_beta6+/config/config.h.in Sat Mar 15 14:08:55 1997
+***************
+*** 137,142 ****
+--- 137,145 ----
+ /* Define if you have the syscall_ftruncate function. */
+ #undef HAVE_SYSCALL_FTRUNCATE
+
++ /* Define if you have the syscall_flock function. */
++ #undef HAVE_SYSCALL_FLOCK
++
+ /* Define if you have the syscall_getdents function. */
+ #undef HAVE_SYSCALL_GETDENTS
+
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/config/configure.in pthreads-1_60_beta6+/config/configure.in
+*** pthreads-1_60_beta6/config/configure.in Wed Nov 13 14:03:08 1996
+--- pthreads-1_60_beta6+/config/configure.in Sat Mar 15 14:08:55 1997
+***************
+*** 241,247 ****
+
+ PTHREADS_CHECK_SYSCALLS(open write read creat close fcntl lseek dup2 dup pipe
+ fchmod fchown execve fstat lstat link unlink chdir chown chmod stat
+! rename select getdtablesize ioctl ftruncate
+ dnl - signals
+ sigsuspend sigaction sigpause sigprocmask ksigaction
+ dnl - directory reading
+--- 241,247 ----
+
+ PTHREADS_CHECK_SYSCALLS(open write read creat close fcntl lseek dup2 dup pipe
+ fchmod fchown execve fstat lstat link unlink chdir chown chmod stat
+! rename select getdtablesize ioctl ftruncate flock
+ dnl - signals
+ sigsuspend sigaction sigpause sigprocmask ksigaction
+ dnl - directory reading
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/gen/directory.c pthreads-1_60_beta6+/gen/directory.c
+*** pthreads-1_60_beta6/gen/directory.c Sat May 20 10:55:34 1995
+--- pthreads-1_60_beta6+/gen/directory.c Sat Mar 15 14:08:55 1997
+***************
+*** 251,262 ****
+--- 251,266 ----
+ /*
+ * Seek to an entry in a directory.
+ * _seekdir is in telldir.c so that it can share opaque data structures.
++ *
++ * Use the POSIX reentrant safe readdir_r to simplify varifying POSIX
++ * thread-safe compliance.
+ */
+ void seekdir(DIR * dirp, long loc)
+ {
+ register struct ddloc ** prevlp;
+ register struct ddloc * lp;
+ struct dirent * dp;
++ struct dirent de;
+
+ pthread_mutex_lock (dirp->dd_lock);
+ prevlp = (struct ddloc **)&(dirp->dd_ddloc);
+***************
+*** 277,283 ****
+ dirp->dd_seek = lp->loc_seek;
+ dirp->dd_loc = 0;
+ while (dirp->dd_loc < lp->loc_loc) {
+! if (!(dp = readdir(dirp))) {
+ *prevlp = lp->loc_next;
+ break;
+ }
+--- 281,287 ----
+ dirp->dd_seek = lp->loc_seek;
+ dirp->dd_loc = 0;
+ while (dirp->dd_loc < lp->loc_loc) {
+! if (readdir_r(dirp, &de, &dp)) {
+ *prevlp = lp->loc_next;
+ break;
+ }
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/gen/getcwd.c pthreads-1_60_beta6+/gen/getcwd.c
+*** pthreads-1_60_beta6/gen/getcwd.c Sat Sep 2 17:39:30 1995
+--- pthreads-1_60_beta6+/gen/getcwd.c Sat Mar 15 14:08:55 1997
+***************
+*** 50,67 ****
+ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
+ dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
+
+ char *
+ getcwd(pt, size)
+ char *pt;
+ size_t size;
+ {
+- register struct dirent *dp;
+ register DIR *dir;
+ register dev_t dev;
+ register ino_t ino;
+ register int first;
+ register char *bpt, *bup;
+ struct stat s;
+ dev_t root_dev;
+ ino_t root_ino;
+ size_t ptsize, upsize;
+--- 50,71 ----
+ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
+ dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
+
++ /* Only use reentrant safe routines to simplify varifying POSIX thread-safe
++ * compliance. (mevans).
++ */
+ char *
+ getcwd(pt, size)
+ char *pt;
+ size_t size;
+ {
+ register DIR *dir;
+ register dev_t dev;
+ register ino_t ino;
+ register int first;
+ register char *bpt, *bup;
+ struct stat s;
++ struct dirent *dp;
++ struct dirent de;
+ dev_t root_dev;
+ ino_t root_ino;
+ size_t ptsize, upsize;
+***************
+*** 166,179 ****
+ save_errno = 0;
+ if (s.st_dev == dev) {
+ for (;;) {
+! if (!(dp = readdir(dir)))
+ goto notfound;
+ if (dp->d_fileno == ino)
+ break;
+ }
+ } else
+ for (;;) {
+! if (!(dp = readdir(dir)))
+ goto notfound;
+ if (ISDOT(dp))
+ continue;
+--- 170,183 ----
+ save_errno = 0;
+ if (s.st_dev == dev) {
+ for (;;) {
+! if (readdir_r(dir, &de, &dp))
+ goto notfound;
+ if (dp->d_fileno == ino)
+ break;
+ }
+ } else
+ for (;;) {
+! if (readdir_r(dir, &de, &dp))
+ goto notfound;
+ if (ISDOT(dp))
+ continue;
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/include/syslog.h pthreads-1_60_beta6+/include/syslog.h
+*** pthreads-1_60_beta6/include/syslog.h Mon Sep 26 21:26:29 1994
+--- pthreads-1_60_beta6+/include/syslog.h Sat Mar 15 14:08:56 1997
+***************
+*** 9,14 ****
+--- 9,16 ----
+ #ifndef SYSLOG_H
+ #define SYSLOG_H
+
++ /* Added __[BEGIN/END]_DECLS so this file would work with C++. (mevans) */
++ #include <sys/cdefs.h>
+ #include <stdarg.h>
+
+ /* Discipline: openlog(), closelog(), and setlogmask() are not thread-safe
+***************
+*** 84,95 ****
+--- 86,101 ----
+ #define LOG_NDELAY 0x08 /* don't delay open */
+ #define LOG_NOWAIT 0x10 /* if forking to log on console, don't wait() */
+
++ __BEGIN_DECLS
++
+ /* Syslogging functions. */
+ void syslog(int pri, char *fmt, ...);
+ void vsyslog(int pri, char *fmt, va_list args);
+ void openlog(char *ident, int logstat, int logfac);
+ void closelog(void);
+ int setlogmask(int pmask);
++
++ __END_DECLS
+
+ #endif
+
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/machdep/engine-i386-linux-1.0.c pthreads-1_60_beta6+/machdep/engine-i386-linux-1.0.c
+*** pthreads-1_60_beta6/machdep/engine-i386-linux-1.0.c Mon Oct 21 20:39:13 1996
+--- pthreads-1_60_beta6+/machdep/engine-i386-linux-1.0.c Sat Mar 15 14:08:56 1997
+***************
+*** 142,147 ****
+--- 142,149 ----
+ * machdep_pthread_start().
+ */
+ machdep_pthread->machdep_state->__pc = (char *)machdep_pthread_start;
++ machdep_pthread->machdep_state->__bp = (char *)0;/* So the backtrace
++ * is sensible (mevans) */
+
+ /* Stack starts high and builds down. */
+ machdep_pthread->machdep_state->__sp =
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/machdep/syscall-i386-linux-1.0.S pthreads-1_60_beta6+/machdep/syscall-i386-linux-1.0.S
+*** pthreads-1_60_beta6/machdep/syscall-i386-linux-1.0.S Mon Oct 21 22:17:32 1996
+--- pthreads-1_60_beta6+/machdep/syscall-i386-linux-1.0.S Sat Mar 15 14:08:56 1997
+***************
+*** 148,156 ****
+ /* =========================================================================
+ * exit 1 select 82
+ * fork 2 socketcall 102
+! * read 3 readv 145
+! * write 4 writev 146
+! * open 5
+ * creat 8
+ * link 9
+ * unlink 10
+--- 148,156 ----
+ /* =========================================================================
+ * exit 1 select 82
+ * fork 2 socketcall 102
+! * read 3 flock 143
+! * write 4 readv 145
+! * open 5 writev 146
+ * creat 8
+ * link 9
+ * unlink 10
+***************
+*** 390,394 ****
+--- 390,401 ----
+ */
+ #ifdef HAVE_SYSCALL_WRITEV
+ SYSCALL3(writev)
++ #endif
++
++ /* ==========================================================================
++ * machdep_sys_flock()
++ */
++ #ifdef HAVE_SYSCALL_FLOCK
++ SYSCALL2(flock)
+ #endif
+
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/net/gethostbyname.c pthreads-1_60_beta6+/net/gethostbyname.c
+*** pthreads-1_60_beta6/net/gethostbyname.c Mon Apr 22 22:41:21 1996
+--- pthreads-1_60_beta6+/net/gethostbyname.c Sat Mar 15 14:08:58 1997
+***************
+*** 146,161 ****
+ {
+ char **alias;
+ FILE *fp = NULL;
+
+ pthread_mutex_lock(&host_iterate_lock);
+ sethostent(0);
+! while ((result = gethostent_r(result, buf, bufsize, errval)) != NULL) {
+ /* Check the entry's name and aliases against the given name. */
+ if (strcasecmp(result->h_name, name) == 0)
+ break;
+ for (alias = result->h_aliases; *alias; alias++) {
+! if (strcasecmp(*alias, name) == 0)
+ break;
+ }
+ }
+ pthread_mutex_unlock(&host_iterate_lock);
+--- 146,166 ----
+ {
+ char **alias;
+ FILE *fp = NULL;
++ int fFound = FALSE;
+
+ pthread_mutex_lock(&host_iterate_lock);
+ sethostent(0);
+! while (!fFound && (result = gethostent_r(result, buf, bufsize, errval))
+! != NULL) {
+ /* Check the entry's name and aliases against the given name. */
+ if (strcasecmp(result->h_name, name) == 0)
+ break;
+ for (alias = result->h_aliases; *alias; alias++) {
+! if (strcasecmp(*alias, name) == 0) {
+! /* fFound will exit while loop. (mevans). */
+! fFound = TRUE;
+ break;
++ }
+ }
+ }
+ pthread_mutex_unlock(&host_iterate_lock);
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/net/res_debug.c pthreads-1_60_beta6+/net/res_debug.c
+*** pthreads-1_60_beta6/net/res_debug.c Thu Feb 23 22:42:35 1995
+--- pthreads-1_60_beta6+/net/res_debug.c Sat Mar 15 14:08:58 1997
+***************
+*** 375,380 ****
+--- 375,383 ----
+
+ /*
+ * Print resource record fields in human readable form.
++ *
++ * Removed calls to non-reentrant routines to simplify varifying
++ * POSIX thread-safe implementations. (mevans).
+ */
+ char *
+ p_rr(cp, msg, file)
+***************
+*** 386,391 ****
+--- 389,395 ----
+ char *cp1, *cp2;
+ u_long tmpttl, t;
+ int lcnt;
++ char buf[32];
+
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL); /* compression error */
+***************
+*** 413,426 ****
+ case C_HS:
+ bcopy(cp, (char *)&inaddr, sizeof(inaddr));
+ if (dlen == 4) {
+! fprintf(file,"\t%s", inet_ntoa(inaddr));
+ cp += dlen;
+ } else if (dlen == 7) {
+ char *address;
+ u_char protocol;
+ u_short port;
+
+! address = inet_ntoa(inaddr);
+ cp += sizeof(inaddr);
+ protocol = *(u_char*)cp;
+ cp += sizeof(u_char);
+--- 417,432 ----
+ case C_HS:
+ bcopy(cp, (char *)&inaddr, sizeof(inaddr));
+ if (dlen == 4) {
+! fprintf(file,"\t%s",
+! inet_ntoa_r(inaddr, buf, sizeof(buf)));
+ cp += dlen;
+ } else if (dlen == 7) {
+ char *address;
+ u_char protocol;
+ u_short port;
+
+! address = inet_ntoa_r(inaddr,
+! buf, sizeof(buf));
+ cp += sizeof(inaddr);
+ protocol = *(u_char*)cp;
+ cp += sizeof(u_char);
+***************
+*** 524,530 ****
+ bcopy(cp, (char *)&inaddr, sizeof(inaddr));
+ cp += sizeof(u_long);
+ fprintf(file, "\t%s %s ( ",
+! inet_ntoa(inaddr),
+ deproto((int) *cp));
+ cp += sizeof(u_char);
+ n = 0;
+--- 530,536 ----
+ bcopy(cp, (char *)&inaddr, sizeof(inaddr));
+ cp += sizeof(u_long);
+ fprintf(file, "\t%s %s ( ",
+! inet_ntoa_r(inaddr, buf, sizeof(buf)),
+ deproto((int) *cp));
+ cp += sizeof(u_char);
+ n = 0;
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/pthreads/fd_kern.c pthreads-1_60_beta6+/pthreads/fd_kern.c
+*** pthreads-1_60_beta6/pthreads/fd_kern.c Tue Oct 1 12:26:48 1996
+--- pthreads-1_60_beta6+/pthreads/fd_kern.c Sat Mar 15 14:09:00 1997
+***************
+*** 215,221 ****
+ * Called when there is no active thread to run.
+ */
+ extern struct timeval __fd_kern_wait_timeout;
+!
+ void fd_kern_wait()
+ {
+ fd_set fd_set_read, fd_set_write, fd_set_except;
+--- 215,221 ----
+ * Called when there is no active thread to run.
+ */
+ extern struct timeval __fd_kern_wait_timeout;
+! extern volatile sig_atomic_t sig_to_process;
+ void fd_kern_wait()
+ {
+ fd_set fd_set_read, fd_set_write, fd_set_except;
+***************
+*** 254,260 ****
+
+ machdep_unset_thread_timer(NULL);
+ __fd_kern_wait_timeout.tv_usec = 0;
+! __fd_kern_wait_timeout.tv_sec = 3600;
+
+ machdep_sys_sigprocmask(SIG_UNBLOCK, &sig_to_block, &oset);
+
+--- 254,260 ----
+
+ machdep_unset_thread_timer(NULL);
+ __fd_kern_wait_timeout.tv_usec = 0;
+! __fd_kern_wait_timeout.tv_sec = (sig_to_process) ? 0 : 3600;
+
+ machdep_sys_sigprocmask(SIG_UNBLOCK, &sig_to_block, &oset);
+
+***************
+*** 726,731 ****
+--- 726,753 ----
+ return(ret);
+ }
+
++ #if defined (HAVE_SYSCALL_FLOCK)
++ /* ==========================================================================
++ * flock()
++ *
++ * Added (mevans)
++ */
++ int flock(int fd, int operation)
++ {
++ int ret;
++
++ if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
++ if ((ret = machdep_sys_flock(fd_table[fd]->fd.i,
++ operation)) < OK) {
++ SET_ERRNO(-ret);
++ ret = NOTOK;
++ }
++ fd_unlock(fd, FD_RDWR);
++ }
++ return(ret);
++ }
++ #endif
++
+ /* ==========================================================================
+ * pipe()
+ */
+***************
+*** 1126,1132 ****
+ /* Get the error, this function should not fail */
+ machdep_sys_getsockopt(fd_table[fd]->fd.i, SOL_SOCKET,
+ SO_ERROR, &ret, &tmpnamelen);
+! SET_ERRNO(-ret);
+ ret = NOTOK;
+ }
+ } else {
+--- 1148,1155 ----
+ /* Get the error, this function should not fail */
+ machdep_sys_getsockopt(fd_table[fd]->fd.i, SOL_SOCKET,
+ SO_ERROR, &ret, &tmpnamelen);
+! /* ret is already positive (mevans) */
+! SET_ERRNO(ret);
+ ret = NOTOK;
+ }
+ } else {
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/pthreads/malloc.c pthreads-1_60_beta6+/pthreads/malloc.c
+*** pthreads-1_60_beta6/pthreads/malloc.c Thu Mar 9 21:06:43 1995
+--- pthreads-1_60_beta6+/pthreads/malloc.c Sat Mar 15 14:09:00 1997
+***************
+*** 196,204 ****
+ else
+ n = n - x;
+ if (n) {
+! if (sbrk(n) == (char *)-1)
+ return (NULL);
+ }
+ bucket = 0;
+ amt = 8;
+ while (pagesz > amt) {
+--- 196,207 ----
+ else
+ n = n - x;
+ if (n) {
+! if (sbrk(n) == (char *)-1) {
+! /* Unlock before returning (mevans) */
+! pthread_mutex_unlock(mutex);
+ return (NULL);
+ }
++ }
+ bucket = 0;
+ amt = 8;
+ while (pagesz > amt) {
+***************
+*** 363,366 ****
+--- 366,382 ----
+ free(cp);
+
+ return (res);
++ }
++ /* ==========================================================================
++ * calloc()
++ *
++ * Added to ensure pthread's allocation is used (mevans).
++ */
++ void *calloc(size_t nmemb, size_t size)
++ {
++ void *p;
++ size *= nmemb;
++ p = malloc(size);
++ if (p) memset(p, 0, size);
++ return (p);
+ }
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/pthreads/select.c pthreads-1_60_beta6+/pthreads/select.c
+*** pthreads-1_60_beta6/pthreads/select.c Sat Jul 6 21:58:55 1996
+--- pthreads-1_60_beta6+/pthreads/select.c Sat Mar 15 14:09:00 1997
+***************
+*** 165,176 ****
+ pthread_resched_resume(PS_SELECT_WAIT);
+
+ /* We're awake */
+- CLEAR_PF_DONE_EVENT(pthread_run);
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ ret = OK;
+ } else {
+ ret = data.nfds;
+ }
+ } else {
+ pthread_resched_resume(PS_SELECT_WAIT);
+ CLEAR_PF_DONE_EVENT(pthread_run);
+--- 165,180 ----
+ pthread_resched_resume(PS_SELECT_WAIT);
+
+ /* We're awake */
+ if (sleep_cancel(pthread_run) == NOTOK) {
+ ret = OK;
+ } else {
+ ret = data.nfds;
+ }
++ /* Moving this after the sleep_cancel() seemed
++ * to fix intermittent crashes during heavy
++ * socket use. (mevans)
++ */
++ CLEAR_PF_DONE_EVENT(pthread_run);
+ } else {
+ pthread_resched_resume(PS_SELECT_WAIT);
+ CLEAR_PF_DONE_EVENT(pthread_run);
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/pthreads/signal.c pthreads-1_60_beta6+/pthreads/signal.c
+*** pthreads-1_60_beta6/pthreads/signal.c Tue Mar 12 21:33:17 1996
+--- pthreads-1_60_beta6+/pthreads/signal.c Sat Mar 15 14:09:00 1997
+***************
+*** 65,71 ****
+ */
+
+ static sig_atomic_t signum_to_process[SIGMAX + 1] = { 0, };
+! static sig_atomic_t sig_to_process = 0;
+
+ /* static volatile sigset_t sig_to_process; */
+ static volatile int sig_count = 0;
+--- 65,71 ----
+ */
+
+ static sig_atomic_t signum_to_process[SIGMAX + 1] = { 0, };
+! volatile sig_atomic_t sig_to_process = 0;
+
+ /* static volatile sigset_t sig_to_process; */
+ static volatile int sig_count = 0;
+***************
+*** 303,309 ****
+ break;
+ case NOTOK:
+ /* Do the registered action, no threads were sleeping */
+! sigdefault(sig);
+ break;
+ }
+ break;
+--- 303,317 ----
+ break;
+ case NOTOK:
+ /* Do the registered action, no threads were sleeping */
+! /* There is a timing window that gets
+! * here when no threads are on the
+! * sleep queue. This is a quick fix.
+! * The real problem is possibly related
+! * to heavy use of condition variables
+! * with time outs.
+! * (mevans)
+! *sigdefault(sig);
+! */
+ break;
+ }
+ break;
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/stdio/setvbuf.c pthreads-1_60_beta6+/stdio/setvbuf.c
+*** pthreads-1_60_beta6/stdio/setvbuf.c Sat Sep 3 20:58:36 1994
+--- pthreads-1_60_beta6+/stdio/setvbuf.c Sat Mar 15 14:09:00 1997
+***************
+*** 142,148 ****
+ flags |= __SLBF;
+ if (flags & __SRW)
+ flags &= ~(__SRD | __SWR);
+! fp->_w = 0;
+ fp->_flags = flags;
+ fp->_bf._base = fp->_p = (unsigned char *)buf;
+ fp->_bf._size = size;
+--- 142,148 ----
+ flags |= __SLBF;
+ if (flags & __SRW)
+ flags &= ~(__SRD | __SWR);
+! fp->_w = size; /* Was 0 (mevans) */
+ fp->_flags = flags;
+ fp->_bf._base = fp->_p = (unsigned char *)buf;
+ fp->_bf._size = size;
+diff -c -b -r -d -I .*$Id:.* pthreads-1_60_beta6/stdlib/system.c pthreads-1_60_beta6+/stdlib/system.c
+*** pthreads-1_60_beta6/stdlib/system.c Wed Apr 24 21:18:56 1996
+--- pthreads-1_60_beta6+/stdlib/system.c Sat Mar 15 14:09:01 1997
+***************
+*** 62,68 ****
+ argp[2] = (char *) command;
+ sigemptyset(&tmp_mask);
+ sigaddset(&tmp_mask, SIGCHLD);
+! pthread_sigmask(SIG_BLOCK, tmp_mask, &old_mask);
+ switch(pid = fork()) {
+ case -1: /* error */
+ (void)pthread_sigmask(SIG_SETMASK, &old_mask, NULL);
+--- 62,69 ----
+ argp[2] = (char *) command;
+ sigemptyset(&tmp_mask);
+ sigaddset(&tmp_mask, SIGCHLD);
+! /* Pass the address of tmp_mask to avoid a sigfault. (mevans). */
+! pthread_sigmask(SIG_BLOCK, &tmp_mask, &old_mask);
+ switch(pid = fork()) {
+ case -1: /* error */
+ (void)pthread_sigmask(SIG_SETMASK, &old_mask, NULL);
diff --git a/mit-pthreads/patches/p153 b/mit-pthreads/patches/p153
new file mode 100755
index 00000000000..4e374e29a10
--- /dev/null
+++ b/mit-pthreads/patches/p153
@@ -0,0 +1,90 @@
+<HEAD><TITLE>discuss@charon.mit.edu: [153] in "Pthreads Bugs"</TITLE>
+<H1>[153] in Pthreads Bugs</H1></HEAD>
+<A HREF="/"><IMG SRC="/i-d.gif" ALT="root"></A>
+<A HREF="?153"><IMG SRC="/i-back.gif" ALT="meeting"></A>
+<A HREF="/help.html"><IMG SRC="/i-help.gif" ALT="help"></A>
+<A HREF="1"><IMG SRC="/i-first.gif" ALT="first"></A>
+<A HREF="151"><IMG SRC="/i-fref.gif" ALT="first in chain"></A>
+<A HREF="152"><IMG SRC="/i-pref.gif" ALT="previous in chain"></A>
+<A HREF="152"><IMG SRC="/i-prev.gif" ALT="previous"></A>
+<A HREF="154"><IMG SRC="/i-next.gif" ALT="next"></A>
+<IMG SRC="/n-nref.gif" ALT="">
+<IMG SRC="/n-lref.gif" ALT="">
+<A HREF="161"><IMG SRC="/i-last.gif" ALT="last"></A>
+<HR><H2>Re: sleep / SIGALRM problem in 1_60_beta6</H2>
+<H3>daemon@ATHENA.MIT.EDU (Mon Dec 9 19:32:22 1996
+)</H3>
+<PRE>
+Date: Mon, 09 Dec 1996 17:22:50 -0700
+From: "Mark M. Evans" &lt;mevans@cti-ltd.com&gt;
+To: Tim Hinderliter &lt;kyd@internap.com&gt;
+Cc: pthreads-bugs@MIT.EDU
+
+I think I found what caused fd_kern_wait() to block for the entire
+hour (instead of waking up due to the SIGALRM). Basically, the
+SIGALRM that would move the sleeping thread to the run queue occurs
+while pthread_kernel_lock is set, but *before* the critical section in
+fd_kern_wait() that sets __fd_kern_wait_timeout.tv_sec to 3600. So,
+sig_handler_real() clears __fd_kern_wait_timeout.tv_sec "too soon."
+
+I've worked around this by checking sig_to_process in the critical
+section to determine if we are truly idle. To do this I had to make
+sig_to_process publicly available.
+
+Here are the diffs (relative to the pthreads/pthreads directory):
+
+diff -c -r1.2 -r1.3
+*** signal.c 1996/11/20 05:09:50 1.2
+--- signal.c 1996/12/09 23:14:52 1.3
+***************
+*** 65,71 ****
+ */
+
+ static sig_atomic_t signum_to_process[SIGMAX + 1] = { 0, };
+! static sig_atomic_t sig_to_process = 0;
+
+ /* static volatile sigset_t sig_to_process; */
+ static volatile int sig_count = 0;
+--- 65,71 ----
+ */
+
+ static sig_atomic_t signum_to_process[SIGMAX + 1] = { 0, };
+! sig_atomic_t sig_to_process = 0;
+
+ /* static volatile sigset_t sig_to_process; */
+ static volatile int sig_count = 0;
+*** fd_kern.c 1996/12/03 04:14:59 1.6
+--- fd_kern.c 1996/12/09 23:14:51 1.7
+***************
+*** 215,221 ****
+ * Called when there is no active thread to run.
+ */
+ extern struct timeval __fd_kern_wait_timeout;
+!
+ void fd_kern_wait()
+ {
+ fd_set fd_set_read, fd_set_write, fd_set_except;
+--- 215,221 ----
+ * Called when there is no active thread to run.
+ */
+ extern struct timeval __fd_kern_wait_timeout;
+! extern volatile sig_atomic_t sig_to_process;
+ void fd_kern_wait()
+ {
+ fd_set fd_set_read, fd_set_write, fd_set_except;
+***************
+*** 254,260 ****
+
+ machdep_unset_thread_timer(NULL);
+ __fd_kern_wait_timeout.tv_usec = 0;
+! __fd_kern_wait_timeout.tv_sec = 3600;
+
+ machdep_sys_sigprocmask(SIG_UNBLOCK, &amp;sig_to_block, &amp;oset);
+
+--- 254,260 ----
+
+ machdep_unset_thread_timer(NULL);
+ __fd_kern_wait_timeout.tv_usec = 0;
+! __fd_kern_wait_timeout.tv_sec = (sig_to_process) ? 0 : 3600;
+
+ machdep_sys_sigprocmask(SIG_UNBLOCK, &amp;sig_to_block, &amp;oset);
diff --git a/mit-pthreads/patches/p155 b/mit-pthreads/patches/p155
new file mode 100755
index 00000000000..dbdfa7de899
--- /dev/null
+++ b/mit-pthreads/patches/p155
@@ -0,0 +1,96 @@
+<HEAD><TITLE>discuss@charon.mit.edu: [155] in "Pthreads Bugs"</TITLE>
+<H1>[155] in Pthreads Bugs</H1></HEAD>
+<A HREF="/"><IMG SRC="/i-d.gif" ALT="root"></A>
+<A HREF="?155"><IMG SRC="/i-back.gif" ALT="meeting"></A>
+<A HREF="/help.html"><IMG SRC="/i-help.gif" ALT="help"></A>
+<A HREF="1"><IMG SRC="/i-first.gif" ALT="first"></A>
+<IMG SRC="/n-fref.gif" ALT="">
+<IMG SRC="/n-pref.gif" ALT="">
+<A HREF="154"><IMG SRC="/i-prev.gif" ALT="previous"></A>
+<A HREF="156"><IMG SRC="/i-next.gif" ALT="next"></A>
+<IMG SRC="/n-nref.gif" ALT="">
+<IMG SRC="/n-lref.gif" ALT="">
+<A HREF="161"><IMG SRC="/i-last.gif" ALT="last"></A>
+<HR><H2>pthread_kill() Bug</H2>
+<H3>daemon@ATHENA.MIT.EDU (Thu Dec 26 20:34:45 1996
+)</H3>
+<PRE>
+From: Chris Colohan &lt;colohan@eecg.toronto.edu&gt;
+To: pthreads-bugs@MIT.EDU, proven@MIT.EDU
+Date: Thu, 26 Dec 1996 20:33:48 -0500
+
+pthread_kill() has a problem in PThreads 1.60beta6. It checks to see
+if the target thread is in the state PS_SIGWAIT, and if it is it
+reschedules it. But it does not check if there is more than one
+thread in the PS_SIGWAIT state, and hence mangles the pthread_sigwait
+linked list, potentially resulting in threads getting blocked forever,
+and signals never being delivered. I have a *very* contrived test
+case that demonstrates this problem if you would like it. Please let
+me know...
+
+Chris
+===
+
+Diffs created with diff -c:
+
+*** /home/colohan/thesis/t/pthreads-1_60_beta6/pthreads/pthread_kill.c Tue Feb 21 03:07:18 1995
+--- pthread_kill.c Thu Dec 26 19:50:22 1996
+***************
+*** 41,51 ****
+--- 41,58 ----
+
+ #include &lt;pthread.h&gt;
+
++ /* Defined in sig.c, a linked list of threads currently
++ * blocked in sigwait(): */
++ extern struct pthread * pthread_sigwait;
++
++
+ /* ==========================================================================
+ * pthread_kill()
+ */
+ int pthread_kill(struct pthread * pthread, int sig)
+ {
++ struct pthread ** pthread_ptr;
++
+ pthread_sched_prevent();
+
+ /* Check who is the current owner of pthread */
+***************
+*** 53,62 ****
+ if (0) {
+ } else {
+ if (pthread-&gt;state == PS_SIGWAIT) {
+! if (sigismember(pthread-&gt;data.sigwait, sig)) {
+! *(int *)(pthread-&gt;ret) = sig;
+! pthread_sched_other_resume(pthread);
+! return(OK);
+ }
+ }
+ sigaddset(&amp;(pthread-&gt;sigpending), sig);
+--- 60,84 ----
+ if (0) {
+ } else {
+ if (pthread-&gt;state == PS_SIGWAIT) {
+! if(sigismember(pthread-&gt;data.sigwait, sig)) {
+! for (pthread_ptr = &amp;pthread_sigwait;
+! (*pthread_ptr);
+! pthread_ptr = &amp;((*pthread_ptr)-&gt;next)) {
+! if ((*pthread_ptr) == pthread) {
+!
+! /* Take the thread out of the
+! * pthread_sigwait linked list: */
+! *pthread_ptr=(*pthread_ptr)-&gt;next;
+!
+! *(int *)(pthread-&gt;ret) = sig;
+! pthread_sched_other_resume(pthread);
+! return(OK);
+! }
+! }
+! /* A thread should not be in the state PS_SIGWAIT
+! * without being in the pthread_sigwait linked
+! * list: */
+! PANIC();
+ }
+ }
+ sigaddset(&amp;(pthread-&gt;sigpending), sig);