diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2009-12-06 17:55:00 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2009-12-06 17:55:00 +0000 |
commit | a55f01c83e7912069ec9a626f7a96cd0f4d7d81e (patch) | |
tree | 61bf70dbc59d64e4a3cdeed81efc1480f0b56bae /lib/libpthread | |
parent | 7fb64f8c55eb07b0bee7925ab053db98f596eabd (diff) |
Make internal file descriptor handling async-signal safe by eliminating
the use of spinlocks and malloc. All needed memory is allocated upfront
and _thread_kern_sig_defer/undefer() is now used to protect critical
sections. okay guenther@
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/uthread/pthread_private.h | 13 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_close.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_dup2.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_fd.c | 139 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_fork.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_getpeername.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_getsockname.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_getsockopt.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_init.c | 7 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_setsockopt.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_shutdown.c | 6 |
11 files changed, 124 insertions, 83 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index 3f3a4933c57..324f6d20900 100644 --- a/lib/libpthread/uthread/pthread_private.h +++ b/lib/libpthread/uthread/pthread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread_private.h,v 1.72 2009/10/27 20:06:29 deraadt Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.73 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -505,9 +505,9 @@ enum pthread_state { * File status flags struture - shared for dup'ed fd's */ struct fs_flags { - spinlock_t lock; int flags; int refcnt; + SLIST_ENTRY(fs_flags) fe; /* free list entry. */ }; /* @@ -534,13 +534,6 @@ enum fd_entry_mode { * File descriptor table structure. */ struct fd_table_entry { - /* - * Lock for accesses to this file descriptor table - * entry. This is passed to _spinlock() to provide atomic - * access to this structure. It does *not* represent the - * state of the lock on the file descriptor. - */ - spinlock_t lock; _thread_list_t r_queue; /* Read queue. */ _thread_list_t w_queue; /* Write queue. */ struct pthread *r_owner; /* thread owning read lock. */ @@ -554,6 +547,7 @@ struct fd_table_entry { struct fs_flags *status_flags; /* Shared file status flags. */ enum fd_entry_state state; /* Open, closing, or closed. */ enum fd_entry_mode init_mode; /* The mode used for init. */ + SLIST_ENTRY(fd_table_entry) fe; /* Free list entry. */ }; struct pthread_poll_data { @@ -1176,6 +1170,7 @@ void _thread_start(void); void _thread_start_sig_handler(void); void _thread_seterrno(pthread_t,int); void _thread_fs_flags_replace(int, struct fs_flags *); +int _thread_fd_init_mem(void); void _thread_fd_init(void); int _thread_fd_table_init(int, enum fd_entry_mode, struct fs_flags *); void _thread_fd_entry_close(int); diff --git a/lib/libpthread/uthread/uthread_close.c b/lib/libpthread/uthread/uthread_close.c index 60232ec7d8c..fece136c9eb 100644 --- a/lib/libpthread/uthread/uthread_close.c +++ b/lib/libpthread/uthread/uthread_close.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_close.c,v 1.14 2007/04/27 12:59:24 kurt Exp $ */ +/* $OpenBSD: uthread_close.c,v 1.15 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -57,14 +57,14 @@ close(int fd) * _thread_sys_close() to stop races caused by the * fd state transition. */ - _SPINLOCK(&_thread_fd_table[fd]->lock); + _thread_kern_sig_defer(); _thread_fd_entry_close(fd); /* Close the file descriptor: */ ret = _thread_sys_close(fd); - _SPINUNLOCK(&_thread_fd_table[fd]->lock); + _thread_kern_sig_undefer(); _FD_UNLOCK(fd, FD_RDWR_CLOSE); } diff --git a/lib/libpthread/uthread/uthread_dup2.c b/lib/libpthread/uthread/uthread_dup2.c index f035a4609e2..e2b57df8c5e 100644 --- a/lib/libpthread/uthread/uthread_dup2.c +++ b/lib/libpthread/uthread/uthread_dup2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_dup2.c,v 1.12 2008/02/02 21:44:59 kurt Exp $ */ +/* $OpenBSD: uthread_dup2.c,v 1.13 2009/12/06 17:54:59 kurt Exp $ */ /* PUBLIC DOMAIN <marc@snafu.org> */ #include <errno.h> @@ -66,12 +66,12 @@ dup2(int fd, int newfd) */ if (ret == -1) { saved_errno = errno; - _SPINLOCK(&_thread_fd_table[newfd]->lock); + _thread_kern_sig_defer(); _thread_fd_entry_close(newfd); _thread_sys_close(newfd); - _SPINUNLOCK(&_thread_fd_table[newfd]->lock); + _thread_kern_sig_undefer(); errno = saved_errno ; } _FD_UNLOCK(newfd, FD_RDWR_CLOSE); diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c index 4de7371b4b5..45db8fb8167 100644 --- a/lib/libpthread/uthread/uthread_fd.c +++ b/lib/libpthread/uthread/uthread_fd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fd.c,v 1.31 2008/10/02 23:27:24 deraadt Exp $ */ +/* $OpenBSD: uthread_fd.c,v 1.32 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -43,7 +43,40 @@ #include "pthread_private.h" /* Static variables: */ -static spinlock_t fd_table_lock = _SPINLOCK_INITIALIZER; + +static struct fd_table_entry *_thread_fd_entries; +static struct fs_flags *_thread_fd_flags; + +static SLIST_HEAD(, fd_table_entry) _thread_fd_entries_head; +static SLIST_HEAD(, fs_flags) _thread_fd_flags_head; + +int +_thread_fd_init_mem(void) +{ + int fd; + + _thread_fd_entries = calloc((size_t)_thread_max_fdtsize, + sizeof(struct fd_table_entry)); + if (_thread_fd_entries == NULL) + return (-1); + + _thread_fd_flags = calloc((size_t)_thread_max_fdtsize, + sizeof(struct fs_flags)); + if (_thread_fd_flags == NULL) { + free(_thread_fd_entries); + _thread_fd_entries = NULL; + return (-1); + } + + /* add pre-allocated entries to freelists */ + for (fd = 0; fd < _thread_max_fdtsize; fd++) + { + SLIST_INSERT_HEAD(&_thread_fd_entries_head, &_thread_fd_entries[fd], fe); + SLIST_INSERT_HEAD(&_thread_fd_flags_head, &_thread_fd_flags[fd], fe); + } + + return (0); +} /* * Build a new fd entry and return it. @@ -53,14 +86,24 @@ _thread_fs_flags_entry(void) { struct fs_flags *entry; - entry = (struct fs_flags *) malloc(sizeof(struct fs_flags)); + _thread_kern_sig_defer(); + entry = SLIST_FIRST(&_thread_fd_flags_head); if (entry != NULL) { + SLIST_REMOVE_HEAD(&_thread_fd_flags_head, fe); memset(entry, 0, sizeof *entry); - _SPINLOCK_INIT(&entry->lock); } + _thread_kern_sig_undefer(); return entry; } +static void +_thread_fs_flags_free(struct fs_flags *entry) +{ + _thread_kern_sig_defer(); + SLIST_INSERT_HEAD(&_thread_fd_flags_head, entry, fe); + _thread_kern_sig_undefer(); +} + /* * Initialize a new status_flags entry and set system * file descriptor non-blocking. @@ -108,10 +151,10 @@ _thread_fs_flags_replace(int fd, struct fs_flags *new_status_flags) int flags; int saved_errno; + _thread_kern_sig_defer(); if (entry->status_flags != new_status_flags) { if (entry->status_flags != NULL) { old_status_flags = entry->status_flags; - _SPINLOCK(&old_status_flags->lock); old_status_flags->refcnt -= 1; if (old_status_flags->refcnt <= 0) { /* @@ -152,19 +195,17 @@ _thread_fs_flags_replace(int fd, struct fs_flags *new_status_flags) /* Clear the nonblocking file descriptor flag: */ _thread_sys_fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); } - free(old_status_flags); + _thread_fs_flags_free(old_status_flags); errno = saved_errno; - } else - _SPINUNLOCK(&old_status_flags->lock); + } } /* replace with new status flags */ if (new_status_flags != NULL) { - _SPINLOCK(&new_status_flags->lock); new_status_flags->refcnt += 1; - _SPINUNLOCK(&new_status_flags->lock); } entry->status_flags = new_status_flags; } + _thread_kern_sig_undefer(); } /* @@ -175,18 +216,28 @@ _thread_fd_entry(void) { struct fd_table_entry *entry; - entry = (struct fd_table_entry *) malloc(sizeof(struct fd_table_entry)); + _thread_kern_sig_defer(); + entry = SLIST_FIRST(&_thread_fd_entries_head); if (entry != NULL) { + SLIST_REMOVE_HEAD(&_thread_fd_entries_head, fe); memset(entry, 0, sizeof *entry); - _SPINLOCK_INIT(&entry->lock); TAILQ_INIT(&entry->r_queue); TAILQ_INIT(&entry->w_queue); entry->state = FD_ENTRY_CLOSED; entry->init_mode = FD_INIT_UNKNOWN; } + _thread_kern_sig_undefer(); return entry; } +static void +_thread_fs_entry_free(struct fd_table_entry *entry) +{ + _thread_kern_sig_defer(); + SLIST_INSERT_HEAD(&_thread_fd_entries_head, entry, fe); + _thread_kern_sig_undefer(); +} + /* * Initialize the thread fd table for dup-ed fds, typically the stdio * fds. @@ -203,6 +254,8 @@ _thread_fd_init(void) struct fd_table_entry *entry1, *entry2; struct fs_flags *status_flags; + _thread_fd_init_mem(); + saved_errno = errno; flags = calloc((size_t)_thread_init_fdtsize, sizeof *flags); if (flags == NULL) @@ -221,7 +274,7 @@ _thread_fd_init(void) * so the entries would never be cleaned. */ - _SPINLOCK(&fd_table_lock); + _thread_kern_sig_defer(); for (fd = 0; fd < _thread_init_fdtsize; fd += 1) { if (flags[fd] == -1) continue; @@ -256,14 +309,14 @@ _thread_fd_init(void) _thread_fd_table[fd] = entry1; flags[fd] |= O_NONBLOCK; } else { - free(entry1); - free(status_flags); + _thread_fs_entry_free(entry1); + _thread_fs_flags_free(status_flags); } } else { PANIC("Cannot allocate memory for flags table"); } } - _SPINUNLOCK(&fd_table_lock); + _thread_kern_sig_undefer(); /* lastly, restore the file flags. Flags for files that we know to be duped have been modified so set the non-blocking' @@ -309,8 +362,8 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta /* use _thread_fd_entry errno */ ret = -1; } else { - /* Lock the file descriptor table: */ - _SPINLOCK(&fd_table_lock); + /* Protect the file descriptor table: */ + _thread_kern_sig_defer(); /* * Check if another thread allocated the @@ -325,21 +378,21 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta entry = NULL; } - /* Unlock the file descriptor table: */ - _SPINUNLOCK(&fd_table_lock); + /* Unprotect the file descriptor table: */ + _thread_kern_sig_undefer(); /* * If another thread initialized the table entry * throw the new entry away. */ if (entry != NULL) - free(entry); + _thread_fs_entry_free(entry); } } if (ret == 0) { entry = _thread_fd_table[fd]; - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); switch (init_mode) { case FD_INIT_UNKNOWN: /* @@ -374,7 +427,7 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta } /* if flags init failed free new flags */ if (new_status_flags != NULL) - free(new_status_flags); + _thread_fs_flags_free(new_status_flags); } break; case FD_INIT_NEW: @@ -401,7 +454,7 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta } /* if flags init failed free new flags */ if (new_status_flags != NULL) - free(new_status_flags); + _thread_fs_flags_free(new_status_flags); } break; case FD_INIT_BLOCKING: @@ -433,7 +486,7 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta } /* if flags init failed free new flags */ if (new_status_flags != NULL) - free(new_status_flags); + _thread_fs_flags_free(new_status_flags); } else if (entry->state == FD_ENTRY_OPEN && entry->init_mode == FD_INIT_UNKNOWN) { entry->status_flags->flags &= ~O_NONBLOCK; @@ -471,7 +524,7 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta entry->init_mode = init_mode; break; } - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); } /* Return the completion status: */ @@ -512,13 +565,6 @@ _thread_fd_unlock(int fd, int lock_type) */ _thread_kern_sig_defer(); - /* - * Lock the file descriptor table entry to prevent - * other threads for clashing with the current - * thread's accesses: - */ - _SPINLOCK(&entry->lock); - /* Check if the running thread owns the read lock: */ if (entry->r_owner == thread && (lock_type & FD_READ)) { @@ -592,9 +638,6 @@ _thread_fd_unlock(int fd, int lock_type) } } - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&entry->lock); - /* * Undefer and handle pending signals, yielding if * necessary: @@ -622,11 +665,11 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) entry = _thread_fd_table[fd]; /* - * Lock the file descriptor table entry to prevent + * Protect the file descriptor table entry to prevent * other threads for clashing with the current * thread's accesses: */ - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); /* reject all new locks on entries that are closing */ if (entry->state == FD_ENTRY_CLOSING) { @@ -672,10 +715,10 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) _thread_kern_set_timeout(timeout); /* - * Unlock the file descriptor + * Unprotect the file descriptor * table entry: */ - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); /* * Schedule this thread to wait on @@ -690,10 +733,10 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) __LINE__); /* - * Lock the file descriptor + * Protect the file descriptor * table entry again: */ - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); } else { /* @@ -747,10 +790,10 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) _thread_kern_set_timeout(timeout); /* - * Unlock the file descriptor + * Unprotect the file descriptor * table entry: */ - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); /* * Schedule this thread to wait on @@ -765,10 +808,10 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) __LINE__); /* - * Lock the file descriptor + * Unprotect the file descriptor * table entry again: */ - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); } else { /* * The running thread now owns the @@ -788,8 +831,8 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) entry->w_lockcount++; } - /* Unlock the file descriptor table entry: */ - _SPINUNLOCK(&entry->lock); + /* Unprotect the file descriptor table entry: */ + _thread_kern_sig_undefer(); } /* Return the completion status: */ diff --git a/lib/libpthread/uthread/uthread_fork.c b/lib/libpthread/uthread/uthread_fork.c index 726b578e3af..e80f2b3a140 100644 --- a/lib/libpthread/uthread/uthread_fork.c +++ b/lib/libpthread/uthread/uthread_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fork.c,v 1.20 2009/10/21 15:32:01 guenther Exp $ */ +/* $OpenBSD: uthread_fork.c,v 1.21 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -203,7 +203,6 @@ _dofork(int vfork) for (i = 0; i < _thread_max_fdtsize; i++) { if (_thread_fd_table[i] != NULL) { /* Initialise the file locks: */ - _SPINLOCK_INIT(&_thread_fd_table[i]->lock); _thread_fd_table[i]->r_owner = NULL; _thread_fd_table[i]->w_owner = NULL; _thread_fd_table[i]->r_fname = NULL; @@ -212,8 +211,7 @@ _dofork(int vfork) _thread_fd_table[i]->w_lineno = 0; _thread_fd_table[i]->r_lockcount = 0; _thread_fd_table[i]->w_lockcount = 0; - if (_thread_fd_table[i]->status_flags != NULL) - _SPINLOCK_INIT(&_thread_fd_table[i]->status_flags->lock); + /* * If a fd was in the process of closing * then finish closing it. diff --git a/lib/libpthread/uthread/uthread_getpeername.c b/lib/libpthread/uthread/uthread_getpeername.c index 7a026a6885c..02ff6c83813 100644 --- a/lib/libpthread/uthread/uthread_getpeername.c +++ b/lib/libpthread/uthread/uthread_getpeername.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_getpeername.c,v 1.5 2008/06/03 14:45:05 kurt Exp $ */ +/* $OpenBSD: uthread_getpeername.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -49,14 +49,14 @@ getpeername(int fd, struct sockaddr * peer, socklen_t *paddrlen) if (ret == 0) { entry = _thread_fd_table[fd]; - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); if (entry->state == FD_ENTRY_OPEN) { ret = _thread_sys_getpeername(fd, peer, paddrlen); } else { ret = -1; errno = EBADF; } - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); } return ret; diff --git a/lib/libpthread/uthread/uthread_getsockname.c b/lib/libpthread/uthread/uthread_getsockname.c index 22ad8075c8e..2c634a69fbf 100644 --- a/lib/libpthread/uthread/uthread_getsockname.c +++ b/lib/libpthread/uthread/uthread_getsockname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_getsockname.c,v 1.5 2008/06/03 14:45:05 kurt Exp $ */ +/* $OpenBSD: uthread_getsockname.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -49,14 +49,14 @@ getsockname(int fd, struct sockaddr * name, socklen_t *namelen) if (ret == 0) { entry = _thread_fd_table[fd]; - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); if (entry->state == FD_ENTRY_OPEN) { ret = _thread_sys_getsockname(fd, name, namelen); } else { ret = -1; errno = EBADF; } - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); } return ret; diff --git a/lib/libpthread/uthread/uthread_getsockopt.c b/lib/libpthread/uthread/uthread_getsockopt.c index 09d31955652..3687c87958d 100644 --- a/lib/libpthread/uthread/uthread_getsockopt.c +++ b/lib/libpthread/uthread/uthread_getsockopt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_getsockopt.c,v 1.5 2008/06/03 14:45:05 kurt Exp $ */ +/* $OpenBSD: uthread_getsockopt.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -49,14 +49,14 @@ getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen) if (ret == 0) { entry = _thread_fd_table[fd]; - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); if (entry->state == FD_ENTRY_OPEN) { ret = _thread_sys_getsockopt(fd, level, optname, optval, optlen); } else { ret = -1; errno = EBADF; } - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); } return ret; diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c index c9b20880ad4..34aa110707b 100644 --- a/lib/libpthread/uthread/uthread_init.c +++ b/lib/libpthread/uthread/uthread_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_init.c,v 1.43 2008/12/18 09:30:32 guenther Exp $ */ +/* $OpenBSD: uthread_init.c,v 1.44 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -369,6 +369,11 @@ _thread_init(void) PANIC("Cannot allocate memory for file descriptor table"); } + if (_thread_fd_init_mem()) { + _thread_max_fdtsize = 0; + PANIC("Cannot allocate memory for file descriptor table"); + } + /* Allocate memory for the pollfd table: */ _thread_pfd_table = calloc((size_t)_thread_max_pfdtsize, sizeof(struct pollfd)); if (_thread_pfd_table == NULL) diff --git a/lib/libpthread/uthread/uthread_setsockopt.c b/lib/libpthread/uthread/uthread_setsockopt.c index bf6041985be..b453b8bef11 100644 --- a/lib/libpthread/uthread/uthread_setsockopt.c +++ b/lib/libpthread/uthread/uthread_setsockopt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_setsockopt.c,v 1.5 2008/06/03 14:45:05 kurt Exp $ */ +/* $OpenBSD: uthread_setsockopt.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -49,14 +49,14 @@ setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) if (ret == 0) { entry = _thread_fd_table[fd]; - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); if (entry->state == FD_ENTRY_OPEN) { ret = _thread_sys_setsockopt(fd, level, optname, optval, optlen); } else { ret = -1; errno = EBADF; } - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); } return ret; diff --git a/lib/libpthread/uthread/uthread_shutdown.c b/lib/libpthread/uthread/uthread_shutdown.c index e8f3e776afb..dcb7e38c42c 100644 --- a/lib/libpthread/uthread/uthread_shutdown.c +++ b/lib/libpthread/uthread/uthread_shutdown.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_shutdown.c,v 1.5 2006/10/17 20:57:28 kurt Exp $ */ +/* $OpenBSD: uthread_shutdown.c,v 1.6 2009/12/06 17:54:59 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -49,14 +49,14 @@ shutdown(int fd, int how) if (ret == 0) { entry = _thread_fd_table[fd]; - _SPINLOCK(&entry->lock); + _thread_kern_sig_defer(); if (entry->state == FD_ENTRY_OPEN) { ret = _thread_sys_shutdown(fd, how); } else { ret = -1; errno = EBADF; } - _SPINUNLOCK(&entry->lock); + _thread_kern_sig_undefer(); } return (ret); |