summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eischen <deischen@FreeBSD.org>2002-08-29 23:06:07 +0000
committerDaniel Eischen <deischen@FreeBSD.org>2002-08-29 23:06:07 +0000
commitd8b5986dd6a718d948b9ea0e2da3256ac45bff42 (patch)
tree24c4da9130c487d85f113d7fdfa44a22f470cb61
parentee92a1ab51e1543706ad3802c5d218b04df5e0ba (diff)
Notes
-rw-r--r--lib/libc_r/uthread/pthread_private.h8
-rw-r--r--lib/libc_r/uthread/uthread_accept.c9
-rw-r--r--lib/libc_r/uthread/uthread_close.c3
-rw-r--r--lib/libc_r/uthread/uthread_connect.c6
-rw-r--r--lib/libc_r/uthread/uthread_dup.c2
-rw-r--r--lib/libc_r/uthread/uthread_dup2.c4
-rw-r--r--lib/libc_r/uthread/uthread_execve.c2
-rw-r--r--lib/libc_r/uthread/uthread_exit.c2
-rw-r--r--lib/libc_r/uthread/uthread_fcntl.c11
-rw-r--r--lib/libc_r/uthread/uthread_fd.c16
-rw-r--r--lib/libc_r/uthread/uthread_ioctl.c9
-rw-r--r--lib/libc_r/uthread/uthread_read.c4
-rw-r--r--lib/libc_r/uthread/uthread_readv.c4
-rw-r--r--lib/libc_r/uthread/uthread_recvfrom.c3
-rw-r--r--lib/libc_r/uthread/uthread_recvmsg.c3
-rw-r--r--lib/libc_r/uthread/uthread_sendfile.c6
-rw-r--r--lib/libc_r/uthread/uthread_sendmsg.c3
-rw-r--r--lib/libc_r/uthread/uthread_sendto.c3
-rw-r--r--lib/libc_r/uthread/uthread_sig.c2
-rw-r--r--lib/libc_r/uthread/uthread_write.c4
-rw-r--r--lib/libc_r/uthread/uthread_writev.c4
-rw-r--r--lib/libkse/thread/thr_close.c3
-rw-r--r--lib/libkse/thread/thr_exit.c2
-rw-r--r--lib/libkse/thread/thr_fcntl.c11
-rw-r--r--lib/libkse/thread/thr_private.h8
-rw-r--r--lib/libkse/thread/thr_read.c4
-rw-r--r--lib/libkse/thread/thr_readv.c4
-rw-r--r--lib/libkse/thread/thr_sig.c2
-rw-r--r--lib/libkse/thread/thr_write.c4
-rw-r--r--lib/libkse/thread/thr_writev.c4
-rw-r--r--lib/libpthread/thread/thr_close.c3
-rw-r--r--lib/libpthread/thread/thr_exit.c2
-rw-r--r--lib/libpthread/thread/thr_fcntl.c11
-rw-r--r--lib/libpthread/thread/thr_private.h8
-rw-r--r--lib/libpthread/thread/thr_read.c4
-rw-r--r--lib/libpthread/thread/thr_readv.c4
-rw-r--r--lib/libpthread/thread/thr_sig.c2
-rw-r--r--lib/libpthread/thread/thr_write.c4
-rw-r--r--lib/libpthread/thread/thr_writev.c4
39 files changed, 115 insertions, 77 deletions
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h
index ef45706710f36..97b30b703092b 100644
--- a/lib/libc_r/uthread/pthread_private.h
+++ b/lib/libc_r/uthread/pthread_private.h
@@ -1140,8 +1140,6 @@ void _set_curthread(struct pthread *);
void *_thread_stack_alloc(size_t, size_t);
void _thread_stack_free(void *, size_t, size_t);
int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
-int _thread_fd_lock(int, int, struct timespec *);
-int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
int _mutex_cv_lock(pthread_mutex_t *);
int _mutex_cv_unlock(pthread_mutex_t *);
void _mutex_lock_backout(pthread_t);
@@ -1177,6 +1175,11 @@ void _waitq_clearactive(void);
#endif
void _thread_exit(char *, int, char *);
void _thread_exit_cleanup(void);
+int _thread_fd_getflags(int);
+int _thread_fd_lock(int, int, struct timespec *);
+int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
+void _thread_fd_setflags(int, int);
+int _thread_fd_table_init(int fd);
void _thread_fd_unlock(int, int);
void _thread_fd_unlock_debug(int, int, char *, int);
void _thread_fd_unlock_owned(pthread_t);
@@ -1203,7 +1206,6 @@ void _thread_sigframe_restore(struct pthread *thread,
struct pthread_signal_frame *psf);
void _thread_start(void);
void _thread_seterrno(pthread_t, int);
-int _thread_fd_table_init(int fd);
pthread_addr_t _thread_gc(pthread_addr_t);
void _thread_enter_cancellation_point(void);
void _thread_leave_cancellation_point(void);
diff --git a/lib/libc_r/uthread/uthread_accept.c b/lib/libc_r/uthread/uthread_accept.c
index e04b97bc54176..8f903367331b0 100644
--- a/lib/libc_r/uthread/uthread_accept.c
+++ b/lib/libc_r/uthread/uthread_accept.c
@@ -52,7 +52,8 @@ _accept(int fd, struct sockaddr * name, socklen_t *namelen)
/* Enter a loop to wait for a connection request: */
while ((ret = __sys_accept(fd, name, namelen)) < 0) {
/* Check if the socket is to block: */
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) {
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0
+ && (errno == EWOULDBLOCK || errno == EAGAIN)) {
/* Save the socket file descriptor: */
curthread->data.fd.fd = fd;
curthread->data.fd.fname = __FILE__;
@@ -99,9 +100,9 @@ _accept(int fd, struct sockaddr * name, socklen_t *namelen)
* set the new socket flags to non-blocking, as that
* will be the inherited state of the new socket.
*/
- if((ret > 0) && (_thread_fd_table[fd]->flags & O_NONBLOCK) == 0)
- _thread_fd_table[ret]->flags &= ~O_NONBLOCK;
-
+ if((ret > 0) && (_thread_fd_getflags(fd) & O_NONBLOCK) == 0)
+ _thread_fd_setflags(ret,
+ _thread_fd_getflags(ret) & ~O_NONBLOCK);
/* Unlock the file descriptor: */
_FD_UNLOCK(fd, FD_RDWR);
}
diff --git a/lib/libc_r/uthread/uthread_close.c b/lib/libc_r/uthread/uthread_close.c
index 0a5bd24fa418b..22c939440ddc6 100644
--- a/lib/libc_r/uthread/uthread_close.c
+++ b/lib/libc_r/uthread/uthread_close.c
@@ -82,7 +82,8 @@ _close(int fd)
* using, which would then cause any reads to block
* indefinitely.
*/
- if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode)) && (_thread_fd_table[fd]->flags & O_NONBLOCK) == 0) {
+ if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode))
+ && (_thread_fd_getflags(fd) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(fd, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libc_r/uthread/uthread_connect.c b/lib/libc_r/uthread/uthread_connect.c
index 9612e1f20f4d6..a3fe75f26ef91 100644
--- a/lib/libc_r/uthread/uthread_connect.c
+++ b/lib/libc_r/uthread/uthread_connect.c
@@ -49,9 +49,9 @@ _connect(int fd, const struct sockaddr * name, socklen_t namelen)
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
if ((ret = __sys_connect(fd, name, namelen)) < 0) {
- if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) &&
- ((errno == EWOULDBLOCK) || (errno == EINPROGRESS) ||
- (errno == EALREADY) || (errno == EAGAIN))) {
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0
+ && ((errno == EWOULDBLOCK) || (errno == EINPROGRESS)
+ || (errno == EALREADY) || (errno == EAGAIN))) {
curthread->data.fd.fd = fd;
/* Set the timeout: */
diff --git a/lib/libc_r/uthread/uthread_dup.c b/lib/libc_r/uthread/uthread_dup.c
index 9fc2e583223ee..aaae6914679d3 100644
--- a/lib/libc_r/uthread/uthread_dup.c
+++ b/lib/libc_r/uthread/uthread_dup.c
@@ -59,7 +59,7 @@ _dup(int fd)
* Save the file open flags so that they can be
* checked later:
*/
- _thread_fd_table[ret]->flags = _thread_fd_table[fd]->flags;
+ _thread_fd_setflags(ret, _thread_fd_getflags(fd));
}
/* Unlock the file descriptor: */
diff --git a/lib/libc_r/uthread/uthread_dup2.c b/lib/libc_r/uthread/uthread_dup2.c
index d8cead7f3c62f..739a7ad897dbe 100644
--- a/lib/libc_r/uthread/uthread_dup2.c
+++ b/lib/libc_r/uthread/uthread_dup2.c
@@ -81,8 +81,8 @@ _dup2(int fd, int newfd)
* Save the file open flags so that
* they can be checked later:
*/
- _thread_fd_table[ret]->flags =
- _thread_fd_table[fd]->flags;
+ _thread_fd_setflags(ret,
+ _thread_fd_getflags(fd));
}
}
diff --git a/lib/libc_r/uthread/uthread_execve.c b/lib/libc_r/uthread/uthread_execve.c
index 082814d3087cf..612f9039a2edc 100644
--- a/lib/libc_r/uthread/uthread_execve.c
+++ b/lib/libc_r/uthread/uthread_execve.c
@@ -68,7 +68,7 @@ _execve(const char *name, char *const * argv, char *const * envp)
for (i = 0; i < _thread_dtablesize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
- !(_thread_fd_table[i]->flags & O_NONBLOCK)) {
+ (_thread_fd_getflags(i) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(i, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libc_r/uthread/uthread_exit.c b/lib/libc_r/uthread/uthread_exit.c
index fd90e29590773..8af1c1f90da75 100644
--- a/lib/libc_r/uthread/uthread_exit.c
+++ b/lib/libc_r/uthread/uthread_exit.c
@@ -69,7 +69,7 @@ void _exit(int status)
for (i = 0; i < _thread_dtablesize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
- !(_thread_fd_table[i]->flags & O_NONBLOCK)) {
+ (_thread_fd_getflags(i) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(i, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libc_r/uthread/uthread_fcntl.c b/lib/libc_r/uthread/uthread_fcntl.c
index 1d12c0e185b88..a5b64054f6ef3 100644
--- a/lib/libc_r/uthread/uthread_fcntl.c
+++ b/lib/libc_r/uthread/uthread_fcntl.c
@@ -76,9 +76,10 @@ _fcntl(int fd, int cmd,...)
} else {
/*
* Save the file open flags so that they can
- * be checked later:
+ * be checked later:
*/
- _thread_fd_table[ret]->flags = _thread_fd_table[fd]->flags;
+ _thread_fd_setflags(ret,
+ _thread_fd_getflags(fd));
}
break;
case F_SETFD:
@@ -89,7 +90,7 @@ _fcntl(int fd, int cmd,...)
ret = __sys_fcntl(fd, cmd, 0);
break;
case F_GETFL:
- ret = _thread_fd_table[fd]->flags;
+ ret = _thread_fd_getflags(fd);
break;
case F_SETFL:
/*
@@ -119,10 +120,10 @@ _fcntl(int fd, int cmd,...)
*/
} else if (nonblock)
/* A non-blocking descriptor: */
- _thread_fd_table[fd]->flags = flags | O_NONBLOCK;
+ _thread_fd_setflags(fd, flags | O_NONBLOCK);
else
/* Save the flags: */
- _thread_fd_table[fd]->flags = flags & ~O_NONBLOCK;
+ _thread_fd_setflags(fd, flags & ~O_NONBLOCK);
break;
default:
/* Might want to make va_arg use a union */
diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c
index 060515ab50bd9..7b8bb717ab67b 100644
--- a/lib/libc_r/uthread/uthread_fd.c
+++ b/lib/libc_r/uthread/uthread_fd.c
@@ -182,6 +182,22 @@ _thread_fd_table_init(int fd)
return (ret);
}
+int
+_thread_fd_getflags(int fd)
+{
+ if (_thread_fd_table[fd] != NULL)
+ return (_thread_fd_table[fd]->flags);
+ else
+ return (0);
+}
+
+void
+_thread_fd_setflags(int fd, int flags)
+{
+ if (_thread_fd_table[fd] != NULL)
+ _thread_fd_table[fd]->flags = flags;
+}
+
#ifdef _FDLOCKS_ENABLED
void
_thread_fd_unlock(int fd, int lock_type)
diff --git a/lib/libc_r/uthread/uthread_ioctl.c b/lib/libc_r/uthread/uthread_ioctl.c
index 9c7889f97e760..7199372b6e18b 100644
--- a/lib/libc_r/uthread/uthread_ioctl.c
+++ b/lib/libc_r/uthread/uthread_ioctl.c
@@ -43,6 +43,7 @@ int
_ioctl(int fd, unsigned long request,...)
{
int ret;
+ int flags;
int *op;
va_list ap;
@@ -58,8 +59,12 @@ _ioctl(int fd, unsigned long request,...)
* twiddling the flag based on the request
*/
op = va_arg(ap, int *);
- _thread_fd_table[fd]->flags &= ~O_NONBLOCK;
- _thread_fd_table[fd]->flags |= ((*op) ? O_NONBLOCK : 0);
+ flags = _thread_fd_getflags(fd);
+ if (*op == 0)
+ flags &= ~O_NONBLOCK;
+ else
+ flags |= O_NONBLOCK;
+ _thread_fd_setflags(fd, flags);
ret = 0;
break;
default:
diff --git a/lib/libc_r/uthread/uthread_read.c b/lib/libc_r/uthread/uthread_read.c
index 4d814143492db..067befa0c1764 100644
--- a/lib/libc_r/uthread/uthread_read.c
+++ b/lib/libc_r/uthread/uthread_read.c
@@ -57,7 +57,7 @@ _read(int fd, void *buf, size_t nbytes)
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for read: */
if (type != O_RDONLY && type != O_RDWR) {
@@ -69,7 +69,7 @@ _read(int fd, void *buf, size_t nbytes)
/* Perform a non-blocking read syscall: */
while ((ret = __sys_read(fd, buf, nbytes)) < 0) {
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
diff --git a/lib/libc_r/uthread/uthread_readv.c b/lib/libc_r/uthread/uthread_readv.c
index 0aa6c15820c5d..e2b79d73696cc 100644
--- a/lib/libc_r/uthread/uthread_readv.c
+++ b/lib/libc_r/uthread/uthread_readv.c
@@ -52,7 +52,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for read: */
if (type != O_RDONLY && type != O_RDWR) {
@@ -64,7 +64,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
/* Perform a non-blocking readv syscall: */
while ((ret = __sys_readv(fd, iov, iovcnt)) < 0) {
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
diff --git a/lib/libc_r/uthread/uthread_recvfrom.c b/lib/libc_r/uthread/uthread_recvfrom.c
index 0643126752a8e..d6f8da1b99745 100644
--- a/lib/libc_r/uthread/uthread_recvfrom.c
+++ b/lib/libc_r/uthread/uthread_recvfrom.c
@@ -49,7 +49,8 @@ _recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from,
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
while ((ret = __sys_recvfrom(fd, buf, len, flags, from, from_len)) < 0) {
- if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
+ if (((_thread_fd_getflags(fd) & O_NONBLOCK) == 0)
+ && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
curthread->data.fd.fd = fd;
/* Set the timeout: */
diff --git a/lib/libc_r/uthread/uthread_recvmsg.c b/lib/libc_r/uthread/uthread_recvmsg.c
index f3932aa377ef3..cae23f39fdee1 100644
--- a/lib/libc_r/uthread/uthread_recvmsg.c
+++ b/lib/libc_r/uthread/uthread_recvmsg.c
@@ -48,7 +48,8 @@ _recvmsg(int fd, struct msghdr *msg, int flags)
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
while ((ret = __sys_recvmsg(fd, msg, flags)) < 0) {
- if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
+ if (((_thread_fd_getflags(fd) & O_NONBLOCK) == 0)
+ && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
curthread->data.fd.fd = fd;
/* Set the timeout: */
diff --git a/lib/libc_r/uthread/uthread_sendfile.c b/lib/libc_r/uthread/uthread_sendfile.c
index 81dcf63283c59..ddaddeb3ff1e8 100644
--- a/lib/libc_r/uthread/uthread_sendfile.c
+++ b/lib/libc_r/uthread/uthread_sendfile.c
@@ -83,14 +83,14 @@ _sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
}
/* Check the descriptor access modes. */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
if (type != O_RDONLY && type != O_RDWR) {
/* File is not open for read. */
ret = -1;
errno = EBADF;
goto ERROR_2;
}
- type = _thread_fd_table[s]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(s) & O_ACCMODE;
if (type != O_WRONLY && type != O_RDWR) {
/* File is not open for write. */
ret = -1;
@@ -99,7 +99,7 @@ _sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[s]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(s) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number of bytes are
diff --git a/lib/libc_r/uthread/uthread_sendmsg.c b/lib/libc_r/uthread/uthread_sendmsg.c
index 5a3476bb8fa74..46f85cb4e2172 100644
--- a/lib/libc_r/uthread/uthread_sendmsg.c
+++ b/lib/libc_r/uthread/uthread_sendmsg.c
@@ -48,7 +48,8 @@ _sendmsg(int fd, const struct msghdr *msg, int flags)
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
while ((ret = __sys_sendmsg(fd, msg, flags)) < 0) {
- if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
+ if (!(_thread_fd_getflags(fd) & O_NONBLOCK)
+ && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
curthread->data.fd.fd = fd;
/* Set the timeout: */
diff --git a/lib/libc_r/uthread/uthread_sendto.c b/lib/libc_r/uthread/uthread_sendto.c
index 97f871854cc90..7560ed0665530 100644
--- a/lib/libc_r/uthread/uthread_sendto.c
+++ b/lib/libc_r/uthread/uthread_sendto.c
@@ -49,7 +49,8 @@ _sendto(int fd, const void *msg, size_t len, int flags, const struct
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
while ((ret = __sys_sendto(fd, msg, len, flags, to, to_len)) < 0) {
- if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
+ if (((_thread_fd_getflags(fd) & O_NONBLOCK) == 0)
+ && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
curthread->data.fd.fd = fd;
/* Set the timeout: */
diff --git a/lib/libc_r/uthread/uthread_sig.c b/lib/libc_r/uthread/uthread_sig.c
index 7aa9b53967b32..cf319c694f5d3 100644
--- a/lib/libc_r/uthread/uthread_sig.c
+++ b/lib/libc_r/uthread/uthread_sig.c
@@ -536,7 +536,7 @@ thread_sig_handle_special(int sig)
* Set the file descriptor to non-blocking:
*/
__sys_fcntl(i, F_SETFL,
- _thread_fd_table[i]->flags | O_NONBLOCK);
+ _thread_fd_getflags(i) | O_NONBLOCK);
}
}
/*
diff --git a/lib/libc_r/uthread/uthread_write.c b/lib/libc_r/uthread/uthread_write.c
index e655a348c0763..072b989ee750e 100644
--- a/lib/libc_r/uthread/uthread_write.c
+++ b/lib/libc_r/uthread/uthread_write.c
@@ -59,7 +59,7 @@ _write(int fd, const void *buf, size_t nbytes)
/* Lock the file descriptor for write: */
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for write: */
if (type != O_WRONLY && type != O_RDWR) {
@@ -70,7 +70,7 @@ _write(int fd, const void *buf, size_t nbytes)
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number
diff --git a/lib/libc_r/uthread/uthread_writev.c b/lib/libc_r/uthread/uthread_writev.c
index ec77258f87bf3..b07278ac39b3a 100644
--- a/lib/libc_r/uthread/uthread_writev.c
+++ b/lib/libc_r/uthread/uthread_writev.c
@@ -75,7 +75,7 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
/* Lock the file descriptor for write: */
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for write: */
if (type != O_WRONLY && type != O_RDWR) {
@@ -86,7 +86,7 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number
diff --git a/lib/libkse/thread/thr_close.c b/lib/libkse/thread/thr_close.c
index 0a5bd24fa418b..22c939440ddc6 100644
--- a/lib/libkse/thread/thr_close.c
+++ b/lib/libkse/thread/thr_close.c
@@ -82,7 +82,8 @@ _close(int fd)
* using, which would then cause any reads to block
* indefinitely.
*/
- if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode)) && (_thread_fd_table[fd]->flags & O_NONBLOCK) == 0) {
+ if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode))
+ && (_thread_fd_getflags(fd) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(fd, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libkse/thread/thr_exit.c b/lib/libkse/thread/thr_exit.c
index fd90e29590773..8af1c1f90da75 100644
--- a/lib/libkse/thread/thr_exit.c
+++ b/lib/libkse/thread/thr_exit.c
@@ -69,7 +69,7 @@ void _exit(int status)
for (i = 0; i < _thread_dtablesize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
- !(_thread_fd_table[i]->flags & O_NONBLOCK)) {
+ (_thread_fd_getflags(i) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(i, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libkse/thread/thr_fcntl.c b/lib/libkse/thread/thr_fcntl.c
index 1d12c0e185b88..a5b64054f6ef3 100644
--- a/lib/libkse/thread/thr_fcntl.c
+++ b/lib/libkse/thread/thr_fcntl.c
@@ -76,9 +76,10 @@ _fcntl(int fd, int cmd,...)
} else {
/*
* Save the file open flags so that they can
- * be checked later:
+ * be checked later:
*/
- _thread_fd_table[ret]->flags = _thread_fd_table[fd]->flags;
+ _thread_fd_setflags(ret,
+ _thread_fd_getflags(fd));
}
break;
case F_SETFD:
@@ -89,7 +90,7 @@ _fcntl(int fd, int cmd,...)
ret = __sys_fcntl(fd, cmd, 0);
break;
case F_GETFL:
- ret = _thread_fd_table[fd]->flags;
+ ret = _thread_fd_getflags(fd);
break;
case F_SETFL:
/*
@@ -119,10 +120,10 @@ _fcntl(int fd, int cmd,...)
*/
} else if (nonblock)
/* A non-blocking descriptor: */
- _thread_fd_table[fd]->flags = flags | O_NONBLOCK;
+ _thread_fd_setflags(fd, flags | O_NONBLOCK);
else
/* Save the flags: */
- _thread_fd_table[fd]->flags = flags & ~O_NONBLOCK;
+ _thread_fd_setflags(fd, flags & ~O_NONBLOCK);
break;
default:
/* Might want to make va_arg use a union */
diff --git a/lib/libkse/thread/thr_private.h b/lib/libkse/thread/thr_private.h
index ef45706710f36..97b30b703092b 100644
--- a/lib/libkse/thread/thr_private.h
+++ b/lib/libkse/thread/thr_private.h
@@ -1140,8 +1140,6 @@ void _set_curthread(struct pthread *);
void *_thread_stack_alloc(size_t, size_t);
void _thread_stack_free(void *, size_t, size_t);
int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
-int _thread_fd_lock(int, int, struct timespec *);
-int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
int _mutex_cv_lock(pthread_mutex_t *);
int _mutex_cv_unlock(pthread_mutex_t *);
void _mutex_lock_backout(pthread_t);
@@ -1177,6 +1175,11 @@ void _waitq_clearactive(void);
#endif
void _thread_exit(char *, int, char *);
void _thread_exit_cleanup(void);
+int _thread_fd_getflags(int);
+int _thread_fd_lock(int, int, struct timespec *);
+int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
+void _thread_fd_setflags(int, int);
+int _thread_fd_table_init(int fd);
void _thread_fd_unlock(int, int);
void _thread_fd_unlock_debug(int, int, char *, int);
void _thread_fd_unlock_owned(pthread_t);
@@ -1203,7 +1206,6 @@ void _thread_sigframe_restore(struct pthread *thread,
struct pthread_signal_frame *psf);
void _thread_start(void);
void _thread_seterrno(pthread_t, int);
-int _thread_fd_table_init(int fd);
pthread_addr_t _thread_gc(pthread_addr_t);
void _thread_enter_cancellation_point(void);
void _thread_leave_cancellation_point(void);
diff --git a/lib/libkse/thread/thr_read.c b/lib/libkse/thread/thr_read.c
index 4d814143492db..067befa0c1764 100644
--- a/lib/libkse/thread/thr_read.c
+++ b/lib/libkse/thread/thr_read.c
@@ -57,7 +57,7 @@ _read(int fd, void *buf, size_t nbytes)
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for read: */
if (type != O_RDONLY && type != O_RDWR) {
@@ -69,7 +69,7 @@ _read(int fd, void *buf, size_t nbytes)
/* Perform a non-blocking read syscall: */
while ((ret = __sys_read(fd, buf, nbytes)) < 0) {
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
diff --git a/lib/libkse/thread/thr_readv.c b/lib/libkse/thread/thr_readv.c
index 0aa6c15820c5d..e2b79d73696cc 100644
--- a/lib/libkse/thread/thr_readv.c
+++ b/lib/libkse/thread/thr_readv.c
@@ -52,7 +52,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for read: */
if (type != O_RDONLY && type != O_RDWR) {
@@ -64,7 +64,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
/* Perform a non-blocking readv syscall: */
while ((ret = __sys_readv(fd, iov, iovcnt)) < 0) {
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
diff --git a/lib/libkse/thread/thr_sig.c b/lib/libkse/thread/thr_sig.c
index 7aa9b53967b32..cf319c694f5d3 100644
--- a/lib/libkse/thread/thr_sig.c
+++ b/lib/libkse/thread/thr_sig.c
@@ -536,7 +536,7 @@ thread_sig_handle_special(int sig)
* Set the file descriptor to non-blocking:
*/
__sys_fcntl(i, F_SETFL,
- _thread_fd_table[i]->flags | O_NONBLOCK);
+ _thread_fd_getflags(i) | O_NONBLOCK);
}
}
/*
diff --git a/lib/libkse/thread/thr_write.c b/lib/libkse/thread/thr_write.c
index e655a348c0763..072b989ee750e 100644
--- a/lib/libkse/thread/thr_write.c
+++ b/lib/libkse/thread/thr_write.c
@@ -59,7 +59,7 @@ _write(int fd, const void *buf, size_t nbytes)
/* Lock the file descriptor for write: */
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for write: */
if (type != O_WRONLY && type != O_RDWR) {
@@ -70,7 +70,7 @@ _write(int fd, const void *buf, size_t nbytes)
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number
diff --git a/lib/libkse/thread/thr_writev.c b/lib/libkse/thread/thr_writev.c
index ec77258f87bf3..b07278ac39b3a 100644
--- a/lib/libkse/thread/thr_writev.c
+++ b/lib/libkse/thread/thr_writev.c
@@ -75,7 +75,7 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
/* Lock the file descriptor for write: */
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for write: */
if (type != O_WRONLY && type != O_RDWR) {
@@ -86,7 +86,7 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number
diff --git a/lib/libpthread/thread/thr_close.c b/lib/libpthread/thread/thr_close.c
index 0a5bd24fa418b..22c939440ddc6 100644
--- a/lib/libpthread/thread/thr_close.c
+++ b/lib/libpthread/thread/thr_close.c
@@ -82,7 +82,8 @@ _close(int fd)
* using, which would then cause any reads to block
* indefinitely.
*/
- if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode)) && (_thread_fd_table[fd]->flags & O_NONBLOCK) == 0) {
+ if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode))
+ && (_thread_fd_getflags(fd) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(fd, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libpthread/thread/thr_exit.c b/lib/libpthread/thread/thr_exit.c
index fd90e29590773..8af1c1f90da75 100644
--- a/lib/libpthread/thread/thr_exit.c
+++ b/lib/libpthread/thread/thr_exit.c
@@ -69,7 +69,7 @@ void _exit(int status)
for (i = 0; i < _thread_dtablesize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
- !(_thread_fd_table[i]->flags & O_NONBLOCK)) {
+ (_thread_fd_getflags(i) & O_NONBLOCK) == 0) {
/* Get the current flags: */
flags = __sys_fcntl(i, F_GETFL, NULL);
/* Clear the nonblocking file descriptor flag: */
diff --git a/lib/libpthread/thread/thr_fcntl.c b/lib/libpthread/thread/thr_fcntl.c
index 1d12c0e185b88..a5b64054f6ef3 100644
--- a/lib/libpthread/thread/thr_fcntl.c
+++ b/lib/libpthread/thread/thr_fcntl.c
@@ -76,9 +76,10 @@ _fcntl(int fd, int cmd,...)
} else {
/*
* Save the file open flags so that they can
- * be checked later:
+ * be checked later:
*/
- _thread_fd_table[ret]->flags = _thread_fd_table[fd]->flags;
+ _thread_fd_setflags(ret,
+ _thread_fd_getflags(fd));
}
break;
case F_SETFD:
@@ -89,7 +90,7 @@ _fcntl(int fd, int cmd,...)
ret = __sys_fcntl(fd, cmd, 0);
break;
case F_GETFL:
- ret = _thread_fd_table[fd]->flags;
+ ret = _thread_fd_getflags(fd);
break;
case F_SETFL:
/*
@@ -119,10 +120,10 @@ _fcntl(int fd, int cmd,...)
*/
} else if (nonblock)
/* A non-blocking descriptor: */
- _thread_fd_table[fd]->flags = flags | O_NONBLOCK;
+ _thread_fd_setflags(fd, flags | O_NONBLOCK);
else
/* Save the flags: */
- _thread_fd_table[fd]->flags = flags & ~O_NONBLOCK;
+ _thread_fd_setflags(fd, flags & ~O_NONBLOCK);
break;
default:
/* Might want to make va_arg use a union */
diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h
index ef45706710f36..97b30b703092b 100644
--- a/lib/libpthread/thread/thr_private.h
+++ b/lib/libpthread/thread/thr_private.h
@@ -1140,8 +1140,6 @@ void _set_curthread(struct pthread *);
void *_thread_stack_alloc(size_t, size_t);
void _thread_stack_free(void *, size_t, size_t);
int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
-int _thread_fd_lock(int, int, struct timespec *);
-int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
int _mutex_cv_lock(pthread_mutex_t *);
int _mutex_cv_unlock(pthread_mutex_t *);
void _mutex_lock_backout(pthread_t);
@@ -1177,6 +1175,11 @@ void _waitq_clearactive(void);
#endif
void _thread_exit(char *, int, char *);
void _thread_exit_cleanup(void);
+int _thread_fd_getflags(int);
+int _thread_fd_lock(int, int, struct timespec *);
+int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
+void _thread_fd_setflags(int, int);
+int _thread_fd_table_init(int fd);
void _thread_fd_unlock(int, int);
void _thread_fd_unlock_debug(int, int, char *, int);
void _thread_fd_unlock_owned(pthread_t);
@@ -1203,7 +1206,6 @@ void _thread_sigframe_restore(struct pthread *thread,
struct pthread_signal_frame *psf);
void _thread_start(void);
void _thread_seterrno(pthread_t, int);
-int _thread_fd_table_init(int fd);
pthread_addr_t _thread_gc(pthread_addr_t);
void _thread_enter_cancellation_point(void);
void _thread_leave_cancellation_point(void);
diff --git a/lib/libpthread/thread/thr_read.c b/lib/libpthread/thread/thr_read.c
index 4d814143492db..067befa0c1764 100644
--- a/lib/libpthread/thread/thr_read.c
+++ b/lib/libpthread/thread/thr_read.c
@@ -57,7 +57,7 @@ _read(int fd, void *buf, size_t nbytes)
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for read: */
if (type != O_RDONLY && type != O_RDWR) {
@@ -69,7 +69,7 @@ _read(int fd, void *buf, size_t nbytes)
/* Perform a non-blocking read syscall: */
while ((ret = __sys_read(fd, buf, nbytes)) < 0) {
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
diff --git a/lib/libpthread/thread/thr_readv.c b/lib/libpthread/thread/thr_readv.c
index 0aa6c15820c5d..e2b79d73696cc 100644
--- a/lib/libpthread/thread/thr_readv.c
+++ b/lib/libpthread/thread/thr_readv.c
@@ -52,7 +52,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
/* Lock the file descriptor for read: */
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for read: */
if (type != O_RDONLY && type != O_RDWR) {
@@ -64,7 +64,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
/* Perform a non-blocking readv syscall: */
while ((ret = __sys_readv(fd, iov, iovcnt)) < 0) {
- if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
+ if ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
diff --git a/lib/libpthread/thread/thr_sig.c b/lib/libpthread/thread/thr_sig.c
index 7aa9b53967b32..cf319c694f5d3 100644
--- a/lib/libpthread/thread/thr_sig.c
+++ b/lib/libpthread/thread/thr_sig.c
@@ -536,7 +536,7 @@ thread_sig_handle_special(int sig)
* Set the file descriptor to non-blocking:
*/
__sys_fcntl(i, F_SETFL,
- _thread_fd_table[i]->flags | O_NONBLOCK);
+ _thread_fd_getflags(i) | O_NONBLOCK);
}
}
/*
diff --git a/lib/libpthread/thread/thr_write.c b/lib/libpthread/thread/thr_write.c
index e655a348c0763..072b989ee750e 100644
--- a/lib/libpthread/thread/thr_write.c
+++ b/lib/libpthread/thread/thr_write.c
@@ -59,7 +59,7 @@ _write(int fd, const void *buf, size_t nbytes)
/* Lock the file descriptor for write: */
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for write: */
if (type != O_WRONLY && type != O_RDWR) {
@@ -70,7 +70,7 @@ _write(int fd, const void *buf, size_t nbytes)
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number
diff --git a/lib/libpthread/thread/thr_writev.c b/lib/libpthread/thread/thr_writev.c
index ec77258f87bf3..b07278ac39b3a 100644
--- a/lib/libpthread/thread/thr_writev.c
+++ b/lib/libpthread/thread/thr_writev.c
@@ -75,7 +75,7 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
/* Lock the file descriptor for write: */
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
/* Get the read/write mode type: */
- type = _thread_fd_table[fd]->flags & O_ACCMODE;
+ type = _thread_fd_getflags(fd) & O_ACCMODE;
/* Check if the file is not open for write: */
if (type != O_WRONLY && type != O_RDWR) {
@@ -86,7 +86,7 @@ _writev(int fd, const struct iovec * iov, int iovcnt)
}
/* Check if file operations are to block */
- blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0);
+ blocking = ((_thread_fd_getflags(fd) & O_NONBLOCK) == 0);
/*
* Loop while no error occurs and until the expected number