[106] in Pthreads mailing list archive
Patches for pthreads-1.60 beta3
daemon@ATHENA.MIT.EDU (NIIBE Yutaka)
Wed Sep 6 00:06:50 1995
Date: Wed, 6 Sep 1995 12:44:29 +0900
From: NIIBE Yutaka <gniibe@mri.co.jp>
To: pthreads@MIT.EDU
Hi, I tried to make threaded X work with pthread on Linux. I use
libc-5.2.7 (it includes pthread) by H.J. Lu, and found some problem.
With these fixes, at least multi-threaded ico works fine. :-)
--
NIIBE Yutaka
Mitsubishi Research Institute, Inc.
====================================== Start of REPORT ===============
(1) fcntl() should not set __FD_NONBLOCK flag in file descripter table.
Pthread library assumes all file descripters are set to NONBLOCK and
__FD_NONBLOCK flag in `fd_table[fd]->flags' is not set. Fcntl breaks
this. Here is fix.
--- pthreads/pthreads/fd.c.orig Tue May 30 23:51:22 1995
+++ pthreads/pthreads/fd.c Wed Sep 6 11:46:49 1995
@@ -851,7 +851,7 @@
flags = va_arg(ap, int);
if ((ret = fd_table[fd]->ops->fcntl(fd_table[fd]->fd,
fd_table[fd]->flags, cmd, flags | __FD_NONBLOCK)) == OK) {
- fd_table[fd]->flags = flags;
+ fd_table[fd]->flags = flags & ~__FD_NONBLOCK;
}
break;
/* case F_SETLKW: */
(2) pthread_sig_process() assumes that pthread_kernel is locked, but
acutually there ara cases that it is called unlocked. Here is fix.
niibe% diff -u pthreads/pthreads/signal.c.orig pthreads/pthreads/signal.c
--- pthreads/pthreads/signal.c.orig Wed Jun 14 16:28:37 1995
+++ pthreads/pthreads/signal.c Wed Sep 6 11:46:49 1995
@@ -454,7 +454,9 @@
sig_handler(0);
} else {
if (pthread_run && pthread_run->sigcount) {
+ pthread_kernel_lock++;
pthread_sig_process();
+ pthread_kernel_lock--;
}
break;
}
@@ -479,7 +481,9 @@
sig_handler(0);
} else {
if (pthread_run && pthread_run->sigcount) {
+ pthread_kernel_lock++;
pthread_sig_process();
+ pthread_kernel_lock--;
}
break;
}
@@ -498,7 +502,9 @@
sig_handler(0);
} else {
if (pthread_run && pthread_run->sigcount) {
+ pthread_kernel_lock++;
pthread_sig_process();
+ pthread_kernel_lock--;
}
break;
}
(3) PREVENT/RESUME mismatch
pthread_sched_prevent() and pthread_resched_resume()/pthread_sched_resume()
must be matched. But there are some mismatches, here is fix.
--- pthreads/pthreads/cond.c.orig Wed Jun 14 16:28:28 1995
+++ pthreads/pthreads/cond.c Wed Sep 6 11:46:49 1995
@@ -173,6 +173,7 @@
pthread_mutex_lock(&pthread_cond_debug_mutex);
if (pthread_cond_is_debug(cond) == NOTOK) {
pthread_mutex_lock(&pthread_cond_debug_mutex);
+ pthread_sched_resume();
return(EINVAL);
}
pthread_mutex_lock(&pthread_cond_debug_mutex);
@@ -217,6 +218,7 @@
pthread_mutex_lock(&pthread_cond_debug_mutex);
if (pthread_cond_is_debug(cond) == NOTOK) {
pthread_mutex_lock(&pthread_cond_debug_mutex);
+ pthread_sched_resume();
return(EINVAL);
}
pthread_mutex_lock(&pthread_cond_debug_mutex);
@@ -273,6 +275,7 @@
pthread_mutex_lock(&pthread_cond_debug_mutex);
if (pthread_cond_is_debug(cond) == NOTOK) {
pthread_mutex_lock(&pthread_cond_debug_mutex);
+ pthread_sched_resume();
return(EINVAL);
}
pthread_mutex_lock(&pthread_cond_debug_mutex);
@@ -313,6 +316,7 @@
pthread_mutex_lock(&pthread_cond_debug_mutex);
if (pthread_cond_is_debug(cond) == NOTOK) {
pthread_mutex_lock(&pthread_cond_debug_mutex);
+ pthread_sched_resume();
return(EINVAL);
}
pthread_mutex_lock(&pthread_cond_debug_mutex);
--- pthreads/pthreads/schedparam.c.orig Sun Apr 2 19:45:00 1995
+++ pthreads/pthreads/schedparam.c Wed Sep 6 11:46:49 1995
@@ -124,6 +124,7 @@
} else {
pthread->attr.schedparam_policy = new_policy;
pthread->pthread_priority = prio;
+ pthread_sched_resume();
}
return(OK);
break;
(4) Select
(4-1) When timeout, it should not return error.
(4-2) When first machdep_sys_select returns >OK, it shouldn't set errno.
--- pthreads/pthreads/select.c.orig Fri May 19 02:44:26 1995
+++ pthreads/pthreads/select.c Wed Sep 6 12:04:01 1995
@@ -167,8 +167,12 @@
/* We're awake */
CLEAR_PF_DONE_EVENT(pthread_run);
if (sleep_cancel(pthread_run) == NOTOK) {
+#if 0
SET_ERRNO(ETIMEDOUT);
ret = -ETIMEDOUT;
+#else
+ ret = OK;
+#endif
} else {
ret = data.nfds;
}
@@ -177,8 +181,9 @@
CLEAR_PF_DONE_EVENT(pthread_run);
ret = data.nfds; /* XXX ??? snl */
}
- } else {
+ } else if (ret < 0) {
SET_ERRNO(-ret);
+ ret = NOTOK;
}
}
(5) Not implemented.
(5-1) As Alan Cox introduces sendmsg/recvmsg around Linux 1.3.20,
we now have those system calls.
--- pthreads/machdep/engine-i386-linux-1.0.c.orig Tue May 30 23:39:40 1995
+++ pthreads/machdep/engine-i386-linux-1.0.c Wed Sep 6 12:33:13 1995
@@ -390,7 +390,13 @@
*/
int machdep_sys_sendmsg(int a, char * b, int c)
{
- return(-ENOSYS);
+ int array[3];
+
+ array[0] = (int)a;
+ array[1] = (int)b;
+ array[2] = (int)c;
+
+ return(machdep_sys_socketcall(SYS_SENDMSG, array));
}
/* ==========================================================================
@@ -436,7 +442,13 @@
*/
int machdep_sys_recvmsg(int a, char * b, int c)
{
- return(-ENOSYS);
+ int array[3];
+
+ array[0] = (int)a;
+ array[1] = (int)b;
+ array[2] = (int)c;
+
+ return(machdep_sys_socketcall(SYS_RECVMSG, array));
}
/* ==========================================================================
====================================== END of REPORT =====================