Add weak definitions for wrapped system calls. In general:
_foo - wrapped system call foo - weak definition to _foo and for cancellation points: _foo - wrapped system call __foo - enter cancellation point, call _foo(), leave cancellation point foo - weak definition to __foo Change use of global _thread_run to call a function to get the currently running thread. Make all pthread_foo functions weak definitions to _pthread_foo, where _pthread_foo is the implementation. This allows an application to provide its own pthread functions. Provide slightly different versions of pthread_mutex_lock and pthread_mutex_init so that we can tell the difference between a libc mutex and an application mutex. Threads holding mutexes internal to libc should never be allowed to exit, call signal handlers, or cancel. Approved by: -arch
This commit is contained in:
parent
06b2be66d9
commit
01750324fa
@ -22,23 +22,6 @@ CFLAGS+=-D_PTHREADS_INVARIANTS
|
||||
AINC= -I${.CURDIR}/../libc/${MACHINE_ARCH} -I${.CURDIR}/uthread
|
||||
PRECIOUSLIB= yes
|
||||
|
||||
#
|
||||
# This is a list of syscalls that are renamed as _thread_sys_{syscall}
|
||||
# so that libc_r can provide replacement functions.
|
||||
#
|
||||
HIDDEN_SYSCALLS= aio_suspend.o accept.o bind.o close.o connect.o dup.o dup2.o \
|
||||
execve.o fchflags.o fchmod.o fchown.o fcntl.o \
|
||||
flock.o fpathconf.o fstat.o fstatfs.o fsync.o getdirentries.o \
|
||||
getlogin.o getpeername.o getsockname.o getsockopt.o ioctl.o \
|
||||
kevent.o listen.o \
|
||||
msync.o nanosleep.o nfssvc.o open.o poll.o read.o readv.o recvfrom.o \
|
||||
recvmsg.o sched_yield.o select.o sendfile.o sendmsg.o sendto.o \
|
||||
setsockopt.o shutdown.o sigaction.o sigaltstack.o \
|
||||
signanosleep.o sigpending.o sigprocmask.o sigreturn.o sigsetmask.o \
|
||||
sigsuspend.o socket.o \
|
||||
socketpair.o wait4.o write.o writev.o
|
||||
|
||||
.include "${.CURDIR}/../libc/Makefile.inc"
|
||||
.include "${.CURDIR}/man/Makefile.inc"
|
||||
.include "${.CURDIR}/uthread/Makefile.inc"
|
||||
.include "${.CURDIR}/sys/Makefile.inc"
|
||||
|
@ -313,6 +313,9 @@ struct pthread_mutex_attr {
|
||||
long m_flags;
|
||||
};
|
||||
|
||||
#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
|
||||
{ PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
|
||||
|
||||
/*
|
||||
* Condition variable definitions.
|
||||
*/
|
||||
@ -1207,6 +1210,8 @@ int _find_dead_thread(pthread_t);
|
||||
int _find_thread(pthread_t);
|
||||
void _flockfile_backout(pthread_t);
|
||||
void _funlock_owned(pthread_t);
|
||||
struct pthread *_get_curthread(void);
|
||||
void _set_curthread(struct pthread *);
|
||||
void _join_backout(pthread_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 *);
|
||||
@ -1224,6 +1229,19 @@ void _pq_remove(struct pq_queue *pq, struct pthread *);
|
||||
void _pq_insert_head(struct pq_queue *pq, struct pthread *);
|
||||
void _pq_insert_tail(struct pq_queue *pq, struct pthread *);
|
||||
struct pthread *_pq_first(struct pq_queue *pq);
|
||||
void *_pthread_getspecific(pthread_key_t);
|
||||
int _pthread_key_create(pthread_key_t *, void (*) (void *));
|
||||
int _pthread_key_delete(pthread_key_t);
|
||||
int _pthread_mutex_destroy(pthread_mutex_t *);
|
||||
int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
|
||||
int _pthread_mutex_lock(pthread_mutex_t *);
|
||||
int _pthread_mutex_trylock(pthread_mutex_t *);
|
||||
int _pthread_mutex_unlock(pthread_mutex_t *);
|
||||
int _pthread_mutexattr_init(pthread_mutexattr_t *);
|
||||
int _pthread_mutexattr_destroy(pthread_mutexattr_t *);
|
||||
int _pthread_mutexattr_settype(pthread_mutexattr_t *, int);
|
||||
int _pthread_once(pthread_once_t *, void (*) (void));
|
||||
int _pthread_setspecific(pthread_key_t, const void *);
|
||||
void _waitq_insert(pthread_t pthread);
|
||||
void _waitq_remove(pthread_t pthread);
|
||||
#if defined(_PTHREADS_INVARIANTS)
|
||||
@ -1263,190 +1281,113 @@ void _thread_enter_cancellation_point(void);
|
||||
void _thread_leave_cancellation_point(void);
|
||||
void _thread_cancellation_point(void);
|
||||
|
||||
/* #include <aio.h> */
|
||||
#ifdef _AIO_H_
|
||||
int __sys_aio_suspend(const struct aiocb **, int, const struct timespec);
|
||||
#endif
|
||||
|
||||
/* #include <signal.h> */
|
||||
int _thread_sys_sigaction(int, const struct sigaction *, struct sigaction *);
|
||||
int _thread_sys_sigpending(sigset_t *);
|
||||
int _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *);
|
||||
int _thread_sys_sigsuspend(const sigset_t *);
|
||||
int _thread_sys_siginterrupt(int, int);
|
||||
int _thread_sys_sigpause(int);
|
||||
int _thread_sys_sigreturn(ucontext_t *);
|
||||
int _thread_sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
|
||||
int _thread_sys_sigstack(const struct sigstack *, struct sigstack *);
|
||||
int _thread_sys_sigvec(int, struct sigvec *, struct sigvec *);
|
||||
void _thread_sys_psignal(unsigned int, const char *);
|
||||
void (*_thread_sys_signal(int, void (*)(int)))(int);
|
||||
#ifdef _SIGNAL_H_
|
||||
int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
|
||||
int __sys_sigpending(sigset_t *);
|
||||
int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
|
||||
int __sys_sigsuspend(const sigset_t *);
|
||||
int __sys_sigreturn(ucontext_t *);
|
||||
int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
|
||||
#endif
|
||||
|
||||
/* #include <sys/stat.h> */
|
||||
#ifdef _SYS_STAT_H_
|
||||
int _thread_sys_fchmod(int, mode_t);
|
||||
int _thread_sys_fstat(int, struct stat *);
|
||||
int _thread_sys_fchflags(int, u_long);
|
||||
int __sys_fchmod(int, mode_t);
|
||||
int __sys_fstat(int, struct stat *);
|
||||
int __sys_fchflags(int, u_long);
|
||||
#endif
|
||||
|
||||
/* #include <sys/mount.h> */
|
||||
#ifdef _SYS_MOUNT_H_
|
||||
int _thread_sys_fstatfs(int, struct statfs *);
|
||||
int __sys_fstatfs(int, struct statfs *);
|
||||
#endif
|
||||
|
||||
/* #inclde <sys/event.h> */
|
||||
#ifdef _SYS_EVENT_H_
|
||||
int __sys_kevent(int, const struct kevent *, int, struct kevent *,
|
||||
int, const struct timespec *);
|
||||
#endif
|
||||
int _thread_sys_pipe(int *);
|
||||
|
||||
/* #include <sys/socket.h> */
|
||||
#ifdef _SYS_SOCKET_H_
|
||||
int _thread_sys_accept(int, struct sockaddr *, int *);
|
||||
int _thread_sys_bind(int, const struct sockaddr *, int);
|
||||
int _thread_sys_connect(int, const struct sockaddr *, int);
|
||||
int _thread_sys_getpeername(int, struct sockaddr *, int *);
|
||||
int _thread_sys_getsockname(int, struct sockaddr *, int *);
|
||||
int _thread_sys_getsockopt(int, int, int, void *, int *);
|
||||
int _thread_sys_listen(int, int);
|
||||
int _thread_sys_setsockopt(int, int, int, const void *, int);
|
||||
int _thread_sys_shutdown(int, int);
|
||||
int _thread_sys_socket(int, int, int);
|
||||
int _thread_sys_socketpair(int, int, int, int *);
|
||||
ssize_t _thread_sys_recv(int, void *, size_t, int);
|
||||
ssize_t _thread_sys_recvfrom(int, void *, size_t, int, struct sockaddr *, int *);
|
||||
ssize_t _thread_sys_recvmsg(int, struct msghdr *, int);
|
||||
ssize_t _thread_sys_send(int, const void *, size_t, int);
|
||||
ssize_t _thread_sys_sendmsg(int, const struct msghdr *, int);
|
||||
ssize_t _thread_sys_sendto(int, const void *,size_t, int, const struct sockaddr *, int);
|
||||
#endif
|
||||
|
||||
/* #include <stdio.h> */
|
||||
#ifdef _STDIO_H_
|
||||
FILE *_thread_sys_fdopen(int, const char *);
|
||||
FILE *_thread_sys_fopen(const char *, const char *);
|
||||
FILE *_thread_sys_freopen(const char *, const char *, FILE *);
|
||||
FILE *_thread_sys_popen(const char *, const char *);
|
||||
FILE *_thread_sys_tmpfile(void);
|
||||
char *_thread_sys_ctermid(char *);
|
||||
char *_thread_sys_cuserid(char *);
|
||||
char *_thread_sys_fgetln(FILE *, size_t *);
|
||||
char *_thread_sys_fgets(char *, int, FILE *);
|
||||
char *_thread_sys_gets(char *);
|
||||
char *_thread_sys_tempnam(const char *, const char *);
|
||||
char *_thread_sys_tmpnam(char *);
|
||||
int _thread_sys_fclose(FILE *);
|
||||
int _thread_sys_feof(FILE *);
|
||||
int _thread_sys_ferror(FILE *);
|
||||
int _thread_sys_fflush(FILE *);
|
||||
int _thread_sys_fgetc(FILE *);
|
||||
int _thread_sys_fgetpos(FILE *, fpos_t *);
|
||||
int _thread_sys_fileno(FILE *);
|
||||
int _thread_sys_fprintf(FILE *, const char *, ...);
|
||||
int _thread_sys_fpurge(FILE *);
|
||||
int _thread_sys_fputc(int, FILE *);
|
||||
int _thread_sys_fputs(const char *, FILE *);
|
||||
int _thread_sys_fscanf(FILE *, const char *, ...);
|
||||
int _thread_sys_fseek(FILE *, long, int);
|
||||
int _thread_sys_fsetpos(FILE *, const fpos_t *);
|
||||
int _thread_sys_getc(FILE *);
|
||||
int _thread_sys_getchar(void);
|
||||
int _thread_sys_getw(FILE *);
|
||||
int _thread_sys_pclose(FILE *);
|
||||
int _thread_sys_printf(const char *, ...);
|
||||
int _thread_sys_putc(int, FILE *);
|
||||
int _thread_sys_putchar(int);
|
||||
int _thread_sys_puts(const char *);
|
||||
int _thread_sys_putw(int, FILE *);
|
||||
int _thread_sys_remove(const char *);
|
||||
int _thread_sys_rename (const char *, const char *);
|
||||
int _thread_sys_scanf(const char *, ...);
|
||||
int _thread_sys_setlinebuf(FILE *);
|
||||
int _thread_sys_setvbuf(FILE *, char *, int, size_t);
|
||||
int _thread_sys_snprintf(char *, size_t, const char *, ...);
|
||||
int _thread_sys_sprintf(char *, const char *, ...);
|
||||
int _thread_sys_sscanf(const char *, const char *, ...);
|
||||
int _thread_sys_ungetc(int, FILE *);
|
||||
int _thread_sys_vfprintf(FILE *, const char *, _BSD_VA_LIST_);
|
||||
int _thread_sys_vprintf(const char *, _BSD_VA_LIST_);
|
||||
int _thread_sys_vscanf(const char *, _BSD_VA_LIST_);
|
||||
int _thread_sys_vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_);
|
||||
int _thread_sys_vsprintf(char *, const char *, _BSD_VA_LIST_);
|
||||
int _thread_sys_vsscanf(const char *, const char *, _BSD_VA_LIST_);
|
||||
long _thread_sys_ftell(FILE *);
|
||||
size_t _thread_sys_fread(void *, size_t, size_t, FILE *);
|
||||
size_t _thread_sys_fwrite(const void *, size_t, size_t, FILE *);
|
||||
void _thread_sys_clearerr(FILE *);
|
||||
void _thread_sys_perror(const char *);
|
||||
void _thread_sys_rewind(FILE *);
|
||||
void _thread_sys_setbuf(FILE *, char *);
|
||||
void _thread_sys_setbuffer(FILE *, char *, int);
|
||||
int __sys_accept(int, struct sockaddr *, int *);
|
||||
int __sys_bind(int, const struct sockaddr *, int);
|
||||
int __sys_connect(int, const struct sockaddr *, int);
|
||||
int __sys_getpeername(int, struct sockaddr *, int *);
|
||||
int __sys_getsockname(int, struct sockaddr *, int *);
|
||||
int __sys_getsockopt(int, int, int, void *, int *);
|
||||
int __sys_listen(int, int);
|
||||
int __sys_setsockopt(int, int, int, const void *, int);
|
||||
int __sys_shutdown(int, int);
|
||||
int __sys_socket(int, int, int);
|
||||
int __sys_socketpair(int, int, int, int *);
|
||||
ssize_t __sys_recvfrom(int, void *, size_t, int, struct sockaddr *, int *);
|
||||
ssize_t __sys_recvmsg(int, struct msghdr *, int);
|
||||
ssize_t __sys_send(int, const void *, size_t, int);
|
||||
int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
|
||||
ssize_t __sys_sendmsg(int, const struct msghdr *, int);
|
||||
ssize_t __sys_sendto(int, const void *,size_t, int, const struct sockaddr *, int);
|
||||
#endif
|
||||
|
||||
/* #include <unistd.h> */
|
||||
#ifdef _UNISTD_H_
|
||||
char *_thread_sys_ttyname(int);
|
||||
int _thread_sys_close(int);
|
||||
int _thread_sys_dup(int);
|
||||
int _thread_sys_dup2(int, int);
|
||||
int _thread_sys_exect(const char *, char * const *, char * const *);
|
||||
int _thread_sys_execve(const char *, char * const *, char * const *);
|
||||
int _thread_sys_fchdir(int);
|
||||
int _thread_sys_fchown(int, uid_t, gid_t);
|
||||
int _thread_sys_fsync(int);
|
||||
int _thread_sys_ftruncate(int, off_t);
|
||||
int _thread_sys_pause(void);
|
||||
int _thread_sys_pipe(int *);
|
||||
int _thread_sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
|
||||
long _thread_sys_fpathconf(int, int);
|
||||
off_t _thread_sys_lseek(int, off_t, int);
|
||||
pid_t _thread_sys_fork(void);
|
||||
pid_t _thread_sys_tcgetpgrp(int);
|
||||
ssize_t _thread_sys_read(int, void *, size_t);
|
||||
ssize_t _thread_sys_write(int, const void *, size_t);
|
||||
void _thread_sys__exit(int);
|
||||
int __sys_close(int);
|
||||
int __sys_dup(int);
|
||||
int __sys_dup2(int, int);
|
||||
int __sys_execve(const char *, char * const *, char * const *);
|
||||
int __sys_fchown(int, uid_t, gid_t);
|
||||
int __sys_fork(void);
|
||||
int __sys_fsync(int);
|
||||
int __sys_pipe(int *);
|
||||
int __sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
|
||||
long __sys_fpathconf(int, int);
|
||||
ssize_t __sys_read(int, void *, size_t);
|
||||
ssize_t __sys_write(int, const void *, size_t);
|
||||
void __sys__exit(int);
|
||||
#endif
|
||||
|
||||
/* #include <fcntl.h> */
|
||||
#ifdef _SYS_FCNTL_H_
|
||||
int _thread_sys_creat(const char *, mode_t);
|
||||
int _thread_sys_fcntl(int, int, ...);
|
||||
int _thread_sys_flock(int, int);
|
||||
int _thread_sys_open(const char *, int, ...);
|
||||
int __sys_fcntl(int, int, ...);
|
||||
int __sys_flock(int, int);
|
||||
int __sys_open(const char *, int, ...);
|
||||
#endif
|
||||
|
||||
/* #include <sys/ioctl.h> */
|
||||
#ifdef _SYS_IOCTL_H_
|
||||
int _thread_sys_ioctl(int, unsigned long, ...);
|
||||
int __sys_ioctl(int, unsigned long, ...);
|
||||
#endif
|
||||
|
||||
/* #include <dirent.h> */
|
||||
#ifdef _DIRENT_H_
|
||||
DIR *___thread_sys_opendir2(const char *, int);
|
||||
DIR *_thread_sys_opendir(const char *);
|
||||
int _thread_sys_alphasort(const void *, const void *);
|
||||
int _thread_sys_scandir(const char *, struct dirent ***,
|
||||
int (*)(struct dirent *), int (*)(const void *, const void *));
|
||||
int _thread_sys_closedir(DIR *);
|
||||
int _thread_sys_getdirentries(int, char *, int, long *);
|
||||
long _thread_sys_telldir(const DIR *);
|
||||
struct dirent *_thread_sys_readdir(DIR *);
|
||||
void _thread_sys_rewinddir(DIR *);
|
||||
void _thread_sys_seekdir(DIR *, long);
|
||||
int __sys_getdirentries(int, char *, int, long *);
|
||||
#endif
|
||||
|
||||
/* #include <sys/uio.h> */
|
||||
#ifdef _SYS_UIO_H_
|
||||
ssize_t _thread_sys_readv(int, const struct iovec *, int);
|
||||
ssize_t _thread_sys_writev(int, const struct iovec *, int);
|
||||
ssize_t __sys_readv(int, const struct iovec *, int);
|
||||
ssize_t __sys_writev(int, const struct iovec *, int);
|
||||
#endif
|
||||
|
||||
/* #include <sys/wait.h> */
|
||||
#ifdef WNOHANG
|
||||
pid_t _thread_sys_wait(int *);
|
||||
pid_t _thread_sys_waitpid(pid_t, int *, int);
|
||||
pid_t _thread_sys_wait3(int *, int, struct rusage *);
|
||||
pid_t _thread_sys_wait4(pid_t, int *, int, struct rusage *);
|
||||
pid_t __sys_wait4(pid_t, int *, int, struct rusage *);
|
||||
#endif
|
||||
|
||||
/* #include <poll.h> */
|
||||
#ifdef _SYS_POLL_H_
|
||||
int _thread_sys_poll(struct pollfd *, unsigned, int);
|
||||
int __sys_poll(struct pollfd *, unsigned, int);
|
||||
#endif
|
||||
|
||||
/* #include <sys/mman.h> */
|
||||
#ifdef _SYS_MMAN_H_
|
||||
int _thread_sys_msync(void *, size_t, int);
|
||||
int __sys_msync(void *, size_t, int);
|
||||
#endif
|
||||
|
||||
/* #include <setjmp.h> */
|
||||
|
@ -36,35 +36,37 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak accept=_accept
|
||||
|
||||
int
|
||||
_accept(int fd, struct sockaddr * name, socklen_t *namelen)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
/* Lock the file descriptor: */
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
/* Enter a loop to wait for a connection request: */
|
||||
while ((ret = _thread_sys_accept(fd, name, namelen)) < 0) {
|
||||
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)) {
|
||||
/* Save the socket file descriptor: */
|
||||
_thread_run->data.fd.fd = fd;
|
||||
_thread_run->data.fd.fname = __FILE__;
|
||||
_thread_run->data.fd.branch = __LINE__;
|
||||
curthread->data.fd.fd = fd;
|
||||
curthread->data.fd.fname = __FILE__;
|
||||
curthread->data.fd.branch = __LINE__;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(NULL);
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/* Schedule the next thread: */
|
||||
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
|
||||
|
||||
/* Check if the wait was interrupted: */
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
/* Return an error status: */
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
@ -85,7 +87,7 @@ _accept(int fd, struct sockaddr * name, socklen_t *namelen)
|
||||
/* Initialise the file descriptor table for the new socket: */
|
||||
else if (_thread_fd_table_init(ret) != 0) {
|
||||
/* Quietly close the socket: */
|
||||
_thread_sys_close(ret);
|
||||
__sys_close(ret);
|
||||
|
||||
/* Return an error: */
|
||||
ret = -1;
|
||||
@ -106,6 +108,3 @@ _accept(int fd, struct sockaddr * name, socklen_t *namelen)
|
||||
/* Return the socket file descriptor or -1 on error: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_accept, accept);
|
||||
#endif
|
||||
|
@ -30,10 +30,11 @@
|
||||
*/
|
||||
|
||||
#include <aio.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak aio_suspend=_aio_suspend
|
||||
|
||||
int
|
||||
_aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
|
||||
timespec *timeout)
|
||||
@ -41,11 +42,9 @@ _aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
|
||||
int ret;
|
||||
|
||||
_thread_enter_cancellation_point();
|
||||
ret = _aio_suspend(iocbs, niocb, timeout);
|
||||
ret = __sys_aio_suspend(iocbs, niocb, timeout);
|
||||
_thread_leave_cancellation_point();
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_reference(_aio_suspend, aio_suspend);
|
||||
#endif
|
||||
|
@ -33,11 +33,13 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
int pthread_attr_destroy(pthread_attr_t *attr)
|
||||
#pragma weak pthread_attr_destroy=_pthread_attr_destroy
|
||||
|
||||
int
|
||||
_pthread_attr_destroy(pthread_attr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -58,4 +60,3 @@ int pthread_attr_destroy(pthread_attr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getdetachstate=_pthread_attr_getdetachstate
|
||||
|
||||
int
|
||||
pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
||||
_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -56,4 +57,3 @@ pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getinheritsched=_pthread_attr_getinheritsched
|
||||
|
||||
int
|
||||
pthread_attr_getinheritsched(const pthread_attr_t *attr, int *sched_inherit)
|
||||
_pthread_attr_getinheritsched(const pthread_attr_t *attr, int *sched_inherit)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -48,4 +49,3 @@ pthread_attr_getinheritsched(const pthread_attr_t *attr, int *sched_inherit)
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getschedparam=_pthread_attr_getschedparam
|
||||
|
||||
int
|
||||
pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
|
||||
_pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -48,4 +49,3 @@ pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getschedpolicy=_pthread_attr_getschedpolicy
|
||||
|
||||
int
|
||||
pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
|
||||
_pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -48,4 +49,3 @@ pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getscope=_pthread_attr_getscope
|
||||
|
||||
int
|
||||
pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
|
||||
_pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -51,4 +52,3 @@ pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getstackaddr=_pthread_attr_getstackaddr
|
||||
|
||||
int
|
||||
pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
|
||||
_pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -51,4 +52,3 @@ pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_getstacksize=_pthread_attr_getstacksize
|
||||
|
||||
int
|
||||
pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
||||
_pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -51,4 +52,3 @@ pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -34,11 +34,13 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
int pthread_attr_init(pthread_attr_t *attr)
|
||||
#pragma weak pthread_attr_init=_pthread_attr_init
|
||||
|
||||
int
|
||||
_pthread_attr_init(pthread_attr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t pattr;
|
||||
@ -57,4 +59,3 @@ int pthread_attr_init(pthread_attr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setcreatesuspend_np=_pthread_attr_setcreatesuspend_np
|
||||
|
||||
int
|
||||
pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
|
||||
_pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL || *attr == NULL) {
|
||||
@ -49,4 +50,3 @@ pthread_attr_setcreatesuspend_np(pthread_attr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setdetachstate=_pthread_attr_setdetachstate
|
||||
|
||||
int
|
||||
pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
||||
_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -58,4 +59,3 @@ pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setinheritsched=_pthread_attr_setinheritsched
|
||||
|
||||
int
|
||||
pthread_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit)
|
||||
_pthread_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -48,4 +49,3 @@ pthread_attr_setinheritsched(pthread_attr_t *attr, int sched_inherit)
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setprio=_pthread_attr_setprio
|
||||
|
||||
int
|
||||
pthread_attr_setprio(pthread_attr_t *attr, int priority)
|
||||
_pthread_attr_setprio(pthread_attr_t *attr, int priority)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL || *attr == NULL) {
|
||||
@ -49,4 +50,3 @@ pthread_attr_setprio(pthread_attr_t *attr, int priority)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setschedparam=_pthread_attr_setschedparam
|
||||
|
||||
int
|
||||
pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
|
||||
_pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -54,4 +55,3 @@ pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setschedpolicy=_pthread_attr_setschedpolicy
|
||||
|
||||
int
|
||||
pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
||||
_pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -50,4 +51,3 @@ pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setscope=_pthread_attr_setscope
|
||||
|
||||
int
|
||||
pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
|
||||
_pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -53,4 +54,3 @@ pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setstackaddr=_pthread_attr_setstackaddr
|
||||
|
||||
int
|
||||
pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
|
||||
_pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -51,4 +52,3 @@ pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_attr_setstacksize=_pthread_attr_setstacksize
|
||||
|
||||
int
|
||||
pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
|
||||
_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -51,4 +52,3 @@ pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,21 +33,19 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak bind=_bind
|
||||
|
||||
int
|
||||
_bind(int fd, const struct sockaddr * name, socklen_t namelen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_bind(fd, name, namelen);
|
||||
ret = __sys_bind(fd, name, namelen);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_bind, bind);
|
||||
#endif
|
||||
|
@ -8,8 +8,13 @@
|
||||
|
||||
static void finish_cancellation(void *arg);
|
||||
|
||||
#pragma weak pthread_cancel=_pthread_cancel
|
||||
#pragma weak pthread_setcancelstate=_pthread_setcancelstate
|
||||
#pragma weak pthread_setcanceltype=_pthread_setcanceltype
|
||||
#pragma weak pthread_testcancel=_pthread_testcancel
|
||||
|
||||
int
|
||||
pthread_cancel(pthread_t pthread)
|
||||
_pthread_cancel(pthread_t pthread)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -111,26 +116,27 @@ pthread_cancel(pthread_t pthread)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_setcancelstate(int state, int *oldstate)
|
||||
_pthread_setcancelstate(int state, int *oldstate)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ostate;
|
||||
int ret;
|
||||
|
||||
ostate = _thread_run->cancelflags & PTHREAD_CANCEL_DISABLE;
|
||||
ostate = curthread->cancelflags & PTHREAD_CANCEL_DISABLE;
|
||||
|
||||
switch (state) {
|
||||
case PTHREAD_CANCEL_ENABLE:
|
||||
if (oldstate != NULL)
|
||||
*oldstate = ostate;
|
||||
_thread_run->cancelflags &= ~PTHREAD_CANCEL_DISABLE;
|
||||
if ((_thread_run->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)
|
||||
curthread->cancelflags &= ~PTHREAD_CANCEL_DISABLE;
|
||||
if ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)
|
||||
pthread_testcancel();
|
||||
ret = 0;
|
||||
break;
|
||||
case PTHREAD_CANCEL_DISABLE:
|
||||
if (oldstate != NULL)
|
||||
*oldstate = ostate;
|
||||
_thread_run->cancelflags |= PTHREAD_CANCEL_DISABLE;
|
||||
curthread->cancelflags |= PTHREAD_CANCEL_DISABLE;
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
@ -141,24 +147,25 @@ pthread_setcancelstate(int state, int *oldstate)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_setcanceltype(int type, int *oldtype)
|
||||
_pthread_setcanceltype(int type, int *oldtype)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int otype;
|
||||
int ret;
|
||||
|
||||
otype = _thread_run->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS;
|
||||
otype = curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS;
|
||||
switch (type) {
|
||||
case PTHREAD_CANCEL_ASYNCHRONOUS:
|
||||
if (oldtype != NULL)
|
||||
*oldtype = otype;
|
||||
_thread_run->cancelflags |= PTHREAD_CANCEL_ASYNCHRONOUS;
|
||||
curthread->cancelflags |= PTHREAD_CANCEL_ASYNCHRONOUS;
|
||||
pthread_testcancel();
|
||||
ret = 0;
|
||||
break;
|
||||
case PTHREAD_CANCEL_DEFERRED:
|
||||
if (oldtype != NULL)
|
||||
*oldtype = otype;
|
||||
_thread_run->cancelflags &= ~PTHREAD_CANCEL_ASYNCHRONOUS;
|
||||
curthread->cancelflags &= ~PTHREAD_CANCEL_ASYNCHRONOUS;
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
@ -169,16 +176,18 @@ pthread_setcanceltype(int type, int *oldtype)
|
||||
}
|
||||
|
||||
void
|
||||
pthread_testcancel(void)
|
||||
_pthread_testcancel(void)
|
||||
{
|
||||
if (((_thread_run->cancelflags & PTHREAD_CANCEL_DISABLE) == 0) &&
|
||||
((_thread_run->cancelflags & PTHREAD_CANCELLING) != 0)) {
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
if (((curthread->cancelflags & PTHREAD_CANCEL_DISABLE) == 0) &&
|
||||
((curthread->cancelflags & PTHREAD_CANCELLING) != 0)) {
|
||||
/*
|
||||
* It is possible for this thread to be swapped out
|
||||
* while performing cancellation; do not allow it
|
||||
* to be cancelled again.
|
||||
*/
|
||||
_thread_run->cancelflags &= ~PTHREAD_CANCELLING;
|
||||
curthread->cancelflags &= ~PTHREAD_CANCELLING;
|
||||
_thread_exit_cleanup();
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
PANIC("cancel");
|
||||
@ -188,15 +197,19 @@ pthread_testcancel(void)
|
||||
void
|
||||
_thread_enter_cancellation_point(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/* Look for a cancellation before we block: */
|
||||
pthread_testcancel();
|
||||
_thread_run->cancelflags |= PTHREAD_AT_CANCEL_POINT;
|
||||
curthread->cancelflags |= PTHREAD_AT_CANCEL_POINT;
|
||||
}
|
||||
|
||||
void
|
||||
_thread_leave_cancellation_point(void)
|
||||
{
|
||||
_thread_run->cancelflags &= ~PTHREAD_AT_CANCEL_POINT;
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
curthread->cancelflags &= ~PTHREAD_AT_CANCEL_POINT;
|
||||
/* Look for a cancellation after we unblock: */
|
||||
pthread_testcancel();
|
||||
}
|
||||
@ -204,11 +217,13 @@ _thread_leave_cancellation_point(void)
|
||||
static void
|
||||
finish_cancellation(void *arg)
|
||||
{
|
||||
_thread_run->continuation = NULL;
|
||||
_thread_run->interrupted = 0;
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
if ((_thread_run->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) {
|
||||
_thread_run->cancelflags &= ~PTHREAD_CANCEL_NEEDED;
|
||||
curthread->continuation = NULL;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) {
|
||||
curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED;
|
||||
_thread_exit_cleanup();
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
}
|
||||
|
@ -34,31 +34,35 @@
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_cleanup_push=_pthread_cleanup_push
|
||||
#pragma weak pthread_cleanup_pop=_pthread_cleanup_pop
|
||||
|
||||
void
|
||||
pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
|
||||
_pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct pthread_cleanup *new;
|
||||
|
||||
if ((new = (struct pthread_cleanup *) malloc(sizeof(struct pthread_cleanup))) != NULL) {
|
||||
new->routine = routine;
|
||||
new->routine_arg = routine_arg;
|
||||
new->next = _thread_run->cleanup;
|
||||
new->next = curthread->cleanup;
|
||||
|
||||
_thread_run->cleanup = new;
|
||||
curthread->cleanup = new;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pthread_cleanup_pop(int execute)
|
||||
_pthread_cleanup_pop(int execute)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct pthread_cleanup *old;
|
||||
|
||||
if ((old = _thread_run->cleanup) != NULL) {
|
||||
_thread_run->cleanup = old->next;
|
||||
if ((old = curthread->cleanup) != NULL) {
|
||||
curthread->cleanup = old->next;
|
||||
if (execute) {
|
||||
old->routine(old->routine_arg);
|
||||
}
|
||||
@ -66,4 +70,3 @@ pthread_cleanup_pop(int execute)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -36,10 +36,11 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak close=__close
|
||||
|
||||
int
|
||||
_close(int fd)
|
||||
{
|
||||
@ -60,7 +61,7 @@ _close(int fd)
|
||||
* the file descriptor status:
|
||||
*/
|
||||
else if (((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) &&
|
||||
((ret = _thread_sys_fstat(fd, &sb)) == 0)) {
|
||||
((ret = __sys_fstat(fd, &sb)) == 0)) {
|
||||
/*
|
||||
* Check if the file should be left as blocking.
|
||||
*
|
||||
@ -83,9 +84,9 @@ _close(int fd)
|
||||
*/
|
||||
if ((S_ISREG(sb.st_mode) || S_ISCHR(sb.st_mode)) && (_thread_fd_table[fd]->flags & O_NONBLOCK) == 0) {
|
||||
/* Get the current flags: */
|
||||
flags = _thread_sys_fcntl(fd, F_GETFL, NULL);
|
||||
flags = __sys_fcntl(fd, F_GETFL, NULL);
|
||||
/* Clear the nonblocking file descriptor flag: */
|
||||
_thread_sys_fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||
__sys_fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
/* XXX: Assumes well behaved threads. */
|
||||
@ -95,13 +96,13 @@ _close(int fd)
|
||||
free(entry);
|
||||
|
||||
/* Close the file descriptor: */
|
||||
ret = _thread_sys_close(fd);
|
||||
ret = __sys_close(fd);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
close(int fd)
|
||||
__close(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -111,4 +112,3 @@ close(int fd)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -45,6 +44,14 @@ static inline pthread_t cond_queue_deq(pthread_cond_t);
|
||||
static inline void cond_queue_remove(pthread_cond_t, pthread_t);
|
||||
static inline void cond_queue_enq(pthread_cond_t, pthread_t);
|
||||
|
||||
#pragma weak pthread_cond_init=_pthread_cond_init
|
||||
#pragma weak pthread_cond_destroy=_pthread_cond_destroy
|
||||
#pragma weak pthread_cond_wait=_pthread_cond_wait
|
||||
#pragma weak pthread_cond_timedwait=_pthread_cond_timedwait
|
||||
#pragma weak pthread_cond_signal=_pthread_cond_signal
|
||||
#pragma weak pthread_cond_broadcast=_pthread_cond_broadcast
|
||||
|
||||
|
||||
/* Reinitialize a condition variable to defaults. */
|
||||
int
|
||||
_cond_reinit(pthread_cond_t *cond)
|
||||
@ -70,7 +77,7 @@ _cond_reinit(pthread_cond_t *cond)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
|
||||
_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
|
||||
{
|
||||
enum pthread_cond_type type;
|
||||
pthread_cond_t pcond;
|
||||
@ -130,7 +137,7 @@ pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_destroy(pthread_cond_t *cond)
|
||||
_pthread_cond_destroy(pthread_cond_t *cond)
|
||||
{
|
||||
int rval = 0;
|
||||
|
||||
@ -157,8 +164,9 @@ pthread_cond_destroy(pthread_cond_t *cond)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int rval = 0;
|
||||
int done = 0;
|
||||
int interrupted = 0;
|
||||
@ -213,21 +221,21 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
rval = EINVAL;
|
||||
} else {
|
||||
/* Reset the timeout and interrupted flags: */
|
||||
_thread_run->timeout = 0;
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->timeout = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Queue the running thread for the condition
|
||||
* variable:
|
||||
*/
|
||||
cond_queue_enq(*cond, _thread_run);
|
||||
cond_queue_enq(*cond, curthread);
|
||||
|
||||
/* Remember the mutex and sequence number: */
|
||||
(*cond)->c_mutex = *mutex;
|
||||
seqno = (*cond)->c_seqno;
|
||||
|
||||
/* Wait forever: */
|
||||
_thread_run->wakeup_time.tv_sec = -1;
|
||||
curthread->wakeup_time.tv_sec = -1;
|
||||
|
||||
/* Unlock the mutex: */
|
||||
if ((unlock_mutex != 0) &&
|
||||
@ -237,7 +245,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
* the running thread from the condition
|
||||
* variable queue:
|
||||
*/
|
||||
cond_queue_remove(*cond, _thread_run);
|
||||
cond_queue_remove(*cond, curthread);
|
||||
|
||||
/* Check for no more waiters: */
|
||||
if (TAILQ_FIRST(&(*cond)->c_queue) ==
|
||||
@ -264,7 +272,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
|
||||
done = (seqno != (*cond)->c_seqno);
|
||||
|
||||
if ((_thread_run->flags &
|
||||
if ((curthread->flags &
|
||||
PTHREAD_FLAGS_IN_CONDQ) != 0) {
|
||||
/*
|
||||
* Lock the condition variable
|
||||
@ -273,7 +281,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
_SPINLOCK(&(*cond)->lock);
|
||||
|
||||
cond_queue_remove(*cond,
|
||||
_thread_run);
|
||||
curthread);
|
||||
|
||||
/* Check for no more waiters: */
|
||||
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
|
||||
@ -286,7 +294,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
* Save the interrupted flag; locking
|
||||
* the mutex will destroy it.
|
||||
*/
|
||||
interrupted = _thread_run->interrupted;
|
||||
interrupted = curthread->interrupted;
|
||||
|
||||
/*
|
||||
* Note that even though this thread may have
|
||||
@ -308,8 +316,8 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((interrupted != 0) && (_thread_run->continuation != NULL))
|
||||
_thread_run->continuation((void *) _thread_run);
|
||||
if ((interrupted != 0) && (curthread->continuation != NULL))
|
||||
curthread->continuation((void *) curthread);
|
||||
} while ((done == 0) && (rval == 0));
|
||||
|
||||
_thread_leave_cancellation_point();
|
||||
@ -319,9 +327,10 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
_pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
const struct timespec * abstime)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int rval = 0;
|
||||
int done = 0;
|
||||
int interrupted = 0;
|
||||
@ -375,20 +384,20 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
_SPINUNLOCK(&(*cond)->lock);
|
||||
} else {
|
||||
/* Set the wakeup time: */
|
||||
_thread_run->wakeup_time.tv_sec =
|
||||
curthread->wakeup_time.tv_sec =
|
||||
abstime->tv_sec;
|
||||
_thread_run->wakeup_time.tv_nsec =
|
||||
curthread->wakeup_time.tv_nsec =
|
||||
abstime->tv_nsec;
|
||||
|
||||
/* Reset the timeout and interrupted flags: */
|
||||
_thread_run->timeout = 0;
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->timeout = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Queue the running thread for the condition
|
||||
* variable:
|
||||
*/
|
||||
cond_queue_enq(*cond, _thread_run);
|
||||
cond_queue_enq(*cond, curthread);
|
||||
|
||||
/* Remember the mutex and sequence number: */
|
||||
(*cond)->c_mutex = *mutex;
|
||||
@ -402,7 +411,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
* the running thread from the condition
|
||||
* variable queue:
|
||||
*/
|
||||
cond_queue_remove(*cond, _thread_run);
|
||||
cond_queue_remove(*cond, curthread);
|
||||
|
||||
/* Check for no more waiters: */
|
||||
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
|
||||
@ -432,8 +441,8 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
* interrupted (canceled), or needs to
|
||||
* be resumed after handling a signal.
|
||||
*/
|
||||
if ((_thread_run->timeout == 0) &&
|
||||
(_thread_run->interrupted == 0) &&
|
||||
if ((curthread->timeout == 0) &&
|
||||
(curthread->interrupted == 0) &&
|
||||
(done != 0)) {
|
||||
/* Lock the mutex: */
|
||||
rval = _mutex_cv_lock(mutex);
|
||||
@ -447,7 +456,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
* variable queue:
|
||||
*/
|
||||
cond_queue_remove(*cond,
|
||||
_thread_run);
|
||||
curthread);
|
||||
|
||||
/* Check for no more waiters: */
|
||||
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
|
||||
@ -457,14 +466,14 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
_SPINUNLOCK(&(*cond)->lock);
|
||||
|
||||
/* Return a timeout error: */
|
||||
if (_thread_run->timeout != 0)
|
||||
if (curthread->timeout != 0)
|
||||
rval = ETIMEDOUT;
|
||||
/*
|
||||
* Save the interrupted flag;
|
||||
* locking the mutex will
|
||||
* destroy it.
|
||||
*/
|
||||
interrupted = _thread_run->interrupted;
|
||||
interrupted = curthread->interrupted;
|
||||
|
||||
/*
|
||||
* Lock the mutex and ignore any
|
||||
@ -490,8 +499,8 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
break;
|
||||
}
|
||||
|
||||
if ((interrupted != 0) && (_thread_run->continuation != NULL))
|
||||
_thread_run->continuation((void *) _thread_run);
|
||||
if ((interrupted != 0) && (curthread->continuation != NULL))
|
||||
curthread->continuation((void *) curthread);
|
||||
} while ((done == 0) && (rval == 0));
|
||||
|
||||
_thread_leave_cancellation_point();
|
||||
@ -501,7 +510,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_signal(pthread_cond_t * cond)
|
||||
_pthread_cond_signal(pthread_cond_t * cond)
|
||||
{
|
||||
int rval = 0;
|
||||
pthread_t pthread;
|
||||
@ -569,7 +578,7 @@ pthread_cond_signal(pthread_cond_t * cond)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_cond_broadcast(pthread_cond_t * cond)
|
||||
_pthread_cond_broadcast(pthread_cond_t * cond)
|
||||
{
|
||||
int rval = 0;
|
||||
pthread_t pthread;
|
||||
@ -752,4 +761,3 @@ cond_queue_enq(pthread_cond_t cond, pthread_t pthread)
|
||||
pthread->flags |= PTHREAD_FLAGS_IN_CONDQ;
|
||||
pthread->data.cond = cond;
|
||||
}
|
||||
#endif
|
||||
|
@ -33,11 +33,13 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
int pthread_condattr_destroy(pthread_condattr_t *attr)
|
||||
#pragma weak pthread_condattr_destroy=_pthread_condattr_destroy
|
||||
|
||||
int
|
||||
_pthread_condattr_destroy(pthread_condattr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL || *attr == NULL) {
|
||||
@ -49,4 +51,3 @@ int pthread_condattr_destroy(pthread_condattr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -34,12 +34,13 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_condattr_init=_pthread_condattr_init
|
||||
|
||||
int
|
||||
pthread_condattr_init(pthread_condattr_t *attr)
|
||||
_pthread_condattr_init(pthread_condattr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t pattr;
|
||||
@ -55,4 +56,3 @@ pthread_condattr_init(pthread_condattr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -35,22 +35,24 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak connect=_connect
|
||||
|
||||
int
|
||||
_connect(int fd, const struct sockaddr * name, socklen_t namelen)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct sockaddr tmpname;
|
||||
int errnolen, ret, tmpnamelen;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
if ((ret = _thread_sys_connect(fd, name, namelen)) < 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))) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(NULL);
|
||||
@ -58,14 +60,14 @@ _connect(int fd, const struct sockaddr * name, socklen_t namelen)
|
||||
|
||||
tmpnamelen = sizeof(tmpname);
|
||||
/* 0 now lets see if it really worked */
|
||||
if (((ret = _thread_sys_getpeername(fd, &tmpname, &tmpnamelen)) < 0) && (errno == ENOTCONN)) {
|
||||
if (((ret = __sys_getpeername(fd, &tmpname, &tmpnamelen)) < 0) && (errno == ENOTCONN)) {
|
||||
|
||||
/*
|
||||
* Get the error, this function
|
||||
* should not fail
|
||||
*/
|
||||
errnolen = sizeof(errno);
|
||||
_thread_sys_getsockopt(fd, SOL_SOCKET, SO_ERROR, &errno, &errnolen);
|
||||
__sys_getsockopt(fd, SOL_SOCKET, SO_ERROR, &errno, &errnolen);
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
@ -75,6 +77,3 @@ _connect(int fd, const struct sockaddr * name, socklen_t namelen)
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_connect, connect);
|
||||
#endif
|
||||
|
@ -30,12 +30,13 @@
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak creat=___creat
|
||||
|
||||
int
|
||||
creat(const char *path, mode_t mode)
|
||||
___creat(const char *path, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -45,4 +46,3 @@ creat(const char *path, mode_t mode)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <machine/reg.h>
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
@ -64,10 +63,13 @@ int _thread_CTX_JB_value = CTX_JB;
|
||||
int _thread_CTX_SJB_value = CTX_SJB;
|
||||
int _thread_CTX_UC_value = CTX_UC;
|
||||
|
||||
#pragma weak pthread_create=_pthread_create
|
||||
|
||||
int
|
||||
pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
_pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
void *(*start_routine) (void *), void *arg)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct itimerval itimer;
|
||||
int f_gc = 0;
|
||||
int ret = 0;
|
||||
@ -180,7 +182,7 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
new_thread->magic = PTHREAD_MAGIC;
|
||||
|
||||
/* Initialise the thread for signals: */
|
||||
new_thread->sigmask = _thread_run->sigmask;
|
||||
new_thread->sigmask = curthread->sigmask;
|
||||
new_thread->sigmask_seqno = 0;
|
||||
|
||||
/* Initialize the signal frame: */
|
||||
@ -214,13 +216,13 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
if (new_thread->attr.flags & PTHREAD_INHERIT_SCHED) {
|
||||
/* Copy the scheduling attributes: */
|
||||
new_thread->base_priority =
|
||||
_thread_run->base_priority &
|
||||
curthread->base_priority &
|
||||
~PTHREAD_SIGNAL_PRIORITY;
|
||||
new_thread->attr.prio =
|
||||
_thread_run->base_priority &
|
||||
curthread->base_priority &
|
||||
~PTHREAD_SIGNAL_PRIORITY;
|
||||
new_thread->attr.sched_policy =
|
||||
_thread_run->attr.sched_policy;
|
||||
curthread->attr.sched_policy;
|
||||
} else {
|
||||
/*
|
||||
* Use just the thread priority, leaving the
|
||||
@ -315,13 +317,14 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
void
|
||||
_thread_start(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/* We just left the scheduler via longjmp: */
|
||||
_thread_kern_in_sched = 0;
|
||||
|
||||
/* Run the current thread's start routine with argument: */
|
||||
pthread_exit(_thread_run->start_routine(_thread_run->arg));
|
||||
pthread_exit(curthread->start_routine(curthread->arg));
|
||||
|
||||
/* This point should never be reached. */
|
||||
PANIC("Thread has resumed after exit");
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_detach=_pthread_detach
|
||||
|
||||
int
|
||||
pthread_detach(pthread_t pthread)
|
||||
_pthread_detach(pthread_t pthread)
|
||||
{
|
||||
int rval = 0;
|
||||
pthread_t next_thread;
|
||||
@ -85,4 +86,3 @@ pthread_detach(pthread_t pthread)
|
||||
/* Return the completion status: */
|
||||
return (rval);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,10 +32,11 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak dup=_dup
|
||||
|
||||
int
|
||||
_dup(int fd)
|
||||
{
|
||||
@ -44,12 +45,12 @@ _dup(int fd)
|
||||
/* Lock the file descriptor: */
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
/* Perform the 'dup' syscall: */
|
||||
if ((ret = _thread_sys_dup(fd)) < 0) {
|
||||
if ((ret = __sys_dup(fd)) < 0) {
|
||||
}
|
||||
/* Initialise the file descriptor table entry: */
|
||||
else if (_thread_fd_table_init(ret) != 0) {
|
||||
/* Quietly close the file: */
|
||||
_thread_sys_close(ret);
|
||||
__sys_close(ret);
|
||||
|
||||
/* Reset the file descriptor: */
|
||||
ret = -1;
|
||||
@ -67,6 +68,3 @@ _dup(int fd)
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_dup, dup);
|
||||
#endif
|
||||
|
@ -33,10 +33,11 @@
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak dup2=_dup2
|
||||
|
||||
int
|
||||
_dup2(int fd, int newfd)
|
||||
{
|
||||
@ -56,12 +57,12 @@ _dup2(int fd, int newfd)
|
||||
if (!(newfd_opened = (_thread_fd_table[newfd] != NULL)) ||
|
||||
(ret = _FD_LOCK(newfd, FD_RDWR, NULL)) == 0) {
|
||||
/* Perform the 'dup2' syscall: */
|
||||
if ((ret = _thread_sys_dup2(fd, newfd)) < 0) {
|
||||
if ((ret = __sys_dup2(fd, newfd)) < 0) {
|
||||
}
|
||||
/* Initialise the file descriptor table entry: */
|
||||
else if (_thread_fd_table_init(ret) != 0) {
|
||||
/* Quietly close the file: */
|
||||
_thread_sys_close(ret);
|
||||
__sys_close(ret);
|
||||
|
||||
/* Reset the file descriptor: */
|
||||
ret = -1;
|
||||
@ -83,6 +84,3 @@ _dup2(int fd, int newfd)
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_dup2, dup2);
|
||||
#endif
|
||||
|
@ -31,14 +31,14 @@
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_equal=_pthread_equal
|
||||
|
||||
int
|
||||
pthread_equal(pthread_t t1, pthread_t t2)
|
||||
_pthread_equal(pthread_t t1, pthread_t t2)
|
||||
{
|
||||
/* Compare the two thread pointers: */
|
||||
return (t1 == t2);
|
||||
}
|
||||
#endif
|
||||
|
@ -34,13 +34,15 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak execve=_execve
|
||||
|
||||
int
|
||||
_execve(const char *name, char *const * argv, char *const * envp)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int flags;
|
||||
int i;
|
||||
int ret;
|
||||
@ -56,8 +58,8 @@ _execve(const char *name, char *const * argv, char *const * envp)
|
||||
setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL);
|
||||
|
||||
/* Close the pthread kernel pipe: */
|
||||
_thread_sys_close(_thread_kern_pipe[0]);
|
||||
_thread_sys_close(_thread_kern_pipe[1]);
|
||||
__sys_close(_thread_kern_pipe[0]);
|
||||
__sys_close(_thread_kern_pipe[1]);
|
||||
|
||||
/*
|
||||
* Enter a loop to set all file descriptors to blocking
|
||||
@ -68,9 +70,9 @@ _execve(const char *name, char *const * argv, char *const * envp)
|
||||
if (_thread_fd_table[i] != NULL &&
|
||||
!(_thread_fd_table[i]->flags & O_NONBLOCK)) {
|
||||
/* Get the current flags: */
|
||||
flags = _thread_sys_fcntl(i, F_GETFL, NULL);
|
||||
flags = __sys_fcntl(i, F_GETFL, NULL);
|
||||
/* Clear the nonblocking file descriptor flag: */
|
||||
_thread_sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
|
||||
__sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,19 +96,16 @@ _execve(const char *name, char *const * argv, char *const * envp)
|
||||
act.sa_flags = _thread_sigact[i - 1].sa_flags;
|
||||
|
||||
/* Change the signal action for the process: */
|
||||
_thread_sys_sigaction(i, &act, &oact);
|
||||
__sys_sigaction(i, &act, &oact);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the signal mask: */
|
||||
_thread_sys_sigprocmask(SIG_SETMASK, &_thread_run->sigmask, NULL);
|
||||
__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
||||
|
||||
/* Execute the process: */
|
||||
ret = _thread_sys_execve(name, argv, envp);
|
||||
ret = __sys_execve(name, argv, envp);
|
||||
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_execve, execve);
|
||||
#endif
|
||||
|
@ -37,13 +37,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#define FLAGS_IN_SCHEDQ \
|
||||
(PTHREAD_FLAGS_IN_PRIOQ|PTHREAD_FLAGS_IN_WAITQ|PTHREAD_FLAGS_IN_WORKQ)
|
||||
|
||||
#pragma weak _exit=__exit
|
||||
#pragma weak pthread_exit=_pthread_exit
|
||||
|
||||
void __exit(int status)
|
||||
{
|
||||
int flags;
|
||||
@ -58,8 +60,8 @@ void __exit(int status)
|
||||
setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL);
|
||||
|
||||
/* Close the pthread kernel pipe: */
|
||||
_thread_sys_close(_thread_kern_pipe[0]);
|
||||
_thread_sys_close(_thread_kern_pipe[1]);
|
||||
__sys_close(_thread_kern_pipe[0]);
|
||||
__sys_close(_thread_kern_pipe[1]);
|
||||
|
||||
/*
|
||||
* Enter a loop to set all file descriptors to blocking
|
||||
@ -70,18 +72,16 @@ void __exit(int status)
|
||||
if (_thread_fd_table[i] != NULL &&
|
||||
!(_thread_fd_table[i]->flags & O_NONBLOCK)) {
|
||||
/* Get the current flags: */
|
||||
flags = _thread_sys_fcntl(i, F_GETFL, NULL);
|
||||
flags = __sys_fcntl(i, F_GETFL, NULL);
|
||||
/* Clear the nonblocking file descriptor flag: */
|
||||
_thread_sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
|
||||
__sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
/* Call the _exit syscall: */
|
||||
_thread_sys__exit(status);
|
||||
__sys__exit(status);
|
||||
}
|
||||
|
||||
__strong_reference(__exit, _exit);
|
||||
|
||||
void
|
||||
_thread_exit(char *fname, int lineno, char *string)
|
||||
{
|
||||
@ -97,7 +97,7 @@ _thread_exit(char *fname, int lineno, char *string)
|
||||
strcat(s, ")\n");
|
||||
|
||||
/* Write the string to the standard error file descriptor: */
|
||||
_thread_sys_write(2, s, strlen(s));
|
||||
__sys_write(2, s, strlen(s));
|
||||
|
||||
/* Force this process to exit: */
|
||||
/* XXX - Do we want abort to be conditional on _PTHREADS_INVARIANTS? */
|
||||
@ -116,6 +116,8 @@ _thread_exit(char *fname, int lineno, char *string)
|
||||
void
|
||||
_thread_exit_cleanup(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/*
|
||||
* POSIX states that cancellation/termination of a thread should
|
||||
* not release any visible resources (such as mutexes) and that
|
||||
@ -124,13 +126,13 @@ _thread_exit_cleanup(void)
|
||||
* are not visible to the application and need to be released.
|
||||
*/
|
||||
/* Unlock all owned fd locks: */
|
||||
_thread_fd_unlock_owned(_thread_run);
|
||||
_thread_fd_unlock_owned(curthread);
|
||||
|
||||
/* Unlock all owned file locks: */
|
||||
_funlock_owned(_thread_run);
|
||||
_funlock_owned(curthread);
|
||||
|
||||
/* Unlock all private mutexes: */
|
||||
_mutex_unlock_private(_thread_run);
|
||||
_mutex_unlock_private(curthread);
|
||||
|
||||
/*
|
||||
* This still isn't quite correct because we don't account
|
||||
@ -139,39 +141,40 @@ _thread_exit_cleanup(void)
|
||||
}
|
||||
|
||||
void
|
||||
pthread_exit(void *status)
|
||||
_pthread_exit(void *status)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
pthread_t pthread;
|
||||
|
||||
/* Check if this thread is already in the process of exiting: */
|
||||
if ((_thread_run->flags & PTHREAD_EXITING) != 0) {
|
||||
if ((curthread->flags & PTHREAD_EXITING) != 0) {
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "Thread %p has called pthread_exit() from a destructor. POSIX 1003.1 1996 s16.2.5.2 does not allow this!",_thread_run);
|
||||
snprintf(msg, sizeof(msg), "Thread %p has called pthread_exit() from a destructor. POSIX 1003.1 1996 s16.2.5.2 does not allow this!",curthread);
|
||||
PANIC(msg);
|
||||
}
|
||||
|
||||
/* Flag this thread as exiting: */
|
||||
_thread_run->flags |= PTHREAD_EXITING;
|
||||
curthread->flags |= PTHREAD_EXITING;
|
||||
|
||||
/* Save the return value: */
|
||||
_thread_run->ret = status;
|
||||
curthread->ret = status;
|
||||
|
||||
while (_thread_run->cleanup != NULL) {
|
||||
while (curthread->cleanup != NULL) {
|
||||
pthread_cleanup_pop(1);
|
||||
}
|
||||
if (_thread_run->attr.cleanup_attr != NULL) {
|
||||
_thread_run->attr.cleanup_attr(_thread_run->attr.arg_attr);
|
||||
if (curthread->attr.cleanup_attr != NULL) {
|
||||
curthread->attr.cleanup_attr(curthread->attr.arg_attr);
|
||||
}
|
||||
/* Check if there is thread specific data: */
|
||||
if (_thread_run->specific_data != NULL) {
|
||||
if (curthread->specific_data != NULL) {
|
||||
/* Run the thread-specific data destructors: */
|
||||
_thread_cleanupspecific();
|
||||
}
|
||||
|
||||
/* Free thread-specific poll_data structure, if allocated: */
|
||||
if (_thread_run->poll_data.fds != NULL) {
|
||||
free(_thread_run->poll_data.fds);
|
||||
_thread_run->poll_data.fds = NULL;
|
||||
if (curthread->poll_data.fds != NULL) {
|
||||
free(curthread->poll_data.fds);
|
||||
curthread->poll_data.fds = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -182,7 +185,7 @@ pthread_exit(void *status)
|
||||
PANIC("Cannot lock gc mutex");
|
||||
|
||||
/* Add this thread to the list of dead threads. */
|
||||
TAILQ_INSERT_HEAD(&_dead_list, _thread_run, dle);
|
||||
TAILQ_INSERT_HEAD(&_dead_list, curthread, dle);
|
||||
|
||||
/*
|
||||
* Signal the garbage collector thread that there is something
|
||||
@ -203,9 +206,9 @@ pthread_exit(void *status)
|
||||
PANIC("Cannot lock gc mutex");
|
||||
|
||||
/* Check if there are any threads joined to this one: */
|
||||
while ((pthread = TAILQ_FIRST(&(_thread_run->join_queue))) != NULL) {
|
||||
while ((pthread = TAILQ_FIRST(&(curthread->join_queue))) != NULL) {
|
||||
/* Remove the thread from the queue: */
|
||||
TAILQ_REMOVE(&_thread_run->join_queue, pthread, sqe);
|
||||
TAILQ_REMOVE(&curthread->join_queue, pthread, sqe);
|
||||
pthread->flags &= ~PTHREAD_FLAGS_IN_JOINQ;
|
||||
|
||||
/*
|
||||
@ -217,16 +220,16 @@ pthread_exit(void *status)
|
||||
/*
|
||||
* Set the return value for the woken thread:
|
||||
*/
|
||||
if ((_thread_run->attr.flags & PTHREAD_DETACHED) != 0)
|
||||
if ((curthread->attr.flags & PTHREAD_DETACHED) != 0)
|
||||
pthread->error = ESRCH;
|
||||
else {
|
||||
pthread->ret = _thread_run->ret;
|
||||
pthread->ret = curthread->ret;
|
||||
pthread->error = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove this thread from the thread list: */
|
||||
TAILQ_REMOVE(&_thread_list, _thread_run, tle);
|
||||
TAILQ_REMOVE(&_thread_list, curthread, tle);
|
||||
|
||||
/* This thread will never be re-scheduled. */
|
||||
_thread_kern_sched_state(PS_DEAD, __FILE__, __LINE__);
|
||||
@ -234,4 +237,3 @@ pthread_exit(void *status)
|
||||
/* This point should not be reached. */
|
||||
PANIC("Dead thread has resumed");
|
||||
}
|
||||
#endif
|
||||
|
@ -7,21 +7,18 @@
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fchflags=_fchflags
|
||||
int
|
||||
_fchflags(int fd, u_long flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
|
||||
ret = _thread_sys_fchflags(fd, flags);
|
||||
ret = __sys_fchflags(fd, flags);
|
||||
_FD_UNLOCK(fd, FD_WRITE);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_fchflags, fchflags);
|
||||
#endif
|
||||
|
@ -33,21 +33,19 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fchmod=_fchmod
|
||||
|
||||
int
|
||||
_fchmod(int fd, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
|
||||
ret = _thread_sys_fchmod(fd, mode);
|
||||
ret = __sys_fchmod(fd, mode);
|
||||
_FD_UNLOCK(fd, FD_WRITE);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_fchmod, fchmod);
|
||||
#endif
|
||||
|
@ -34,21 +34,19 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fchown=_fchown
|
||||
|
||||
int
|
||||
_fchown(int fd, uid_t owner, gid_t group)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
|
||||
ret = _thread_sys_fchown(fd, owner, group);
|
||||
ret = __sys_fchown(fd, owner, group);
|
||||
_FD_UNLOCK(fd, FD_WRITE);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_fchown, fchown);
|
||||
#endif
|
||||
|
@ -34,10 +34,11 @@
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fcntl=__fcntl
|
||||
|
||||
int
|
||||
_fcntl(int fd, int cmd,...)
|
||||
{
|
||||
@ -63,12 +64,12 @@ _fcntl(int fd, int cmd,...)
|
||||
oldfd = va_arg(ap, int);
|
||||
|
||||
/* Initialise the file descriptor table entry: */
|
||||
if ((ret = _thread_sys_fcntl(fd, cmd, oldfd)) < 0) {
|
||||
if ((ret = __sys_fcntl(fd, cmd, oldfd)) < 0) {
|
||||
}
|
||||
/* Initialise the file descriptor table entry: */
|
||||
else if (_thread_fd_table_init(ret) != 0) {
|
||||
/* Quietly close the file: */
|
||||
_thread_sys_close(ret);
|
||||
__sys_close(ret);
|
||||
|
||||
/* Reset the file descriptor: */
|
||||
ret = -1;
|
||||
@ -82,10 +83,10 @@ _fcntl(int fd, int cmd,...)
|
||||
break;
|
||||
case F_SETFD:
|
||||
flags = va_arg(ap, int);
|
||||
ret = _thread_sys_fcntl(fd, cmd, flags);
|
||||
ret = __sys_fcntl(fd, cmd, flags);
|
||||
break;
|
||||
case F_GETFD:
|
||||
ret = _thread_sys_fcntl(fd, cmd, 0);
|
||||
ret = __sys_fcntl(fd, cmd, 0);
|
||||
break;
|
||||
case F_GETFL:
|
||||
ret = _thread_fd_table[fd]->flags;
|
||||
@ -104,10 +105,10 @@ _fcntl(int fd, int cmd,...)
|
||||
nonblock = flags & O_NONBLOCK;
|
||||
|
||||
/* Set the file descriptor flags: */
|
||||
if ((ret = _thread_sys_fcntl(fd, cmd, flags | O_NONBLOCK)) != 0) {
|
||||
if ((ret = __sys_fcntl(fd, cmd, flags | O_NONBLOCK)) != 0) {
|
||||
|
||||
/* Get the flags so that we behave like the kernel: */
|
||||
} else if ((flags = _thread_sys_fcntl(fd,
|
||||
} else if ((flags = __sys_fcntl(fd,
|
||||
F_GETFL, 0)) == -1) {
|
||||
/* Error getting flags: */
|
||||
ret = -1;
|
||||
@ -125,7 +126,7 @@ _fcntl(int fd, int cmd,...)
|
||||
break;
|
||||
default:
|
||||
/* Might want to make va_arg use a union */
|
||||
ret = _thread_sys_fcntl(fd, cmd, va_arg(ap, void *));
|
||||
ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ _fcntl(int fd, int cmd,...)
|
||||
}
|
||||
|
||||
int
|
||||
fcntl(int fd, int cmd,...)
|
||||
__fcntl(int fd, int cmd,...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
@ -167,4 +168,3 @@ fcntl(int fd, int cmd,...)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -115,7 +114,7 @@ _thread_fd_table_init(int fd)
|
||||
|
||||
/* Get the flags for the file: */
|
||||
if (((fd >= 3) || (_pthread_stdio_flags[fd] == -1)) &&
|
||||
(entry->flags = _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) {
|
||||
(entry->flags = __sys_fcntl(fd, F_GETFL, 0)) == -1) {
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
@ -138,7 +137,7 @@ _thread_fd_table_init(int fd)
|
||||
* driver is naturally non-blocking.
|
||||
*/
|
||||
saved_errno = errno;
|
||||
_thread_sys_fcntl(fd, F_SETFL,
|
||||
__sys_fcntl(fd, F_SETFL,
|
||||
entry->flags | O_NONBLOCK);
|
||||
errno = saved_errno;
|
||||
|
||||
@ -181,6 +180,7 @@ _thread_fd_table_init(int fd)
|
||||
void
|
||||
_thread_fd_unlock(int fd, int lock_type)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -202,7 +202,7 @@ _thread_fd_unlock(int fd, int lock_type)
|
||||
_SPINLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
/* Check if the running thread owns the read lock: */
|
||||
if (_thread_fd_table[fd]->r_owner == _thread_run) {
|
||||
if (_thread_fd_table[fd]->r_owner == curthread) {
|
||||
/* Check the file descriptor and lock types: */
|
||||
if (lock_type == FD_READ || lock_type == FD_RDWR) {
|
||||
/*
|
||||
@ -244,7 +244,7 @@ _thread_fd_unlock(int fd, int lock_type)
|
||||
}
|
||||
}
|
||||
/* Check if the running thread owns the write lock: */
|
||||
if (_thread_fd_table[fd]->w_owner == _thread_run) {
|
||||
if (_thread_fd_table[fd]->w_owner == curthread) {
|
||||
/* Check the file descriptor and lock types: */
|
||||
if (lock_type == FD_WRITE || lock_type == FD_RDWR) {
|
||||
/*
|
||||
@ -300,6 +300,7 @@ _thread_fd_unlock(int fd, int lock_type)
|
||||
int
|
||||
_thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -308,7 +309,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
*/
|
||||
if ((ret = _thread_fd_table_init(fd)) == 0) {
|
||||
/* Clear the interrupted flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Lock the file descriptor table entry to prevent
|
||||
@ -323,8 +324,8 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
* Wait for the file descriptor to be locked
|
||||
* for read for the current thread:
|
||||
*/
|
||||
while ((_thread_fd_table[fd]->r_owner != _thread_run) &&
|
||||
(_thread_run->interrupted == 0)) {
|
||||
while ((_thread_fd_table[fd]->r_owner != curthread) &&
|
||||
(curthread->interrupted == 0)) {
|
||||
/*
|
||||
* Check if the file descriptor is locked by
|
||||
* another thread:
|
||||
@ -336,14 +337,14 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
* queue of threads waiting for a
|
||||
* read lock on this file descriptor:
|
||||
*/
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->r_queue, _thread_run);
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->r_queue, curthread);
|
||||
|
||||
/*
|
||||
* Save the file descriptor details
|
||||
* in the thread structure for the
|
||||
* running thread:
|
||||
*/
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(timeout);
|
||||
@ -371,16 +372,16 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
*/
|
||||
_SPINLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (curthread->interrupted != 0) {
|
||||
FDQ_REMOVE(&_thread_fd_table[fd]->r_queue,
|
||||
_thread_run);
|
||||
curthread);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The running thread now owns the
|
||||
* read lock on this file descriptor:
|
||||
*/
|
||||
_thread_fd_table[fd]->r_owner = _thread_run;
|
||||
_thread_fd_table[fd]->r_owner = curthread;
|
||||
|
||||
/*
|
||||
* Reset the number of read locks for
|
||||
@ -390,20 +391,20 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
}
|
||||
}
|
||||
|
||||
if (_thread_fd_table[fd]->r_owner == _thread_run)
|
||||
if (_thread_fd_table[fd]->r_owner == curthread)
|
||||
/* Increment the read lock count: */
|
||||
_thread_fd_table[fd]->r_lockcount++;
|
||||
}
|
||||
|
||||
/* Check the file descriptor and lock types: */
|
||||
if (_thread_run->interrupted == 0 &&
|
||||
if (curthread->interrupted == 0 &&
|
||||
(lock_type == FD_WRITE || lock_type == FD_RDWR)) {
|
||||
/*
|
||||
* Wait for the file descriptor to be locked
|
||||
* for write for the current thread:
|
||||
*/
|
||||
while ((_thread_fd_table[fd]->w_owner != _thread_run) &&
|
||||
(_thread_run->interrupted == 0)) {
|
||||
while ((_thread_fd_table[fd]->w_owner != curthread) &&
|
||||
(curthread->interrupted == 0)) {
|
||||
/*
|
||||
* Check if the file descriptor is locked by
|
||||
* another thread:
|
||||
@ -416,14 +417,14 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
* write lock on this file
|
||||
* descriptor:
|
||||
*/
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->w_queue, _thread_run);
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->w_queue, curthread);
|
||||
|
||||
/*
|
||||
* Save the file descriptor details
|
||||
* in the thread structure for the
|
||||
* running thread:
|
||||
*/
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(timeout);
|
||||
@ -450,9 +451,9 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
*/
|
||||
_SPINLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (curthread->interrupted != 0) {
|
||||
FDQ_REMOVE(&_thread_fd_table[fd]->w_queue,
|
||||
_thread_run);
|
||||
curthread);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
@ -460,7 +461,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
* write lock on this file
|
||||
* descriptor:
|
||||
*/
|
||||
_thread_fd_table[fd]->w_owner = _thread_run;
|
||||
_thread_fd_table[fd]->w_owner = curthread;
|
||||
|
||||
/*
|
||||
* Reset the number of write locks
|
||||
@ -470,7 +471,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
}
|
||||
}
|
||||
|
||||
if (_thread_fd_table[fd]->w_owner == _thread_run)
|
||||
if (_thread_fd_table[fd]->w_owner == curthread)
|
||||
/* Increment the write lock count: */
|
||||
_thread_fd_table[fd]->w_lockcount++;
|
||||
}
|
||||
@ -478,11 +479,11 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
/* Unlock the file descriptor table entry: */
|
||||
_SPINUNLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (curthread->interrupted != 0) {
|
||||
ret = -1;
|
||||
errno = EINTR;
|
||||
if (_thread_run->continuation != NULL)
|
||||
_thread_run->continuation((void *)_thread_run);
|
||||
if (curthread->continuation != NULL)
|
||||
curthread->continuation((void *)curthread);
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,6 +494,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
|
||||
void
|
||||
_thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -514,7 +516,7 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno)
|
||||
_spinlock_debug(&_thread_fd_table[fd]->lock, fname, lineno);
|
||||
|
||||
/* Check if the running thread owns the read lock: */
|
||||
if (_thread_fd_table[fd]->r_owner == _thread_run) {
|
||||
if (_thread_fd_table[fd]->r_owner == curthread) {
|
||||
/* Check the file descriptor and lock types: */
|
||||
if (lock_type == FD_READ || lock_type == FD_RDWR) {
|
||||
/*
|
||||
@ -556,7 +558,7 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno)
|
||||
}
|
||||
}
|
||||
/* Check if the running thread owns the write lock: */
|
||||
if (_thread_fd_table[fd]->w_owner == _thread_run) {
|
||||
if (_thread_fd_table[fd]->w_owner == curthread) {
|
||||
/* Check the file descriptor and lock types: */
|
||||
if (lock_type == FD_WRITE || lock_type == FD_RDWR) {
|
||||
/*
|
||||
@ -613,6 +615,7 @@ int
|
||||
_thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
char *fname, int lineno)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -621,7 +624,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
*/
|
||||
if ((ret = _thread_fd_table_init(fd)) == 0) {
|
||||
/* Clear the interrupted flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Lock the file descriptor table entry to prevent
|
||||
@ -636,8 +639,8 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
* Wait for the file descriptor to be locked
|
||||
* for read for the current thread:
|
||||
*/
|
||||
while ((_thread_fd_table[fd]->r_owner != _thread_run) &&
|
||||
(_thread_run->interrupted == 0)) {
|
||||
while ((_thread_fd_table[fd]->r_owner != curthread) &&
|
||||
(curthread->interrupted == 0)) {
|
||||
/*
|
||||
* Check if the file descriptor is locked by
|
||||
* another thread:
|
||||
@ -649,16 +652,16 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
* queue of threads waiting for a
|
||||
* read lock on this file descriptor:
|
||||
*/
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->r_queue, _thread_run);
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->r_queue, curthread);
|
||||
|
||||
/*
|
||||
* Save the file descriptor details
|
||||
* in the thread structure for the
|
||||
* running thread:
|
||||
*/
|
||||
_thread_run->data.fd.fd = fd;
|
||||
_thread_run->data.fd.branch = lineno;
|
||||
_thread_run->data.fd.fname = fname;
|
||||
curthread->data.fd.fd = fd;
|
||||
curthread->data.fd.branch = lineno;
|
||||
curthread->data.fd.fname = fname;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(timeout);
|
||||
@ -686,16 +689,16 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
*/
|
||||
_SPINLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (curthread->interrupted != 0) {
|
||||
FDQ_REMOVE(&_thread_fd_table[fd]->r_queue,
|
||||
_thread_run);
|
||||
curthread);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The running thread now owns the
|
||||
* read lock on this file descriptor:
|
||||
*/
|
||||
_thread_fd_table[fd]->r_owner = _thread_run;
|
||||
_thread_fd_table[fd]->r_owner = curthread;
|
||||
|
||||
/*
|
||||
* Reset the number of read locks for
|
||||
@ -712,20 +715,20 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
}
|
||||
}
|
||||
|
||||
if (_thread_fd_table[fd]->r_owner == _thread_run)
|
||||
if (_thread_fd_table[fd]->r_owner == curthread)
|
||||
/* Increment the read lock count: */
|
||||
_thread_fd_table[fd]->r_lockcount++;
|
||||
}
|
||||
|
||||
/* Check the file descriptor and lock types: */
|
||||
if (_thread_run->interrupted == 0 &&
|
||||
if (curthread->interrupted == 0 &&
|
||||
(lock_type == FD_WRITE || lock_type == FD_RDWR)) {
|
||||
/*
|
||||
* Wait for the file descriptor to be locked
|
||||
* for write for the current thread:
|
||||
*/
|
||||
while ((_thread_fd_table[fd]->w_owner != _thread_run) &&
|
||||
(_thread_run->interrupted == 0)) {
|
||||
while ((_thread_fd_table[fd]->w_owner != curthread) &&
|
||||
(curthread->interrupted == 0)) {
|
||||
/*
|
||||
* Check if the file descriptor is locked by
|
||||
* another thread:
|
||||
@ -738,16 +741,16 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
* write lock on this file
|
||||
* descriptor:
|
||||
*/
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->w_queue, _thread_run);
|
||||
FDQ_INSERT(&_thread_fd_table[fd]->w_queue, curthread);
|
||||
|
||||
/*
|
||||
* Save the file descriptor details
|
||||
* in the thread structure for the
|
||||
* running thread:
|
||||
*/
|
||||
_thread_run->data.fd.fd = fd;
|
||||
_thread_run->data.fd.branch = lineno;
|
||||
_thread_run->data.fd.fname = fname;
|
||||
curthread->data.fd.fd = fd;
|
||||
curthread->data.fd.branch = lineno;
|
||||
curthread->data.fd.fname = fname;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(timeout);
|
||||
@ -774,9 +777,9 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
*/
|
||||
_SPINLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (curthread->interrupted != 0) {
|
||||
FDQ_REMOVE(&_thread_fd_table[fd]->w_queue,
|
||||
_thread_run);
|
||||
curthread);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
@ -784,7 +787,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
* write lock on this file
|
||||
* descriptor:
|
||||
*/
|
||||
_thread_fd_table[fd]->w_owner = _thread_run;
|
||||
_thread_fd_table[fd]->w_owner = curthread;
|
||||
|
||||
/*
|
||||
* Reset the number of write locks
|
||||
@ -801,7 +804,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
}
|
||||
}
|
||||
|
||||
if (_thread_fd_table[fd]->w_owner == _thread_run)
|
||||
if (_thread_fd_table[fd]->w_owner == curthread)
|
||||
/* Increment the write lock count: */
|
||||
_thread_fd_table[fd]->w_lockcount++;
|
||||
}
|
||||
@ -809,11 +812,11 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout,
|
||||
/* Unlock the file descriptor table entry: */
|
||||
_SPINUNLOCK(&_thread_fd_table[fd]->lock);
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (curthread->interrupted != 0) {
|
||||
ret = -1;
|
||||
errno = EINTR;
|
||||
if (_thread_run->continuation != NULL)
|
||||
_thread_run->continuation((void *)_thread_run);
|
||||
if (curthread->continuation != NULL)
|
||||
curthread->continuation((void *)curthread);
|
||||
}
|
||||
}
|
||||
|
||||
@ -985,4 +988,3 @@ fd_next_writer(int fd)
|
||||
|
||||
return (pthread);
|
||||
}
|
||||
#endif
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/queue.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -137,6 +136,7 @@ static
|
||||
struct file_lock *
|
||||
do_lock(int idx, FILE *fp)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct file_lock *p;
|
||||
|
||||
/* Check if the static structure is not being used: */
|
||||
@ -171,7 +171,7 @@ do_lock(int idx, FILE *fp)
|
||||
if (p != NULL) {
|
||||
/* Acquire the lock for the running thread: */
|
||||
p->fp = fp;
|
||||
p->owner = _thread_run;
|
||||
p->owner = curthread;
|
||||
p->count = 1;
|
||||
TAILQ_INIT(&p->l_head);
|
||||
}
|
||||
@ -181,6 +181,7 @@ do_lock(int idx, FILE *fp)
|
||||
void
|
||||
_flockfile_debug(FILE * fp, char *fname, int lineno)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int idx = file_idx(fp);
|
||||
struct file_lock *p;
|
||||
|
||||
@ -213,7 +214,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno)
|
||||
* The file is already locked, so check if the
|
||||
* running thread is the owner:
|
||||
*/
|
||||
} else if (p->owner == _thread_run) {
|
||||
} else if (p->owner == curthread) {
|
||||
/*
|
||||
* The running thread is already the
|
||||
* owner, so increment the count of
|
||||
@ -226,7 +227,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno)
|
||||
_SPINUNLOCK(&hash_lock);
|
||||
} else {
|
||||
/* Clear the interrupted flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Prevent being context switched out while
|
||||
@ -239,27 +240,27 @@ _flockfile_debug(FILE * fp, char *fname, int lineno)
|
||||
* Append this thread to the queue of
|
||||
* threads waiting on the lock.
|
||||
*/
|
||||
TAILQ_INSERT_TAIL(&p->l_head,_thread_run,qe);
|
||||
_thread_run->flags |= PTHREAD_FLAGS_IN_FILEQ;
|
||||
TAILQ_INSERT_TAIL(&p->l_head,curthread,qe);
|
||||
curthread->flags |= PTHREAD_FLAGS_IN_FILEQ;
|
||||
|
||||
/* Unlock the hash table: */
|
||||
_SPINUNLOCK(&hash_lock);
|
||||
|
||||
_thread_run->data.fp = fp;
|
||||
curthread->data.fp = fp;
|
||||
|
||||
/* Wait on the FILE lock: */
|
||||
_thread_kern_sched_state(PS_FILE_WAIT, fname, lineno);
|
||||
|
||||
if ((_thread_run->flags & PTHREAD_FLAGS_IN_FILEQ) != 0) {
|
||||
TAILQ_REMOVE(&p->l_head,_thread_run,qe);
|
||||
_thread_run->flags &= ~PTHREAD_FLAGS_IN_FILEQ;
|
||||
if ((curthread->flags & PTHREAD_FLAGS_IN_FILEQ) != 0) {
|
||||
TAILQ_REMOVE(&p->l_head,curthread,qe);
|
||||
curthread->flags &= ~PTHREAD_FLAGS_IN_FILEQ;
|
||||
}
|
||||
|
||||
_thread_kern_sig_undefer();
|
||||
|
||||
if (_thread_run->interrupted != 0 &&
|
||||
_thread_run->continuation != NULL)
|
||||
_thread_run->continuation((void *)_thread_run);
|
||||
if (curthread->interrupted != 0 &&
|
||||
curthread->continuation != NULL)
|
||||
curthread->continuation((void *)curthread);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,6 +274,7 @@ _flockfile(FILE * fp)
|
||||
int
|
||||
_ftrylockfile(FILE * fp)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret = -1;
|
||||
int idx = file_idx(fp);
|
||||
struct file_lock *p;
|
||||
@ -294,7 +296,7 @@ _ftrylockfile(FILE * fp)
|
||||
* The file is already locked, so check if the
|
||||
* running thread is the owner:
|
||||
*/
|
||||
} else if (p->owner == _thread_run) {
|
||||
} else if (p->owner == curthread) {
|
||||
/*
|
||||
* The running thread is already the
|
||||
* owner, so increment the count of
|
||||
@ -325,6 +327,7 @@ _ftrylockfile(FILE * fp)
|
||||
void
|
||||
_funlockfile(FILE * fp)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int idx = file_idx(fp);
|
||||
struct file_lock *p;
|
||||
|
||||
@ -344,7 +347,7 @@ _funlockfile(FILE * fp)
|
||||
* the running thread is the one with the lock:
|
||||
*/
|
||||
if ((p = find_lock(idx, fp)) != NULL &&
|
||||
p->owner == _thread_run) {
|
||||
p->owner == curthread) {
|
||||
/*
|
||||
* Check if this thread has locked the FILE
|
||||
* more than once:
|
||||
@ -503,4 +506,3 @@ _flockfile_backout(pthread_t pthread)
|
||||
_thread_kern_sig_undefer();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -32,7 +32,6 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -97,4 +96,3 @@ _find_dead_thread(pthread_t pthread)
|
||||
/* Return zero if the thread exists: */
|
||||
return ((pthread1 != NULL) ? 0:ESRCH);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,21 +32,19 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <sys/file.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak flock=_flock
|
||||
|
||||
int
|
||||
_flock(int fd, int operation)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_flock(fd, operation);
|
||||
ret = __sys_flock(fd, operation);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_flock, flock);
|
||||
#endif
|
||||
|
@ -36,13 +36,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fork=_fork
|
||||
|
||||
pid_t
|
||||
_fork(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int i, flags;
|
||||
pid_t ret;
|
||||
pthread_t pthread;
|
||||
@ -55,42 +57,42 @@ _fork(void)
|
||||
_thread_kern_sig_defer();
|
||||
|
||||
/* Fork a new process: */
|
||||
if ((ret = _thread_sys_fork()) != 0) {
|
||||
if ((ret = __sys_fork()) != 0) {
|
||||
/* Parent process or error. Nothing to do here. */
|
||||
} else {
|
||||
/* Close the pthread kernel pipe: */
|
||||
_thread_sys_close(_thread_kern_pipe[0]);
|
||||
_thread_sys_close(_thread_kern_pipe[1]);
|
||||
__sys_close(_thread_kern_pipe[0]);
|
||||
__sys_close(_thread_kern_pipe[1]);
|
||||
|
||||
/* Reset signals pending for the running thread: */
|
||||
sigemptyset(&_thread_run->sigpend);
|
||||
sigemptyset(&curthread->sigpend);
|
||||
|
||||
/*
|
||||
* Create a pipe that is written to by the signal handler to
|
||||
* prevent signals being missed in calls to
|
||||
* _thread_sys_select:
|
||||
* __sys_select:
|
||||
*/
|
||||
if (_thread_sys_pipe(_thread_kern_pipe) != 0) {
|
||||
if (__sys_pipe(_thread_kern_pipe) != 0) {
|
||||
/* Cannot create pipe, so abort: */
|
||||
PANIC("Cannot create pthread kernel pipe for forked process");
|
||||
}
|
||||
/* Get the flags for the read pipe: */
|
||||
else if ((flags = _thread_sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
|
||||
else if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
|
||||
/* Abort this application: */
|
||||
abort();
|
||||
}
|
||||
/* Make the read pipe non-blocking: */
|
||||
else if (_thread_sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
/* Abort this application: */
|
||||
abort();
|
||||
}
|
||||
/* Get the flags for the write pipe: */
|
||||
else if ((flags = _thread_sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
|
||||
else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
|
||||
/* Abort this application: */
|
||||
abort();
|
||||
}
|
||||
/* Make the write pipe non-blocking: */
|
||||
else if (_thread_sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
/* Abort this application: */
|
||||
abort();
|
||||
}
|
||||
@ -125,7 +127,7 @@ _fork(void)
|
||||
pthread = TAILQ_NEXT(pthread, dle);
|
||||
|
||||
/* Make sure this isn't the running thread: */
|
||||
if (pthread_save != _thread_run) {
|
||||
if (pthread_save != curthread) {
|
||||
/* Remove this thread from the list: */
|
||||
TAILQ_REMOVE(&_thread_list,
|
||||
pthread_save, tle);
|
||||
@ -165,7 +167,7 @@ _fork(void)
|
||||
}
|
||||
|
||||
/* Treat the current thread as the initial thread: */
|
||||
_thread_initial = _thread_run;
|
||||
_thread_initial = curthread;
|
||||
|
||||
/* Re-init the dead thread list: */
|
||||
TAILQ_INIT(&_dead_list);
|
||||
@ -175,7 +177,7 @@ _fork(void)
|
||||
TAILQ_INIT(&_workq);
|
||||
|
||||
/* Re-init the threads mutex queue: */
|
||||
TAILQ_INIT(&_thread_run->mutexq);
|
||||
TAILQ_INIT(&curthread->mutexq);
|
||||
|
||||
/* No spinlocks yet: */
|
||||
_spinblock_count = 0;
|
||||
@ -217,6 +219,3 @@ _fork(void)
|
||||
/* Return the process ID: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_fork, fork);
|
||||
#endif
|
||||
|
@ -26,21 +26,20 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fpathconf=_fpathconf
|
||||
|
||||
long
|
||||
_fpathconf(int fd, int name)
|
||||
{
|
||||
long ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
ret = _thread_sys_fpathconf(fd, name);
|
||||
ret = __sys_fpathconf(fd, name);
|
||||
_FD_UNLOCK(fd, FD_READ);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_reference(_fpathconf, fpathconf);
|
||||
#endif
|
||||
|
@ -37,10 +37,11 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fstat=_fstat
|
||||
|
||||
int
|
||||
_fstat(int fd, struct stat * buf)
|
||||
{
|
||||
@ -49,12 +50,10 @@ _fstat(int fd, struct stat * buf)
|
||||
/* Lock the file descriptor for read: */
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
/* Get the file status: */
|
||||
ret = _thread_sys_fstat(fd, buf);
|
||||
ret = __sys_fstat(fd, buf);
|
||||
/* Unlock the file descriptor: */
|
||||
_FD_UNLOCK(fd, FD_READ);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_fstat, fstat);
|
||||
#endif
|
||||
|
@ -37,10 +37,11 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fstatfs=_fstatfs
|
||||
|
||||
int
|
||||
_fstatfs(int fd, struct statfs * buf)
|
||||
{
|
||||
@ -49,12 +50,9 @@ _fstatfs(int fd, struct statfs * buf)
|
||||
/* Lock the file descriptor for read: */
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
/* Get the file system status: */
|
||||
ret = _thread_sys_fstatfs(fd, buf);
|
||||
ret = __sys_fstatfs(fd, buf);
|
||||
/* Unlock the file descriptor: */
|
||||
_FD_UNLOCK(fd, FD_READ);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_fstatfs, fstatfs);
|
||||
#endif
|
||||
|
@ -32,24 +32,25 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak fsync=__fsync
|
||||
|
||||
int
|
||||
_fsync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_fsync(fd);
|
||||
ret = __sys_fsync(fd);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
fsync(int fd)
|
||||
__fsync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -59,4 +60,3 @@ fsync(int fd)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -47,6 +47,7 @@
|
||||
pthread_addr_t
|
||||
_thread_gc(pthread_addr_t arg)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int f_debug;
|
||||
int f_done = 0;
|
||||
int ret;
|
||||
@ -61,13 +62,13 @@ _thread_gc(pthread_addr_t arg)
|
||||
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
||||
|
||||
/* Mark this thread as a library thread (not a user thread). */
|
||||
_thread_run->flags |= PTHREAD_FLAGS_PRIVATE;
|
||||
curthread->flags |= PTHREAD_FLAGS_PRIVATE;
|
||||
|
||||
/* Set a debug flag based on an environment variable. */
|
||||
f_debug = (getenv("LIBC_R_DEBUG") != NULL);
|
||||
|
||||
/* Set the name of this thread. */
|
||||
pthread_set_name_np(_thread_run,"GC");
|
||||
pthread_set_name_np(curthread,"GC");
|
||||
|
||||
while (!f_done) {
|
||||
/* Check if debugging this application. */
|
||||
@ -82,8 +83,8 @@ _thread_gc(pthread_addr_t arg)
|
||||
_thread_kern_sig_defer();
|
||||
|
||||
/* Check if this is the last running thread: */
|
||||
if (TAILQ_FIRST(&_thread_list) == _thread_run &&
|
||||
TAILQ_NEXT(_thread_run, tle) == NULL)
|
||||
if (TAILQ_FIRST(&_thread_list) == curthread &&
|
||||
TAILQ_NEXT(curthread, tle) == NULL)
|
||||
/*
|
||||
* This is the last thread, so it can exit
|
||||
* now.
|
||||
|
@ -33,21 +33,19 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak getdirentries=_getdirentries
|
||||
|
||||
int
|
||||
_getdirentries(int fd, char *buf, int nbytes, long *basep)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_getdirentries(fd, buf, nbytes, basep);
|
||||
ret = __sys_getdirentries(fd, buf, nbytes, basep);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_getdirentries, getdirentries);
|
||||
#endif
|
||||
|
@ -33,21 +33,20 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak getpeername=_getpeername
|
||||
|
||||
int
|
||||
_getpeername(int fd, struct sockaddr * peer, socklen_t *paddrlen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
ret = _thread_sys_getpeername(fd, peer, paddrlen);
|
||||
ret = __sys_getpeername(fd, peer, paddrlen);
|
||||
_FD_UNLOCK(fd, FD_READ);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_reference(_getpeername, getpeername);
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_getprio=_pthread_getprio
|
||||
|
||||
int
|
||||
pthread_getprio(pthread_t pthread)
|
||||
_pthread_getprio(pthread_t pthread)
|
||||
{
|
||||
int policy, ret;
|
||||
struct sched_param param;
|
||||
@ -53,4 +54,3 @@ pthread_getprio(pthread_t pthread)
|
||||
/* Return the thread priority or an error status: */
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,13 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_getschedparam=_pthread_getschedparam
|
||||
|
||||
int
|
||||
pthread_getschedparam(pthread_t pthread, int *policy,
|
||||
_pthread_getschedparam(pthread_t pthread, int *policy,
|
||||
struct sched_param *param)
|
||||
{
|
||||
int ret;
|
||||
@ -56,4 +57,3 @@ pthread_getschedparam(pthread_t pthread, int *policy,
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,21 +33,19 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak getsockname=_getsockname
|
||||
|
||||
int
|
||||
_getsockname(int s, struct sockaddr * name, socklen_t *namelen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(s, FD_READ, NULL)) == 0) {
|
||||
ret = _thread_sys_getsockname(s, name, namelen);
|
||||
ret = __sys_getsockname(s, name, namelen);
|
||||
_FD_UNLOCK(s, FD_READ);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_reference(_getsockname, getsockname);
|
||||
#endif
|
||||
|
@ -33,10 +33,11 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak getsockopt=_getsockopt
|
||||
|
||||
int
|
||||
_getsockopt(int fd, int level, int optname, void *optval, socklen_t
|
||||
*optlen)
|
||||
@ -44,11 +45,8 @@ _getsockopt(int fd, int level, int optname, void *optval, socklen_t
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_getsockopt(fd, level, optname, optval, optlen);
|
||||
ret = __sys_getsockopt(fd, level, optname, optval, optlen);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_reference(_getsockopt, getsockopt);
|
||||
#endif
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include "pthread_private.h"
|
||||
@ -47,6 +46,7 @@
|
||||
|
||||
static void dump_thread(int fd, pthread_t pthread, int long_version);
|
||||
|
||||
#pragma weak pthread_set_name_np=_pthread_set_name_np
|
||||
|
||||
struct s_thread_info {
|
||||
enum pthread_state state;
|
||||
@ -92,7 +92,7 @@ _thread_dump_info(void)
|
||||
snprintf(tmpfile, sizeof(tmpfile), "/tmp/uthread.dump.%u.%i",
|
||||
getpid(), i);
|
||||
/* Open the dump file for append and create it if necessary: */
|
||||
if ((fd = _thread_sys_open(tmpfile, O_RDWR | O_CREAT | O_EXCL,
|
||||
if ((fd = __sys_open(tmpfile, O_RDWR | O_CREAT | O_EXCL,
|
||||
0666)) < 0) {
|
||||
/* Can't open the dump file. */
|
||||
if (errno == EEXIST)
|
||||
@ -114,7 +114,7 @@ _thread_dump_info(void)
|
||||
} else {
|
||||
/* Output a header for active threads: */
|
||||
strcpy(s, "\n\n=============\nACTIVE THREADS\n\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
/* Enter a loop to report each thread in the global list: */
|
||||
TAILQ_FOREACH(pthread, &_thread_list, tle) {
|
||||
@ -123,7 +123,7 @@ _thread_dump_info(void)
|
||||
|
||||
/* Output a header for ready threads: */
|
||||
strcpy(s, "\n\n=============\nREADY THREADS\n\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
/* Enter a loop to report each thread in the ready queue: */
|
||||
TAILQ_FOREACH (pq_list, &_readyq.pq_queue, pl_link) {
|
||||
@ -134,7 +134,7 @@ _thread_dump_info(void)
|
||||
|
||||
/* Output a header for waiting threads: */
|
||||
strcpy(s, "\n\n=============\nWAITING THREADS\n\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
/* Enter a loop to report each thread in the waiting queue: */
|
||||
TAILQ_FOREACH (pthread, &_waitingq, pqe) {
|
||||
@ -143,7 +143,7 @@ _thread_dump_info(void)
|
||||
|
||||
/* Output a header for threads in the work queue: */
|
||||
strcpy(s, "\n\n=============\nTHREADS IN WORKQ\n\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
/* Enter a loop to report each thread in the waiting queue: */
|
||||
TAILQ_FOREACH (pthread, &_workq, qe) {
|
||||
@ -154,11 +154,11 @@ _thread_dump_info(void)
|
||||
if (TAILQ_FIRST(&_dead_list) == NULL) {
|
||||
/* Output a record: */
|
||||
strcpy(s, "\n\nTHERE ARE NO DEAD THREADS\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
} else {
|
||||
/* Output a header for dead threads: */
|
||||
strcpy(s, "\n\nDEAD THREADS\n\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
/*
|
||||
* Enter a loop to report each thread in the global
|
||||
@ -172,7 +172,7 @@ _thread_dump_info(void)
|
||||
/* Output a header for file descriptors: */
|
||||
snprintf(s, sizeof(s), "\n\n=============\nFILE DESCRIPTOR "
|
||||
"TABLE (table size %d)\n\n", _thread_dtablesize);
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
/* Enter a loop to report file descriptor lock usage: */
|
||||
for (i = 0; i < _thread_dtablesize; i++) {
|
||||
@ -193,18 +193,19 @@ _thread_dump_info(void)
|
||||
_thread_fd_table[i]->w_lockcount,
|
||||
_thread_fd_table[i]->w_fname,
|
||||
_thread_fd_table[i]->w_lineno);
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the dump file: */
|
||||
_thread_sys_close(fd);
|
||||
__sys_close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dump_thread(int fd, pthread_t pthread, int long_version)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
char s[512];
|
||||
int i;
|
||||
|
||||
@ -219,20 +220,20 @@ dump_thread(int fd, pthread_t pthread, int long_version)
|
||||
pthread, (pthread->name == NULL) ? "" : pthread->name,
|
||||
pthread->active_priority, thread_info[i].name, pthread->fname,
|
||||
pthread->lineno);
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
|
||||
if (long_version != 0) {
|
||||
/* Check if this is the running thread: */
|
||||
if (pthread == _thread_run) {
|
||||
if (pthread == curthread) {
|
||||
/* Output a record for the running thread: */
|
||||
strcpy(s, "This is the running thread\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
}
|
||||
/* Check if this is the initial thread: */
|
||||
if (pthread == _thread_initial) {
|
||||
/* Output a record for the initial thread: */
|
||||
strcpy(s, "This is the initial thread\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
}
|
||||
/* Process according to thread state: */
|
||||
switch (pthread->state) {
|
||||
@ -246,22 +247,22 @@ dump_thread(int fd, pthread_t pthread, int long_version)
|
||||
pthread->data.fd.fd,
|
||||
pthread->data.fd.fname,
|
||||
pthread->data.fd.branch);
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
snprintf(s, sizeof(s), "owner %pr/%pw\n",
|
||||
_thread_fd_table[pthread->data.fd.fd]->r_owner,
|
||||
_thread_fd_table[pthread->data.fd.fd]->w_owner);
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
break;
|
||||
case PS_SIGWAIT:
|
||||
snprintf(s, sizeof(s), "sigmask (hi)");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
for (i = _SIG_WORDS - 1; i >= 0; i--) {
|
||||
snprintf(s, sizeof(s), "%08x\n",
|
||||
pthread->sigmask.__bits[i]);
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
}
|
||||
snprintf(s, sizeof(s), "(lo)\n");
|
||||
_thread_sys_write(fd, s, strlen(s));
|
||||
__sys_write(fd, s, strlen(s));
|
||||
break;
|
||||
/*
|
||||
* Trap other states that are not explicitly
|
||||
@ -276,7 +277,7 @@ dump_thread(int fd, pthread_t pthread, int long_version)
|
||||
|
||||
/* Set the thread name for debug: */
|
||||
void
|
||||
pthread_set_name_np(pthread_t thread, char *name)
|
||||
_pthread_set_name_np(pthread_t thread, char *name)
|
||||
{
|
||||
/* Check if the caller has specified a valid thread: */
|
||||
if (thread != NULL && thread->magic == PTHREAD_MAGIC) {
|
||||
@ -287,4 +288,3 @@ pthread_set_name_np(pthread_t thread, char *name)
|
||||
thread->name = strdup(name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -35,74 +35,117 @@
|
||||
/* Allocate space for global thread variables here: */
|
||||
#define GLOBAL_PTHREAD_PRIVATE
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#include "namespace.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <machine/reg.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ttycom.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/mman.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <machine/reg.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "pthread_private.h"
|
||||
|
||||
/*
|
||||
* All weak references used within libc should be in this table.
|
||||
* This will is so that static libraries will work.
|
||||
*/
|
||||
static void *references[] = {
|
||||
&_accept,
|
||||
&_bind,
|
||||
&_close,
|
||||
&_connect,
|
||||
&_dup,
|
||||
&_dup2,
|
||||
&_execve,
|
||||
&_fcntl,
|
||||
&_flock,
|
||||
&_flockfile,
|
||||
&_fstat,
|
||||
&_fstatfs,
|
||||
&_fsync,
|
||||
&_funlockfile,
|
||||
&_getdirentries,
|
||||
&_getlogin,
|
||||
&_getpeername,
|
||||
&_getsockname,
|
||||
&_getsockopt,
|
||||
&_ioctl,
|
||||
&_kevent,
|
||||
&_listen,
|
||||
&_nanosleep,
|
||||
&_open,
|
||||
&_pthread_getspecific,
|
||||
&_pthread_key_create,
|
||||
&_pthread_key_delete,
|
||||
&_pthread_mutex_destroy,
|
||||
&_pthread_mutex_init,
|
||||
&_pthread_mutex_lock,
|
||||
&_pthread_mutex_trylock,
|
||||
&_pthread_mutex_unlock,
|
||||
&_pthread_mutexattr_init,
|
||||
&_pthread_mutexattr_destroy,
|
||||
&_pthread_mutexattr_settype,
|
||||
&_pthread_once,
|
||||
&_pthread_setspecific,
|
||||
&_read,
|
||||
&_readv,
|
||||
&_recvfrom,
|
||||
&_recvmsg,
|
||||
&_select,
|
||||
&_sendmsg,
|
||||
&_sendto,
|
||||
&_setsockopt,
|
||||
&_sigaction,
|
||||
&_sigprocmask,
|
||||
&_sigsuspend,
|
||||
&_socket,
|
||||
&_socketpair,
|
||||
&_wait4,
|
||||
&_write,
|
||||
&_writev
|
||||
};
|
||||
|
||||
/*
|
||||
* These are needed when linking statically. All references within
|
||||
* libgcc (and in the future libc) to these routines are weak, but
|
||||
* if they are not (strongly) referenced by the application or other
|
||||
* libraries, then the actual functions will not be loaded.
|
||||
*/
|
||||
static void *thread_references[] = {
|
||||
&pthread_once,
|
||||
&pthread_key_create,
|
||||
&pthread_key_delete,
|
||||
&pthread_getspecific,
|
||||
&pthread_setspecific,
|
||||
&pthread_mutex_init,
|
||||
&pthread_mutex_destroy,
|
||||
&pthread_mutex_lock,
|
||||
&pthread_mutex_trylock,
|
||||
&pthread_mutex_unlock,
|
||||
&pthread_cond_init,
|
||||
&pthread_cond_destroy,
|
||||
&pthread_cond_wait,
|
||||
&pthread_cond_timedwait,
|
||||
&pthread_cond_signal,
|
||||
&pthread_cond_broadcast
|
||||
static void *libgcc_references[] = {
|
||||
&_pthread_once,
|
||||
&_pthread_key_create,
|
||||
&_pthread_key_delete,
|
||||
&_pthread_getspecific,
|
||||
&_pthread_setspecific,
|
||||
&_pthread_mutex_init,
|
||||
&_pthread_mutex_destroy,
|
||||
&_pthread_mutex_lock,
|
||||
&_pthread_mutex_trylock,
|
||||
&_pthread_mutex_unlock
|
||||
};
|
||||
|
||||
#ifdef GCC_2_8_MADE_THREAD_AWARE
|
||||
typedef void *** (*dynamic_handler_allocator)();
|
||||
extern void __set_dynamic_handler_allocator(dynamic_handler_allocator);
|
||||
|
||||
static pthread_key_t except_head_key;
|
||||
|
||||
typedef struct {
|
||||
void **__dynamic_handler_chain;
|
||||
void *top_elt[2];
|
||||
} except_struct;
|
||||
|
||||
static void ***dynamic_allocator_handler_fn()
|
||||
{
|
||||
except_struct *dh = (except_struct *)pthread_getspecific(except_head_key);
|
||||
|
||||
if(dh == NULL) {
|
||||
dh = (except_struct *)malloc( sizeof(except_struct) );
|
||||
memset(dh, '\0', sizeof(except_struct));
|
||||
dh->__dynamic_handler_chain= dh->top_elt;
|
||||
pthread_setspecific(except_head_key, (void *)dh);
|
||||
}
|
||||
return &dh->__dynamic_handler_chain;
|
||||
}
|
||||
#endif /* GCC_2_8_MADE_THREAD_AWARE */
|
||||
|
||||
/*
|
||||
* Threaded process initialization
|
||||
@ -124,11 +167,11 @@ _thread_init(void)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Make gcc quiescent about thread_references not being
|
||||
* Make gcc quiescent about {,libgcc_}references not being
|
||||
* referenced:
|
||||
*/
|
||||
if (thread_references[0] == NULL)
|
||||
PANIC("Mandatory pthread_* functions not loaded");
|
||||
if ((references[0] == NULL) || (libgcc_references[0] == NULL))
|
||||
PANIC("Failed loading mandatory references in _thread_init");
|
||||
|
||||
/*
|
||||
* Check for the special case of this process running as
|
||||
@ -143,22 +186,22 @@ _thread_init(void)
|
||||
PANIC("Can't set session ID");
|
||||
if (revoke(_PATH_CONSOLE) != 0)
|
||||
PANIC("Can't revoke console");
|
||||
if ((fd = _thread_sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
|
||||
if ((fd = __sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
|
||||
PANIC("Can't open console");
|
||||
if (setlogin("root") == -1)
|
||||
PANIC("Can't set login to root");
|
||||
if (_thread_sys_ioctl(fd,TIOCSCTTY, (char *) NULL) == -1)
|
||||
if (__sys_ioctl(fd,TIOCSCTTY, (char *) NULL) == -1)
|
||||
PANIC("Can't set controlling terminal");
|
||||
if (_thread_sys_dup2(fd,0) == -1 ||
|
||||
_thread_sys_dup2(fd,1) == -1 ||
|
||||
_thread_sys_dup2(fd,2) == -1)
|
||||
if (__sys_dup2(fd,0) == -1 ||
|
||||
__sys_dup2(fd,1) == -1 ||
|
||||
__sys_dup2(fd,2) == -1)
|
||||
PANIC("Can't dup2");
|
||||
}
|
||||
|
||||
/* Get the standard I/O flags before messing with them : */
|
||||
for (i = 0; i < 3; i++)
|
||||
if (((_pthread_stdio_flags[i] =
|
||||
_thread_sys_fcntl(i,F_GETFL, NULL)) == -1) &&
|
||||
__sys_fcntl(i,F_GETFL, NULL)) == -1) &&
|
||||
(errno != EBADF))
|
||||
PANIC("Cannot get stdio flags");
|
||||
|
||||
@ -166,27 +209,27 @@ _thread_init(void)
|
||||
* Create a pipe that is written to by the signal handler to prevent
|
||||
* signals being missed in calls to _select:
|
||||
*/
|
||||
if (_thread_sys_pipe(_thread_kern_pipe) != 0) {
|
||||
if (__sys_pipe(_thread_kern_pipe) != 0) {
|
||||
/* Cannot create pipe, so abort: */
|
||||
PANIC("Cannot create kernel pipe");
|
||||
}
|
||||
/* Get the flags for the read pipe: */
|
||||
else if ((flags = _thread_sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
|
||||
else if ((flags = __sys_fcntl(_thread_kern_pipe[0], F_GETFL, NULL)) == -1) {
|
||||
/* Abort this application: */
|
||||
PANIC("Cannot get kernel read pipe flags");
|
||||
}
|
||||
/* Make the read pipe non-blocking: */
|
||||
else if (_thread_sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
else if (__sys_fcntl(_thread_kern_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
/* Abort this application: */
|
||||
PANIC("Cannot make kernel read pipe non-blocking");
|
||||
}
|
||||
/* Get the flags for the write pipe: */
|
||||
else if ((flags = _thread_sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
|
||||
else if ((flags = __sys_fcntl(_thread_kern_pipe[1], F_GETFL, NULL)) == -1) {
|
||||
/* Abort this application: */
|
||||
PANIC("Cannot get kernel write pipe flags");
|
||||
}
|
||||
/* Make the write pipe non-blocking: */
|
||||
else if (_thread_sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
else if (__sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
/* Abort this application: */
|
||||
PANIC("Cannot get kernel write pipe flags");
|
||||
}
|
||||
@ -270,6 +313,9 @@ _thread_init(void)
|
||||
/* Initialise the state of the initial thread: */
|
||||
_thread_initial->state = PS_RUNNING;
|
||||
|
||||
/* Set the name of the thread: */
|
||||
_thread_initial->name = strdup("_thread_initial");
|
||||
|
||||
/* Initialise the queue: */
|
||||
TAILQ_INIT(&(_thread_initial->join_queue));
|
||||
|
||||
@ -299,7 +345,7 @@ _thread_init(void)
|
||||
_thread_initial->error = 0;
|
||||
TAILQ_INIT(&_thread_list);
|
||||
TAILQ_INSERT_HEAD(&_thread_list, _thread_initial, tle);
|
||||
_thread_run = _thread_initial;
|
||||
_set_curthread(_thread_initial);
|
||||
|
||||
/* Initialise the global signal action structure: */
|
||||
sigfillset(&act.sa_mask);
|
||||
@ -320,7 +366,7 @@ _thread_init(void)
|
||||
_thread_sigstack.ss_size = SIGSTKSZ;
|
||||
_thread_sigstack.ss_flags = 0;
|
||||
if ((_thread_sigstack.ss_sp == NULL) ||
|
||||
(_thread_sys_sigaltstack(&_thread_sigstack, NULL) != 0))
|
||||
(__sys_sigaltstack(&_thread_sigstack, NULL) != 0))
|
||||
PANIC("Unable to install alternate signal stack");
|
||||
|
||||
/* Enter a loop to get the existing signal status: */
|
||||
@ -330,7 +376,7 @@ _thread_init(void)
|
||||
}
|
||||
|
||||
/* Get the signal handler details: */
|
||||
else if (_thread_sys_sigaction(i, NULL,
|
||||
else if (__sys_sigaction(i, NULL,
|
||||
&_thread_sigact[i - 1]) != 0) {
|
||||
/*
|
||||
* Abort this process if signal
|
||||
@ -348,9 +394,9 @@ _thread_init(void)
|
||||
* signals that the user-thread kernel needs. Actually
|
||||
* SIGINFO isn't really needed, but it is nice to have.
|
||||
*/
|
||||
if (_thread_sys_sigaction(_SCHED_SIGNAL, &act, NULL) != 0 ||
|
||||
_thread_sys_sigaction(SIGINFO, &act, NULL) != 0 ||
|
||||
_thread_sys_sigaction(SIGCHLD, &act, NULL) != 0) {
|
||||
if (__sys_sigaction(_SCHED_SIGNAL, &act, NULL) != 0 ||
|
||||
__sys_sigaction(SIGINFO, &act, NULL) != 0 ||
|
||||
__sys_sigaction(SIGCHLD, &act, NULL) != 0) {
|
||||
/*
|
||||
* Abort this process if signal initialisation fails:
|
||||
*/
|
||||
@ -361,7 +407,7 @@ _thread_init(void)
|
||||
_thread_sigact[SIGCHLD - 1].sa_flags = SA_SIGINFO;
|
||||
|
||||
/* Get the process signal mask: */
|
||||
_thread_sys_sigprocmask(SIG_SETMASK, NULL, &_process_sigmask);
|
||||
__sys_sigprocmask(SIG_SETMASK, NULL, &_process_sigmask);
|
||||
|
||||
/* Get the kernel clockrate: */
|
||||
mib[0] = CTL_KERN;
|
||||
@ -416,17 +462,8 @@ _thread_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GCC_2_8_MADE_THREAD_AWARE
|
||||
/* Create the thread-specific data for the exception linked list. */
|
||||
if(pthread_key_create(&except_head_key, NULL) != 0)
|
||||
PANIC("Failed to create thread specific execption head");
|
||||
|
||||
/* Setup the gcc exception handler per thread. */
|
||||
__set_dynamic_handler_allocator( dynamic_allocator_handler_fn );
|
||||
#endif /* GCC_2_8_MADE_THREAD_AWARE */
|
||||
|
||||
/* Initialise the garbage collector mutex and condition variable. */
|
||||
if (pthread_mutex_init(&_gc_mutex,NULL) != 0 ||
|
||||
if (_pthread_mutex_init(&_gc_mutex,NULL) != 0 ||
|
||||
pthread_cond_init(&_gc_cond,NULL) != 0)
|
||||
PANIC("Failed to initialise garbage collector mutex or condvar");
|
||||
}
|
||||
@ -445,12 +482,3 @@ _thread_main(int argc, char *argv[], char *env)
|
||||
return (main(argc, argv, env));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
/*
|
||||
* A stub for non-threaded programs.
|
||||
*/
|
||||
void
|
||||
_thread_init(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
@ -33,11 +33,12 @@
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <sys/fcntl.h> /* O_NONBLOCK*/
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak ioctl=_ioctl
|
||||
|
||||
int
|
||||
_ioctl(int fd, unsigned long request,...)
|
||||
{
|
||||
@ -62,7 +63,7 @@ _ioctl(int fd, unsigned long request,...)
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
ret = _thread_sys_ioctl(fd, request, va_arg(ap, char *));
|
||||
ret = __sys_ioctl(fd, request, va_arg(ap, char *));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -76,6 +77,3 @@ _ioctl(int fd, unsigned long request,...)
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_ioctl, ioctl);
|
||||
#endif
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include <setjmp.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/user.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <machine/reg.h>
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
@ -43,10 +42,16 @@
|
||||
/* Prototypes: */
|
||||
static inline int check_stack(pthread_t thread, void *stackp);
|
||||
|
||||
#pragma weak siglongjmp=_thread_siglongjmp
|
||||
#pragma weak longjmp=_thread_longjmp
|
||||
#pragma weak _longjmp=__thread_longjmp
|
||||
|
||||
void
|
||||
siglongjmp(sigjmp_buf env, int savemask)
|
||||
_thread_siglongjmp(sigjmp_buf env, int savemask)
|
||||
{
|
||||
if (check_stack(_thread_run, (void *) GET_STACK_SJB(env)))
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
if (check_stack(curthread, (void *) GET_STACK_SJB(env)))
|
||||
PANIC("siglongjmp()ing between thread contexts is undefined by "
|
||||
"POSIX 1003.1");
|
||||
|
||||
@ -58,9 +63,11 @@ siglongjmp(sigjmp_buf env, int savemask)
|
||||
}
|
||||
|
||||
void
|
||||
longjmp(jmp_buf env, int val)
|
||||
_thread_longjmp(jmp_buf env, int val)
|
||||
{
|
||||
if (check_stack(_thread_run, (void *) GET_STACK_JB(env)))
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
if (check_stack(curthread, (void *) GET_STACK_JB(env)))
|
||||
PANIC("longjmp()ing between thread contexts is undefined by "
|
||||
"POSIX 1003.1");
|
||||
|
||||
@ -72,9 +79,11 @@ longjmp(jmp_buf env, int val)
|
||||
}
|
||||
|
||||
void
|
||||
_longjmp(jmp_buf env, int val)
|
||||
__thread_longjmp(jmp_buf env, int val)
|
||||
{
|
||||
if (check_stack(_thread_run, (void *) GET_STACK_JB(env)))
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
if (check_stack(curthread, (void *) GET_STACK_JB(env)))
|
||||
PANIC("_longjmp()ing between thread contexts is undefined by "
|
||||
"POSIX 1003.1");
|
||||
|
||||
@ -108,4 +117,3 @@ check_stack(pthread_t thread, void *stackp)
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,13 +32,15 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_join=_pthread_join
|
||||
|
||||
int
|
||||
pthread_join(pthread_t pthread, void **thread_return)
|
||||
_pthread_join(pthread_t pthread, void **thread_return)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret = 0;
|
||||
|
||||
_thread_enter_cancellation_point();
|
||||
@ -51,7 +53,7 @@ pthread_join(pthread_t pthread, void **thread_return)
|
||||
}
|
||||
|
||||
/* Check if the caller has specified itself: */
|
||||
if (pthread == _thread_run) {
|
||||
if (pthread == curthread) {
|
||||
/* Avoid a deadlock condition: */
|
||||
_thread_leave_cancellation_point();
|
||||
return(EDEADLK);
|
||||
@ -72,7 +74,7 @@ pthread_join(pthread_t pthread, void **thread_return)
|
||||
|
||||
/* Check if the thread is not dead: */
|
||||
else if (pthread->state != PS_DEAD) {
|
||||
PTHREAD_ASSERT_NOT_IN_SYNCQ(_thread_run);
|
||||
PTHREAD_ASSERT_NOT_IN_SYNCQ(curthread);
|
||||
|
||||
/*
|
||||
* Enter a loop in case this thread is woken prematurely
|
||||
@ -80,7 +82,7 @@ pthread_join(pthread_t pthread, void **thread_return)
|
||||
*/
|
||||
for (;;) {
|
||||
/* Clear the interrupted flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Protect against being context switched out while
|
||||
@ -90,25 +92,25 @@ pthread_join(pthread_t pthread, void **thread_return)
|
||||
|
||||
/* Add the running thread to the join queue: */
|
||||
TAILQ_INSERT_TAIL(&(pthread->join_queue),
|
||||
_thread_run, sqe);
|
||||
_thread_run->flags |= PTHREAD_FLAGS_IN_JOINQ;
|
||||
_thread_run->data.thread = pthread;
|
||||
curthread, sqe);
|
||||
curthread->flags |= PTHREAD_FLAGS_IN_JOINQ;
|
||||
curthread->data.thread = pthread;
|
||||
|
||||
/* Schedule the next thread: */
|
||||
_thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__);
|
||||
|
||||
if ((_thread_run->flags & PTHREAD_FLAGS_IN_JOINQ) != 0) {
|
||||
if ((curthread->flags & PTHREAD_FLAGS_IN_JOINQ) != 0) {
|
||||
TAILQ_REMOVE(&(pthread->join_queue),
|
||||
_thread_run, sqe);
|
||||
_thread_run->flags &= ~PTHREAD_FLAGS_IN_JOINQ;
|
||||
curthread, sqe);
|
||||
curthread->flags &= ~PTHREAD_FLAGS_IN_JOINQ;
|
||||
}
|
||||
_thread_run->data.thread = NULL;
|
||||
curthread->data.thread = NULL;
|
||||
|
||||
_thread_kern_sig_undefer();
|
||||
|
||||
if (_thread_run->interrupted != 0) {
|
||||
if (_thread_run->continuation != NULL)
|
||||
_thread_run->continuation(_thread_run);
|
||||
if (curthread->interrupted != 0) {
|
||||
if (curthread->continuation != NULL)
|
||||
curthread->continuation(curthread);
|
||||
/*
|
||||
* This thread was interrupted, probably to
|
||||
* invoke a signal handler. Make sure the
|
||||
@ -134,9 +136,9 @@ pthread_join(pthread_t pthread, void **thread_return)
|
||||
* by the thread we're joining to when it
|
||||
* exits or detaches:
|
||||
*/
|
||||
ret = _thread_run->error;
|
||||
ret = curthread->error;
|
||||
if ((ret == 0) && (thread_return != NULL))
|
||||
*thread_return = _thread_run->ret;
|
||||
*thread_return = curthread->ret;
|
||||
|
||||
/* We're done; break out of the loop. */
|
||||
break;
|
||||
@ -156,11 +158,12 @@ pthread_join(pthread_t pthread, void **thread_return)
|
||||
void
|
||||
_join_backout(pthread_t pthread)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
_thread_kern_sig_defer();
|
||||
if ((pthread->flags & PTHREAD_FLAGS_IN_JOINQ) != 0) {
|
||||
TAILQ_REMOVE(&pthread->data.thread->join_queue, pthread, sqe);
|
||||
_thread_run->flags &= ~PTHREAD_FLAGS_IN_JOINQ;
|
||||
curthread->flags &= ~PTHREAD_FLAGS_IN_JOINQ;
|
||||
}
|
||||
_thread_kern_sig_undefer();
|
||||
}
|
||||
#endif
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include <sys/uio.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -80,6 +79,8 @@ static int called_from_handler = 0;
|
||||
void
|
||||
_thread_kern_sched_frame(struct pthread_signal_frame *psf)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/*
|
||||
* Flag the pthread kernel as executing scheduler code
|
||||
* to avoid a signal from interrupting this execution and
|
||||
@ -88,10 +89,10 @@ _thread_kern_sched_frame(struct pthread_signal_frame *psf)
|
||||
_thread_kern_in_sched = 1;
|
||||
|
||||
/* Restore the signal frame: */
|
||||
_thread_sigframe_restore(_thread_run, psf);
|
||||
_thread_sigframe_restore(curthread, psf);
|
||||
|
||||
/* The signal mask was restored; check for any pending signals: */
|
||||
_thread_run->check_pending = 1;
|
||||
curthread->check_pending = 1;
|
||||
|
||||
/* Switch to the thread scheduler: */
|
||||
___longjmp(_thread_kern_sched_jb, 1);
|
||||
@ -101,6 +102,8 @@ _thread_kern_sched_frame(struct pthread_signal_frame *psf)
|
||||
void
|
||||
_thread_kern_sched(ucontext_t *scp)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/*
|
||||
* Flag the pthread kernel as executing scheduler code
|
||||
* to avoid a scheduler signal from interrupting this
|
||||
@ -114,13 +117,13 @@ _thread_kern_sched(ucontext_t *scp)
|
||||
DBG_MSG("Entering scheduler due to signal\n");
|
||||
} else {
|
||||
/* Save the state of the current thread: */
|
||||
if (_setjmp(_thread_run->ctx.jb) == 0) {
|
||||
if (_setjmp(curthread->ctx.jb) == 0) {
|
||||
/* Flag the jump buffer was the last state saved: */
|
||||
_thread_run->ctxtype = CTX_JB_NOSIG;
|
||||
_thread_run->longjmp_val = 1;
|
||||
curthread->ctxtype = CTX_JB_NOSIG;
|
||||
curthread->longjmp_val = 1;
|
||||
} else {
|
||||
DBG_MSG("Returned from ___longjmp, thread %p\n",
|
||||
_thread_run);
|
||||
curthread);
|
||||
/*
|
||||
* This point is reached when a longjmp() is called
|
||||
* to restore the state of a thread.
|
||||
@ -129,10 +132,10 @@ _thread_kern_sched(ucontext_t *scp)
|
||||
*/
|
||||
_thread_kern_in_sched = 0;
|
||||
|
||||
if (_thread_run->sig_defer_count == 0) {
|
||||
if (((_thread_run->cancelflags &
|
||||
if (curthread->sig_defer_count == 0) {
|
||||
if (((curthread->cancelflags &
|
||||
PTHREAD_AT_CANCEL_POINT) == 0) &&
|
||||
((_thread_run->cancelflags &
|
||||
((curthread->cancelflags &
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS) != 0))
|
||||
/*
|
||||
* Cancellations override signals.
|
||||
@ -150,7 +153,7 @@ _thread_kern_sched(ucontext_t *scp)
|
||||
if (_sched_switch_hook != NULL) {
|
||||
/* Run the installed switch hook: */
|
||||
thread_run_switch_hook(_last_user_thread,
|
||||
_thread_run);
|
||||
curthread);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -162,7 +165,9 @@ _thread_kern_sched(ucontext_t *scp)
|
||||
void
|
||||
_thread_kern_sched_sig(void)
|
||||
{
|
||||
_thread_run->check_pending = 1;
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
curthread->check_pending = 1;
|
||||
_thread_kern_sched(NULL);
|
||||
}
|
||||
|
||||
@ -172,13 +177,14 @@ _thread_kern_scheduler(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
struct pthread *curthread = _get_curthread();
|
||||
pthread_t pthread, pthread_h;
|
||||
unsigned int current_tick;
|
||||
int add_to_prioq;
|
||||
|
||||
/* If the currently running thread is a user thread, save it: */
|
||||
if ((_thread_run->flags & PTHREAD_FLAGS_PRIVATE) == 0)
|
||||
_last_user_thread = _thread_run;
|
||||
if ((curthread->flags & PTHREAD_FLAGS_PRIVATE) == 0)
|
||||
_last_user_thread = curthread;
|
||||
|
||||
if (called_from_handler != 0) {
|
||||
called_from_handler = 0;
|
||||
@ -188,7 +194,7 @@ _thread_kern_scheduler(void)
|
||||
* the current thread. Restore the process signal
|
||||
* mask.
|
||||
*/
|
||||
if (_thread_sys_sigprocmask(SIG_SETMASK,
|
||||
if (__sys_sigprocmask(SIG_SETMASK,
|
||||
&_process_sigmask, NULL) != 0)
|
||||
PANIC("Unable to restore process mask after signal");
|
||||
|
||||
@ -196,14 +202,14 @@ _thread_kern_scheduler(void)
|
||||
* Since the signal handler didn't return normally, we
|
||||
* have to tell the kernel to reuse the signal stack.
|
||||
*/
|
||||
if (_thread_sys_sigaltstack(&_thread_sigstack, NULL) != 0)
|
||||
if (__sys_sigaltstack(&_thread_sigstack, NULL) != 0)
|
||||
PANIC("Unable to restore alternate signal stack");
|
||||
}
|
||||
|
||||
/* Are there pending signals for this thread? */
|
||||
if (_thread_run->check_pending != 0) {
|
||||
_thread_run->check_pending = 0;
|
||||
_thread_sig_check_pending(_thread_run);
|
||||
if (curthread->check_pending != 0) {
|
||||
curthread->check_pending = 0;
|
||||
_thread_sig_check_pending(curthread);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -226,22 +232,22 @@ _thread_kern_scheduler(void)
|
||||
_queue_signals = 1;
|
||||
add_to_prioq = 0;
|
||||
|
||||
if (_thread_run != &_thread_kern_thread) {
|
||||
if (curthread != &_thread_kern_thread) {
|
||||
/*
|
||||
* This thread no longer needs to yield the CPU.
|
||||
*/
|
||||
_thread_run->yield_on_sig_undefer = 0;
|
||||
curthread->yield_on_sig_undefer = 0;
|
||||
|
||||
if (_thread_run->state != PS_RUNNING) {
|
||||
if (curthread->state != PS_RUNNING) {
|
||||
/*
|
||||
* Save the current time as the time that the
|
||||
* thread became inactive:
|
||||
*/
|
||||
_thread_run->last_inactive = (long)current_tick;
|
||||
if (_thread_run->last_inactive <
|
||||
_thread_run->last_active) {
|
||||
curthread->last_inactive = (long)current_tick;
|
||||
if (curthread->last_inactive <
|
||||
curthread->last_active) {
|
||||
/* Account for a rollover: */
|
||||
_thread_run->last_inactive =+
|
||||
curthread->last_inactive =+
|
||||
UINT_MAX + 1;
|
||||
}
|
||||
}
|
||||
@ -250,7 +256,7 @@ _thread_kern_scheduler(void)
|
||||
* Place the currently running thread into the
|
||||
* appropriate queue(s).
|
||||
*/
|
||||
switch (_thread_run->state) {
|
||||
switch (curthread->state) {
|
||||
case PS_DEAD:
|
||||
case PS_STATE_MAX: /* to silence -Wall */
|
||||
case PS_SUSPENDED:
|
||||
@ -285,31 +291,31 @@ _thread_kern_scheduler(void)
|
||||
case PS_SIGWAIT:
|
||||
case PS_WAIT_WAIT:
|
||||
/* No timeouts for these states: */
|
||||
_thread_run->wakeup_time.tv_sec = -1;
|
||||
_thread_run->wakeup_time.tv_nsec = -1;
|
||||
curthread->wakeup_time.tv_sec = -1;
|
||||
curthread->wakeup_time.tv_nsec = -1;
|
||||
|
||||
/* Restart the time slice: */
|
||||
_thread_run->slice_usec = -1;
|
||||
curthread->slice_usec = -1;
|
||||
|
||||
/* Insert into the waiting queue: */
|
||||
PTHREAD_WAITQ_INSERT(_thread_run);
|
||||
PTHREAD_WAITQ_INSERT(curthread);
|
||||
break;
|
||||
|
||||
/* States which can timeout: */
|
||||
case PS_COND_WAIT:
|
||||
case PS_SLEEP_WAIT:
|
||||
/* Restart the time slice: */
|
||||
_thread_run->slice_usec = -1;
|
||||
curthread->slice_usec = -1;
|
||||
|
||||
/* Insert into the waiting queue: */
|
||||
PTHREAD_WAITQ_INSERT(_thread_run);
|
||||
PTHREAD_WAITQ_INSERT(curthread);
|
||||
break;
|
||||
|
||||
/* States that require periodic work: */
|
||||
case PS_SPINBLOCK:
|
||||
/* No timeouts for this state: */
|
||||
_thread_run->wakeup_time.tv_sec = -1;
|
||||
_thread_run->wakeup_time.tv_nsec = -1;
|
||||
curthread->wakeup_time.tv_sec = -1;
|
||||
curthread->wakeup_time.tv_nsec = -1;
|
||||
|
||||
/* Increment spinblock count: */
|
||||
_spinblock_count++;
|
||||
@ -320,13 +326,13 @@ _thread_kern_scheduler(void)
|
||||
case PS_POLL_WAIT:
|
||||
case PS_SELECT_WAIT:
|
||||
/* Restart the time slice: */
|
||||
_thread_run->slice_usec = -1;
|
||||
curthread->slice_usec = -1;
|
||||
|
||||
/* Insert into the waiting queue: */
|
||||
PTHREAD_WAITQ_INSERT(_thread_run);
|
||||
PTHREAD_WAITQ_INSERT(curthread);
|
||||
|
||||
/* Insert into the work queue: */
|
||||
PTHREAD_WORKQ_INSERT(_thread_run);
|
||||
PTHREAD_WORKQ_INSERT(curthread);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -342,7 +348,7 @@ _thread_kern_scheduler(void)
|
||||
* has occurred or if we have no more runnable threads.
|
||||
*/
|
||||
else if (((current_tick = _sched_ticks) != last_tick) ||
|
||||
((_thread_run->state != PS_RUNNING) &&
|
||||
((curthread->state != PS_RUNNING) &&
|
||||
(PTHREAD_PRIOQ_FIRST() == NULL))) {
|
||||
/* Unprotect the scheduling queues: */
|
||||
_queue_signals = 0;
|
||||
@ -407,43 +413,43 @@ _thread_kern_scheduler(void)
|
||||
* thread became inactive:
|
||||
*/
|
||||
current_tick = _sched_ticks;
|
||||
_thread_run->last_inactive = (long)current_tick;
|
||||
if (_thread_run->last_inactive <
|
||||
_thread_run->last_active) {
|
||||
curthread->last_inactive = (long)current_tick;
|
||||
if (curthread->last_inactive <
|
||||
curthread->last_active) {
|
||||
/* Account for a rollover: */
|
||||
_thread_run->last_inactive =+ UINT_MAX + 1;
|
||||
curthread->last_inactive =+ UINT_MAX + 1;
|
||||
}
|
||||
|
||||
if ((_thread_run->slice_usec != -1) &&
|
||||
(_thread_run->attr.sched_policy != SCHED_FIFO)) {
|
||||
if ((curthread->slice_usec != -1) &&
|
||||
(curthread->attr.sched_policy != SCHED_FIFO)) {
|
||||
/*
|
||||
* Accumulate the number of microseconds for
|
||||
* which the current thread has run:
|
||||
*/
|
||||
_thread_run->slice_usec +=
|
||||
(_thread_run->last_inactive -
|
||||
_thread_run->last_active) *
|
||||
curthread->slice_usec +=
|
||||
(curthread->last_inactive -
|
||||
curthread->last_active) *
|
||||
(long)_clock_res_usec;
|
||||
/* Check for time quantum exceeded: */
|
||||
if (_thread_run->slice_usec > TIMESLICE_USEC)
|
||||
_thread_run->slice_usec = -1;
|
||||
if (curthread->slice_usec > TIMESLICE_USEC)
|
||||
curthread->slice_usec = -1;
|
||||
}
|
||||
|
||||
if (_thread_run->slice_usec == -1) {
|
||||
if (curthread->slice_usec == -1) {
|
||||
/*
|
||||
* The thread exceeded its time
|
||||
* quantum or it yielded the CPU;
|
||||
* place it at the tail of the
|
||||
* queue for its priority.
|
||||
*/
|
||||
PTHREAD_PRIOQ_INSERT_TAIL(_thread_run);
|
||||
PTHREAD_PRIOQ_INSERT_TAIL(curthread);
|
||||
} else {
|
||||
/*
|
||||
* The thread hasn't exceeded its
|
||||
* interval. Place it at the head
|
||||
* of the queue for its priority.
|
||||
*/
|
||||
PTHREAD_PRIOQ_INSERT_HEAD(_thread_run);
|
||||
PTHREAD_PRIOQ_INSERT_HEAD(curthread);
|
||||
}
|
||||
}
|
||||
|
||||
@ -459,9 +465,11 @@ _thread_kern_scheduler(void)
|
||||
* the running thread to point to the global kernel
|
||||
* thread structure:
|
||||
*/
|
||||
_thread_run = &_thread_kern_thread;
|
||||
_set_curthread(&_thread_kern_thread);
|
||||
curthread = &_thread_kern_thread;
|
||||
|
||||
DBG_MSG("No runnable threads, using kernel thread %p\n",
|
||||
_thread_run);
|
||||
curthread);
|
||||
|
||||
/* Unprotect the scheduling queues: */
|
||||
_queue_signals = 0;
|
||||
@ -532,23 +540,24 @@ _thread_kern_scheduler(void)
|
||||
}
|
||||
|
||||
/* Make the selected thread the current thread: */
|
||||
_thread_run = pthread_h;
|
||||
_set_curthread(pthread_h);
|
||||
curthread = pthread_h;
|
||||
|
||||
/*
|
||||
* Save the current time as the time that the thread
|
||||
* became active:
|
||||
*/
|
||||
current_tick = _sched_ticks;
|
||||
_thread_run->last_active = (long) current_tick;
|
||||
curthread->last_active = (long) current_tick;
|
||||
|
||||
/*
|
||||
* Check if this thread is running for the first time
|
||||
* or running again after using its full time slice
|
||||
* allocation:
|
||||
*/
|
||||
if (_thread_run->slice_usec == -1) {
|
||||
if (curthread->slice_usec == -1) {
|
||||
/* Reset the accumulated time slice period: */
|
||||
_thread_run->slice_usec = 0;
|
||||
curthread->slice_usec = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -556,29 +565,29 @@ _thread_kern_scheduler(void)
|
||||
* installed switch hooks.
|
||||
*/
|
||||
if ((_sched_switch_hook != NULL) &&
|
||||
(_last_user_thread != _thread_run)) {
|
||||
(_last_user_thread != curthread)) {
|
||||
thread_run_switch_hook(_last_user_thread,
|
||||
_thread_run);
|
||||
curthread);
|
||||
}
|
||||
/*
|
||||
* Continue the thread at its current frame:
|
||||
*/
|
||||
switch(_thread_run->ctxtype) {
|
||||
switch(curthread->ctxtype) {
|
||||
case CTX_JB_NOSIG:
|
||||
___longjmp(_thread_run->ctx.jb,
|
||||
_thread_run->longjmp_val);
|
||||
___longjmp(curthread->ctx.jb,
|
||||
curthread->longjmp_val);
|
||||
break;
|
||||
case CTX_JB:
|
||||
__longjmp(_thread_run->ctx.jb,
|
||||
_thread_run->longjmp_val);
|
||||
__longjmp(curthread->ctx.jb,
|
||||
curthread->longjmp_val);
|
||||
break;
|
||||
case CTX_SJB:
|
||||
__siglongjmp(_thread_run->ctx.sigjb,
|
||||
_thread_run->longjmp_val);
|
||||
__siglongjmp(curthread->ctx.sigjb,
|
||||
curthread->longjmp_val);
|
||||
break;
|
||||
case CTX_UC:
|
||||
/* XXX - Restore FP regsisters? */
|
||||
FP_RESTORE_UC(&_thread_run->ctx.uc);
|
||||
FP_RESTORE_UC(&curthread->ctx.uc);
|
||||
|
||||
/*
|
||||
* Do a sigreturn to restart the thread that
|
||||
@ -587,15 +596,15 @@ _thread_kern_scheduler(void)
|
||||
_thread_kern_in_sched = 0;
|
||||
|
||||
#if NOT_YET
|
||||
_setcontext(&_thread_run->ctx.uc);
|
||||
_setcontext(&curthread->ctx.uc);
|
||||
#else
|
||||
/*
|
||||
* Ensure the process signal mask is set
|
||||
* correctly:
|
||||
*/
|
||||
_thread_run->ctx.uc.uc_sigmask =
|
||||
curthread->ctx.uc.uc_sigmask =
|
||||
_process_sigmask;
|
||||
_thread_sys_sigreturn(&_thread_run->ctx.uc);
|
||||
__sys_sigreturn(&curthread->ctx.uc);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@ -611,6 +620,8 @@ _thread_kern_scheduler(void)
|
||||
void
|
||||
_thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/*
|
||||
* Flag the pthread kernel as executing scheduler code
|
||||
* to avoid a scheduler signal from interrupting this
|
||||
@ -625,9 +636,9 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
|
||||
_queue_signals = 1;
|
||||
|
||||
/* Change the state of the current thread: */
|
||||
_thread_run->state = state;
|
||||
_thread_run->fname = fname;
|
||||
_thread_run->lineno = lineno;
|
||||
curthread->state = state;
|
||||
curthread->fname = fname;
|
||||
curthread->lineno = lineno;
|
||||
|
||||
/* Schedule the next thread that is ready: */
|
||||
_thread_kern_sched(NULL);
|
||||
@ -637,6 +648,8 @@ void
|
||||
_thread_kern_sched_state_unlock(enum pthread_state state,
|
||||
spinlock_t *lock, char *fname, int lineno)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/*
|
||||
* Flag the pthread kernel as executing scheduler code
|
||||
* to avoid a scheduler signal from interrupting this
|
||||
@ -652,9 +665,9 @@ _thread_kern_sched_state_unlock(enum pthread_state state,
|
||||
_queue_signals = 1;
|
||||
|
||||
/* Change the state of the current thread: */
|
||||
_thread_run->state = state;
|
||||
_thread_run->fname = fname;
|
||||
_thread_run->lineno = lineno;
|
||||
curthread->state = state;
|
||||
curthread->fname = fname;
|
||||
curthread->lineno = lineno;
|
||||
|
||||
_SPINUNLOCK(lock);
|
||||
|
||||
@ -817,7 +830,7 @@ thread_kern_poll(int wait_reqd)
|
||||
* Wait for a file descriptor to be ready for read, write, or
|
||||
* an exception, or a timeout to occur:
|
||||
*/
|
||||
count = _thread_sys_poll(_thread_pfd_table, nfds, timeout_ms);
|
||||
count = __sys_poll(_thread_pfd_table, nfds, timeout_ms);
|
||||
|
||||
if (kern_pipe_added != 0)
|
||||
/*
|
||||
@ -991,11 +1004,12 @@ thread_kern_poll(int wait_reqd)
|
||||
void
|
||||
_thread_kern_set_timeout(const struct timespec * timeout)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct timespec current_time;
|
||||
struct timeval tv;
|
||||
|
||||
/* Reset the timeout flag for the running thread: */
|
||||
_thread_run->timeout = 0;
|
||||
curthread->timeout = 0;
|
||||
|
||||
/* Check if the thread is to wait forever: */
|
||||
if (timeout == NULL) {
|
||||
@ -1003,28 +1017,28 @@ _thread_kern_set_timeout(const struct timespec * timeout)
|
||||
* Set the wakeup time to something that can be recognised as
|
||||
* different to an actual time of day:
|
||||
*/
|
||||
_thread_run->wakeup_time.tv_sec = -1;
|
||||
_thread_run->wakeup_time.tv_nsec = -1;
|
||||
curthread->wakeup_time.tv_sec = -1;
|
||||
curthread->wakeup_time.tv_nsec = -1;
|
||||
}
|
||||
/* Check if no waiting is required: */
|
||||
else if (timeout->tv_sec == 0 && timeout->tv_nsec == 0) {
|
||||
/* Set the wake up time to 'immediately': */
|
||||
_thread_run->wakeup_time.tv_sec = 0;
|
||||
_thread_run->wakeup_time.tv_nsec = 0;
|
||||
curthread->wakeup_time.tv_sec = 0;
|
||||
curthread->wakeup_time.tv_nsec = 0;
|
||||
} else {
|
||||
/* Get the current time: */
|
||||
GET_CURRENT_TOD(tv);
|
||||
TIMEVAL_TO_TIMESPEC(&tv, ¤t_time);
|
||||
|
||||
/* Calculate the time for the current thread to wake up: */
|
||||
_thread_run->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
|
||||
_thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec;
|
||||
curthread->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
|
||||
curthread->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec;
|
||||
|
||||
/* Check if the nanosecond field needs to wrap: */
|
||||
if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
|
||||
if (curthread->wakeup_time.tv_nsec >= 1000000000) {
|
||||
/* Wrap the nanosecond field: */
|
||||
_thread_run->wakeup_time.tv_sec += 1;
|
||||
_thread_run->wakeup_time.tv_nsec -= 1000000000;
|
||||
curthread->wakeup_time.tv_sec += 1;
|
||||
curthread->wakeup_time.tv_nsec -= 1000000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1032,24 +1046,28 @@ _thread_kern_set_timeout(const struct timespec * timeout)
|
||||
void
|
||||
_thread_kern_sig_defer(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/* Allow signal deferral to be recursive. */
|
||||
_thread_run->sig_defer_count++;
|
||||
curthread->sig_defer_count++;
|
||||
}
|
||||
|
||||
void
|
||||
_thread_kern_sig_undefer(void)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
|
||||
/*
|
||||
* Perform checks to yield only if we are about to undefer
|
||||
* signals.
|
||||
*/
|
||||
if (_thread_run->sig_defer_count > 1) {
|
||||
if (curthread->sig_defer_count > 1) {
|
||||
/* Decrement the signal deferral count. */
|
||||
_thread_run->sig_defer_count--;
|
||||
curthread->sig_defer_count--;
|
||||
}
|
||||
else if (_thread_run->sig_defer_count == 1) {
|
||||
else if (curthread->sig_defer_count == 1) {
|
||||
/* Reenable signals: */
|
||||
_thread_run->sig_defer_count = 0;
|
||||
curthread->sig_defer_count = 0;
|
||||
|
||||
/*
|
||||
* Check if there are queued signals:
|
||||
@ -1061,8 +1079,8 @@ _thread_kern_sig_undefer(void)
|
||||
* Check for asynchronous cancellation before delivering any
|
||||
* pending signals:
|
||||
*/
|
||||
if (((_thread_run->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0) &&
|
||||
((_thread_run->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0))
|
||||
if (((curthread->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0) &&
|
||||
((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0))
|
||||
pthread_testcancel();
|
||||
|
||||
/*
|
||||
@ -1071,9 +1089,9 @@ _thread_kern_sig_undefer(void)
|
||||
*
|
||||
* XXX - Come back and revisit the pending signal problem
|
||||
*/
|
||||
if ((_thread_run->yield_on_sig_undefer != 0) ||
|
||||
SIGNOTEMPTY(_thread_run->sigpend)) {
|
||||
_thread_run->yield_on_sig_undefer = 0;
|
||||
if ((curthread->yield_on_sig_undefer != 0) ||
|
||||
SIGNOTEMPTY(curthread->sigpend)) {
|
||||
curthread->yield_on_sig_undefer = 0;
|
||||
_thread_kern_sched(NULL);
|
||||
}
|
||||
}
|
||||
@ -1088,7 +1106,7 @@ dequeue_signals(void)
|
||||
/*
|
||||
* Enter a loop to clear the pthread kernel pipe:
|
||||
*/
|
||||
while (((num = _thread_sys_read(_thread_kern_pipe[0], bufr,
|
||||
while (((num = __sys_read(_thread_kern_pipe[0], bufr,
|
||||
sizeof(bufr))) > 0) || (num == -1 && errno == EINTR)) {
|
||||
}
|
||||
if ((num < 0) && (errno != EAGAIN)) {
|
||||
@ -1120,4 +1138,18 @@ thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in)
|
||||
_sched_switch_hook(tid_out, tid_in);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct pthread *
|
||||
_get_curthread(void)
|
||||
{
|
||||
if (_thread_initial == NULL)
|
||||
_thread_init();
|
||||
|
||||
return (_thread_run);
|
||||
}
|
||||
|
||||
void
|
||||
_set_curthread(struct pthread *newthread)
|
||||
{
|
||||
_thread_run = newthread;
|
||||
}
|
||||
|
@ -31,46 +31,47 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/event.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak keven=_kevent
|
||||
|
||||
int
|
||||
kevent(int kq, const struct kevent *changelist, int nchanges,
|
||||
_kevent(int kq, const struct kevent *changelist, int nchanges,
|
||||
struct kevent *eventlist, int nevents, const struct timespec *timeout)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct timespec nullts = { 0, 0 };
|
||||
int rc;
|
||||
|
||||
/* Set the wake up time */
|
||||
_thread_kern_set_timeout(timeout);
|
||||
|
||||
rc = _thread_sys_kevent(kq, changelist, nchanges,
|
||||
rc = __sys_kevent(kq, changelist, nchanges,
|
||||
eventlist, nevents, &nullts);
|
||||
if (rc == 0 && (timeout == NULL ||
|
||||
timeout->tv_sec != 0 || timeout->tv_nsec != 0)) {
|
||||
/* Save the socket file descriptor: */
|
||||
_thread_run->data.fd.fd = kq;
|
||||
_thread_run->data.fd.fname = __FILE__;
|
||||
_thread_run->data.fd.branch = __LINE__;
|
||||
curthread->data.fd.fd = kq;
|
||||
curthread->data.fd.fname = __FILE__;
|
||||
curthread->data.fd.branch = __LINE__;
|
||||
|
||||
do {
|
||||
/* Reset the interrupted and timeout flags: */
|
||||
_thread_run->interrupted = 0;
|
||||
_thread_run->timeout = 0;
|
||||
curthread->interrupted = 0;
|
||||
curthread->timeout = 0;
|
||||
|
||||
_thread_kern_sched_state(PS_FDR_WAIT,
|
||||
__FILE__, __LINE__);
|
||||
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
rc = _thread_sys_kevent(kq, NULL, 0,
|
||||
rc = __sys_kevent(kq, NULL, 0,
|
||||
eventlist, nevents, &nullts);
|
||||
} while (rc == 0 && _thread_run->timeout == 0);
|
||||
} while (rc == 0 && curthread->timeout == 0);
|
||||
}
|
||||
return (rc);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,12 +33,13 @@
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_kill=_pthread_kill
|
||||
|
||||
int
|
||||
pthread_kill(pthread_t pthread, int sig)
|
||||
_pthread_kill(pthread_t pthread, int sig)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -71,4 +72,3 @@ pthread_kill(pthread_t pthread, int sig)
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,21 +33,20 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak listen=_listen
|
||||
|
||||
int
|
||||
_listen(int fd, int backlog)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_listen(fd, backlog);
|
||||
ret = __sys_listen(fd, backlog);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_listen, listen);
|
||||
#endif
|
||||
|
@ -34,12 +34,13 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_mutexattr_init=_pthread_mutexattr_init
|
||||
|
||||
int
|
||||
pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
_pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutexattr_t pattr;
|
||||
@ -55,4 +56,3 @@ pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,12 +32,16 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_mutexattr_setkind_np=_pthread_mutexattr_setkind_np
|
||||
#pragma weak pthread_mutexattr_getkind_np=_pthread_mutexattr_getkind_np
|
||||
#pragma weak pthread_mutexattr_gettype=_pthread_mutexattr_gettype
|
||||
#pragma weak pthread_mutexattr_settype=_pthread_mutexattr_settype
|
||||
|
||||
int
|
||||
pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
|
||||
_pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL || *attr == NULL) {
|
||||
@ -51,7 +55,7 @@ pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
|
||||
_pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL) {
|
||||
@ -64,7 +68,7 @@ pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
|
||||
_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL || *attr == NULL || type >= MUTEX_TYPE_MAX) {
|
||||
@ -78,7 +82,7 @@ pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
|
||||
_pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -91,4 +95,3 @@ pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -8,22 +8,23 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak msync=__msync
|
||||
|
||||
int
|
||||
_msync(void *addr, size_t len, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = _thread_sys_msync(addr, len, flags);
|
||||
ret = __sys_msync(addr, len, flags);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
msync(void *addr, size_t len, int flags)
|
||||
__msync(void *addr, size_t len, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -39,4 +40,3 @@ msync(void *addr, size_t len, int flags)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -32,15 +32,15 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <string.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_multi_np=_pthread_multi_np
|
||||
|
||||
int
|
||||
pthread_multi_np()
|
||||
_pthread_multi_np()
|
||||
{
|
||||
/* Return to multi-threaded scheduling mode: */
|
||||
_thread_single = NULL;
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -75,6 +74,20 @@ static inline void mutex_queue_enq(pthread_mutex_t, pthread_t);
|
||||
|
||||
static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER;
|
||||
|
||||
static struct pthread_mutex_attr static_mutex_attr =
|
||||
PTHREAD_MUTEXATTR_STATIC_INITIALIZER;
|
||||
static pthread_mutexattr_t static_mattr = &static_mutex_attr;
|
||||
|
||||
/* Single underscore versions provided for libc internal usage: */
|
||||
#pragma weak pthread_mutex_trylock=__pthread_mutex_trylock
|
||||
#pragma weak pthread_mutex_lock=__pthread_mutex_lock
|
||||
|
||||
/* No difference between libc and application usage of these: */
|
||||
#pragma weak pthread_mutex_init=_pthread_mutex_init
|
||||
#pragma weak pthread_mutex_destroy=_pthread_mutex_destroy
|
||||
#pragma weak pthread_mutex_unlock=_pthread_mutex_unlock
|
||||
|
||||
|
||||
/* Reinitialize a mutex to defaults. */
|
||||
int
|
||||
_mutex_reinit(pthread_mutex_t * mutex)
|
||||
@ -106,7 +119,7 @@ _mutex_reinit(pthread_mutex_t * mutex)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_init(pthread_mutex_t * mutex,
|
||||
_pthread_mutex_init(pthread_mutex_t * mutex,
|
||||
const pthread_mutexattr_t * mutex_attr)
|
||||
{
|
||||
enum pthread_mutextype type;
|
||||
@ -201,7 +214,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_destroy(pthread_mutex_t * mutex)
|
||||
_pthread_mutex_destroy(pthread_mutex_t * mutex)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -259,8 +272,158 @@ init_static(pthread_mutex_t *mutex)
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int
|
||||
init_static_private(pthread_mutex_t *mutex)
|
||||
{
|
||||
int ret;
|
||||
|
||||
_SPINLOCK(&static_init_lock);
|
||||
|
||||
if (*mutex == NULL)
|
||||
ret = pthread_mutex_init(mutex, &static_mattr);
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
_SPINUNLOCK(&static_init_lock);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int
|
||||
mutex_trylock_common(pthread_mutex_t *mutex)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret = 0;
|
||||
|
||||
PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL),
|
||||
"Uninitialized mutex in pthread_mutex_trylock_basic");
|
||||
|
||||
/*
|
||||
* Defer signals to protect the scheduling queues from
|
||||
* access by the signal handler:
|
||||
*/
|
||||
_thread_kern_sig_defer();
|
||||
|
||||
/* Lock the mutex structure: */
|
||||
_SPINLOCK(&(*mutex)->lock);
|
||||
|
||||
/*
|
||||
* If the mutex was statically allocated, properly
|
||||
* initialize the tail queue.
|
||||
*/
|
||||
if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) {
|
||||
TAILQ_INIT(&(*mutex)->m_queue);
|
||||
_MUTEX_INIT_LINK(*mutex);
|
||||
(*mutex)->m_flags |= MUTEX_FLAGS_INITED;
|
||||
}
|
||||
|
||||
/* Process according to mutex type: */
|
||||
switch ((*mutex)->m_protocol) {
|
||||
/* Default POSIX mutex: */
|
||||
case PTHREAD_PRIO_NONE:
|
||||
/* Check if this mutex is not locked: */
|
||||
if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for the running thread: */
|
||||
(*mutex)->m_owner = curthread;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&curthread->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == curthread)
|
||||
ret = mutex_self_trylock(*mutex);
|
||||
else
|
||||
/* Return a busy error: */
|
||||
ret = EBUSY;
|
||||
break;
|
||||
|
||||
/* POSIX priority inheritence mutex: */
|
||||
case PTHREAD_PRIO_INHERIT:
|
||||
/* Check if this mutex is not locked: */
|
||||
if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for the running thread: */
|
||||
(*mutex)->m_owner = curthread;
|
||||
|
||||
/* Track number of priority mutexes owned: */
|
||||
curthread->priority_mutex_count++;
|
||||
|
||||
/*
|
||||
* The mutex takes on the attributes of the
|
||||
* running thread when there are no waiters.
|
||||
*/
|
||||
(*mutex)->m_prio = curthread->active_priority;
|
||||
(*mutex)->m_saved_prio =
|
||||
curthread->inherited_priority;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&curthread->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == curthread)
|
||||
ret = mutex_self_trylock(*mutex);
|
||||
else
|
||||
/* Return a busy error: */
|
||||
ret = EBUSY;
|
||||
break;
|
||||
|
||||
/* POSIX priority protection mutex: */
|
||||
case PTHREAD_PRIO_PROTECT:
|
||||
/* Check for a priority ceiling violation: */
|
||||
if (curthread->active_priority > (*mutex)->m_prio)
|
||||
ret = EINVAL;
|
||||
|
||||
/* Check if this mutex is not locked: */
|
||||
else if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for the running thread: */
|
||||
(*mutex)->m_owner = curthread;
|
||||
|
||||
/* Track number of priority mutexes owned: */
|
||||
curthread->priority_mutex_count++;
|
||||
|
||||
/*
|
||||
* The running thread inherits the ceiling
|
||||
* priority of the mutex and executes at that
|
||||
* priority.
|
||||
*/
|
||||
curthread->active_priority = (*mutex)->m_prio;
|
||||
(*mutex)->m_saved_prio =
|
||||
curthread->inherited_priority;
|
||||
curthread->inherited_priority =
|
||||
(*mutex)->m_prio;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&curthread->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == curthread)
|
||||
ret = mutex_self_trylock(*mutex);
|
||||
else
|
||||
/* Return a busy error: */
|
||||
ret = EBUSY;
|
||||
break;
|
||||
|
||||
/* Trap invalid mutex types: */
|
||||
default:
|
||||
/* Return an invalid argument error: */
|
||||
ret = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Unlock the mutex structure: */
|
||||
_SPINUNLOCK(&(*mutex)->lock);
|
||||
|
||||
/*
|
||||
* Undefer and handle pending signals, yielding if
|
||||
* necessary:
|
||||
*/
|
||||
_thread_kern_sig_undefer();
|
||||
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_trylock(pthread_mutex_t * mutex)
|
||||
__pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -271,153 +434,41 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
|
||||
* If the mutex is statically initialized, perform the dynamic
|
||||
* initialization:
|
||||
*/
|
||||
else if (*mutex != NULL || (ret = init_static(mutex)) == 0) {
|
||||
/*
|
||||
* Defer signals to protect the scheduling queues from
|
||||
* access by the signal handler:
|
||||
*/
|
||||
_thread_kern_sig_defer();
|
||||
else if ((*mutex != NULL) || (ret = init_static(mutex)) == 0)
|
||||
ret = mutex_trylock_common(mutex);
|
||||
|
||||
/* Lock the mutex structure: */
|
||||
_SPINLOCK(&(*mutex)->lock);
|
||||
|
||||
/*
|
||||
* If the mutex was statically allocated, properly
|
||||
* initialize the tail queue.
|
||||
*/
|
||||
if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) {
|
||||
TAILQ_INIT(&(*mutex)->m_queue);
|
||||
_MUTEX_INIT_LINK(*mutex);
|
||||
(*mutex)->m_flags |= MUTEX_FLAGS_INITED;
|
||||
}
|
||||
|
||||
/* Process according to mutex type: */
|
||||
switch ((*mutex)->m_protocol) {
|
||||
/* Default POSIX mutex: */
|
||||
case PTHREAD_PRIO_NONE:
|
||||
/* Check if this mutex is not locked: */
|
||||
if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for the running thread: */
|
||||
(*mutex)->m_owner = _thread_run;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&_thread_run->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == _thread_run)
|
||||
ret = mutex_self_trylock(*mutex);
|
||||
else
|
||||
/* Return a busy error: */
|
||||
ret = EBUSY;
|
||||
break;
|
||||
|
||||
/* POSIX priority inheritence mutex: */
|
||||
case PTHREAD_PRIO_INHERIT:
|
||||
/* Check if this mutex is not locked: */
|
||||
if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for the running thread: */
|
||||
(*mutex)->m_owner = _thread_run;
|
||||
|
||||
/* Track number of priority mutexes owned: */
|
||||
_thread_run->priority_mutex_count++;
|
||||
|
||||
/*
|
||||
* The mutex takes on the attributes of the
|
||||
* running thread when there are no waiters.
|
||||
*/
|
||||
(*mutex)->m_prio = _thread_run->active_priority;
|
||||
(*mutex)->m_saved_prio =
|
||||
_thread_run->inherited_priority;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&_thread_run->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == _thread_run)
|
||||
ret = mutex_self_trylock(*mutex);
|
||||
else
|
||||
/* Return a busy error: */
|
||||
ret = EBUSY;
|
||||
break;
|
||||
|
||||
/* POSIX priority protection mutex: */
|
||||
case PTHREAD_PRIO_PROTECT:
|
||||
/* Check for a priority ceiling violation: */
|
||||
if (_thread_run->active_priority > (*mutex)->m_prio)
|
||||
ret = EINVAL;
|
||||
|
||||
/* Check if this mutex is not locked: */
|
||||
else if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for the running thread: */
|
||||
(*mutex)->m_owner = _thread_run;
|
||||
|
||||
/* Track number of priority mutexes owned: */
|
||||
_thread_run->priority_mutex_count++;
|
||||
|
||||
/*
|
||||
* The running thread inherits the ceiling
|
||||
* priority of the mutex and executes at that
|
||||
* priority.
|
||||
*/
|
||||
_thread_run->active_priority = (*mutex)->m_prio;
|
||||
(*mutex)->m_saved_prio =
|
||||
_thread_run->inherited_priority;
|
||||
_thread_run->inherited_priority =
|
||||
(*mutex)->m_prio;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&_thread_run->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == _thread_run)
|
||||
ret = mutex_self_trylock(*mutex);
|
||||
else
|
||||
/* Return a busy error: */
|
||||
ret = EBUSY;
|
||||
break;
|
||||
|
||||
/* Trap invalid mutex types: */
|
||||
default:
|
||||
/* Return an invalid argument error: */
|
||||
ret = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Unlock the mutex structure: */
|
||||
_SPINUNLOCK(&(*mutex)->lock);
|
||||
|
||||
/*
|
||||
* Undefer and handle pending signals, yielding if
|
||||
* necessary:
|
||||
*/
|
||||
_thread_kern_sig_undefer();
|
||||
}
|
||||
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
_pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (_thread_initial == NULL)
|
||||
_thread_init();
|
||||
|
||||
if (mutex == NULL)
|
||||
return (EINVAL);
|
||||
ret = EINVAL;
|
||||
|
||||
/*
|
||||
* If the mutex is statically initialized, perform the dynamic
|
||||
* initialization:
|
||||
* initialization marking the mutex private (delete safe):
|
||||
*/
|
||||
if ((*mutex == NULL) &&
|
||||
((ret = init_static(mutex)) != 0))
|
||||
return (ret);
|
||||
else if ((*mutex != NULL) || (ret = init_static_private(mutex)) == 0)
|
||||
ret = mutex_trylock_common(mutex);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
mutex_lock_common(pthread_mutex_t * mutex)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret = 0;
|
||||
|
||||
PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL),
|
||||
"Uninitialized mutex in pthread_mutex_trylock_basic");
|
||||
|
||||
/* Reset the interrupted flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/*
|
||||
* Enter a loop waiting to become the mutex owner. We need a
|
||||
@ -453,27 +504,27 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
case PTHREAD_PRIO_NONE:
|
||||
if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for this thread: */
|
||||
(*mutex)->m_owner = _thread_run;
|
||||
(*mutex)->m_owner = curthread;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&_thread_run->mutexq,
|
||||
TAILQ_INSERT_TAIL(&curthread->mutexq,
|
||||
(*mutex), m_qe);
|
||||
|
||||
} else if ((*mutex)->m_owner == _thread_run)
|
||||
} else if ((*mutex)->m_owner == curthread)
|
||||
ret = mutex_self_lock(*mutex);
|
||||
else {
|
||||
/*
|
||||
* Join the queue of threads waiting to lock
|
||||
* the mutex:
|
||||
*/
|
||||
mutex_queue_enq(*mutex, _thread_run);
|
||||
mutex_queue_enq(*mutex, curthread);
|
||||
|
||||
/*
|
||||
* Keep a pointer to the mutex this thread
|
||||
* is waiting on:
|
||||
*/
|
||||
_thread_run->data.mutex = *mutex;
|
||||
curthread->data.mutex = *mutex;
|
||||
|
||||
/*
|
||||
* Unlock the mutex structure and schedule the
|
||||
@ -492,42 +543,42 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
/* Check if this mutex is not locked: */
|
||||
if ((*mutex)->m_owner == NULL) {
|
||||
/* Lock the mutex for this thread: */
|
||||
(*mutex)->m_owner = _thread_run;
|
||||
(*mutex)->m_owner = curthread;
|
||||
|
||||
/* Track number of priority mutexes owned: */
|
||||
_thread_run->priority_mutex_count++;
|
||||
curthread->priority_mutex_count++;
|
||||
|
||||
/*
|
||||
* The mutex takes on attributes of the
|
||||
* running thread when there are no waiters.
|
||||
*/
|
||||
(*mutex)->m_prio = _thread_run->active_priority;
|
||||
(*mutex)->m_prio = curthread->active_priority;
|
||||
(*mutex)->m_saved_prio =
|
||||
_thread_run->inherited_priority;
|
||||
_thread_run->inherited_priority =
|
||||
curthread->inherited_priority;
|
||||
curthread->inherited_priority =
|
||||
(*mutex)->m_prio;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&_thread_run->mutexq,
|
||||
TAILQ_INSERT_TAIL(&curthread->mutexq,
|
||||
(*mutex), m_qe);
|
||||
|
||||
} else if ((*mutex)->m_owner == _thread_run)
|
||||
} else if ((*mutex)->m_owner == curthread)
|
||||
ret = mutex_self_lock(*mutex);
|
||||
else {
|
||||
/*
|
||||
* Join the queue of threads waiting to lock
|
||||
* the mutex:
|
||||
*/
|
||||
mutex_queue_enq(*mutex, _thread_run);
|
||||
mutex_queue_enq(*mutex, curthread);
|
||||
|
||||
/*
|
||||
* Keep a pointer to the mutex this thread
|
||||
* is waiting on:
|
||||
*/
|
||||
_thread_run->data.mutex = *mutex;
|
||||
curthread->data.mutex = *mutex;
|
||||
|
||||
if (_thread_run->active_priority >
|
||||
if (curthread->active_priority >
|
||||
(*mutex)->m_prio)
|
||||
/* Adjust priorities: */
|
||||
mutex_priority_adjust(*mutex);
|
||||
@ -547,7 +598,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
/* POSIX priority protection mutex: */
|
||||
case PTHREAD_PRIO_PROTECT:
|
||||
/* Check for a priority ceiling violation: */
|
||||
if (_thread_run->active_priority > (*mutex)->m_prio)
|
||||
if (curthread->active_priority > (*mutex)->m_prio)
|
||||
ret = EINVAL;
|
||||
|
||||
/* Check if this mutex is not locked: */
|
||||
@ -556,43 +607,43 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
* Lock the mutex for the running
|
||||
* thread:
|
||||
*/
|
||||
(*mutex)->m_owner = _thread_run;
|
||||
(*mutex)->m_owner = curthread;
|
||||
|
||||
/* Track number of priority mutexes owned: */
|
||||
_thread_run->priority_mutex_count++;
|
||||
curthread->priority_mutex_count++;
|
||||
|
||||
/*
|
||||
* The running thread inherits the ceiling
|
||||
* priority of the mutex and executes at that
|
||||
* priority:
|
||||
*/
|
||||
_thread_run->active_priority = (*mutex)->m_prio;
|
||||
curthread->active_priority = (*mutex)->m_prio;
|
||||
(*mutex)->m_saved_prio =
|
||||
_thread_run->inherited_priority;
|
||||
_thread_run->inherited_priority =
|
||||
curthread->inherited_priority;
|
||||
curthread->inherited_priority =
|
||||
(*mutex)->m_prio;
|
||||
|
||||
/* Add to the list of owned mutexes: */
|
||||
_MUTEX_ASSERT_NOT_OWNED(*mutex);
|
||||
TAILQ_INSERT_TAIL(&_thread_run->mutexq,
|
||||
TAILQ_INSERT_TAIL(&curthread->mutexq,
|
||||
(*mutex), m_qe);
|
||||
} else if ((*mutex)->m_owner == _thread_run)
|
||||
} else if ((*mutex)->m_owner == curthread)
|
||||
ret = mutex_self_lock(*mutex);
|
||||
else {
|
||||
/*
|
||||
* Join the queue of threads waiting to lock
|
||||
* the mutex:
|
||||
*/
|
||||
mutex_queue_enq(*mutex, _thread_run);
|
||||
mutex_queue_enq(*mutex, curthread);
|
||||
|
||||
/*
|
||||
* Keep a pointer to the mutex this thread
|
||||
* is waiting on:
|
||||
*/
|
||||
_thread_run->data.mutex = *mutex;
|
||||
curthread->data.mutex = *mutex;
|
||||
|
||||
/* Clear any previous error: */
|
||||
_thread_run->error = 0;
|
||||
curthread->error = 0;
|
||||
|
||||
/*
|
||||
* Unlock the mutex structure and schedule the
|
||||
@ -609,8 +660,8 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
* waiting for the mutex causing a ceiling
|
||||
* violation.
|
||||
*/
|
||||
ret = _thread_run->error;
|
||||
_thread_run->error = 0;
|
||||
ret = curthread->error;
|
||||
curthread->error = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -625,8 +676,8 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
* Check to see if this thread was interrupted and
|
||||
* is still in the mutex queue of waiting threads:
|
||||
*/
|
||||
if (_thread_run->interrupted != 0)
|
||||
mutex_queue_remove(*mutex, _thread_run);
|
||||
if (curthread->interrupted != 0)
|
||||
mutex_queue_remove(*mutex, curthread);
|
||||
|
||||
/* Unlock the mutex structure: */
|
||||
_SPINUNLOCK(&(*mutex)->lock);
|
||||
@ -636,19 +687,61 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
|
||||
* necessary:
|
||||
*/
|
||||
_thread_kern_sig_undefer();
|
||||
} while (((*mutex)->m_owner != _thread_run) && (ret == 0) &&
|
||||
(_thread_run->interrupted == 0));
|
||||
} while (((*mutex)->m_owner != curthread) && (ret == 0) &&
|
||||
(curthread->interrupted == 0));
|
||||
|
||||
if (_thread_run->interrupted != 0 &&
|
||||
_thread_run->continuation != NULL)
|
||||
_thread_run->continuation((void *) _thread_run);
|
||||
if (curthread->interrupted != 0 &&
|
||||
curthread->continuation != NULL)
|
||||
curthread->continuation((void *) curthread);
|
||||
|
||||
/* Return the completion status: */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_unlock(pthread_mutex_t * mutex)
|
||||
__pthread_mutex_lock(pthread_mutex_t *mutex)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (_thread_initial == NULL)
|
||||
_thread_init();
|
||||
|
||||
if (mutex == NULL)
|
||||
ret = EINVAL;
|
||||
|
||||
/*
|
||||
* If the mutex is statically initialized, perform the dynamic
|
||||
* initialization:
|
||||
*/
|
||||
else if ((*mutex != NULL) || ((ret = init_static(mutex)) == 0))
|
||||
ret = mutex_lock_common(mutex);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutex_lock(pthread_mutex_t *mutex)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (_thread_initial == NULL)
|
||||
_thread_init();
|
||||
|
||||
if (mutex == NULL)
|
||||
ret = EINVAL;
|
||||
|
||||
/*
|
||||
* If the mutex is statically initialized, perform the dynamic
|
||||
* initialization marking it private (delete safe):
|
||||
*/
|
||||
else if ((*mutex != NULL) || ((ret = init_static_private(mutex)) == 0))
|
||||
ret = mutex_lock_common(mutex);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutex_unlock(pthread_mutex_t * mutex)
|
||||
{
|
||||
return (mutex_unlock_common(mutex, /* add reference */ 0));
|
||||
}
|
||||
@ -738,6 +831,7 @@ mutex_self_lock(pthread_mutex_t mutex)
|
||||
static inline int
|
||||
mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret = 0;
|
||||
|
||||
if (mutex == NULL || *mutex == NULL) {
|
||||
@ -760,7 +854,7 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
|
||||
* Check if the running thread is not the owner of the
|
||||
* mutex:
|
||||
*/
|
||||
if ((*mutex)->m_owner != _thread_run) {
|
||||
if ((*mutex)->m_owner != curthread) {
|
||||
/*
|
||||
* Return an invalid argument error for no
|
||||
* owner and a permission error otherwise:
|
||||
@ -828,7 +922,7 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
|
||||
* Check if the running thread is not the owner of the
|
||||
* mutex:
|
||||
*/
|
||||
if ((*mutex)->m_owner != _thread_run) {
|
||||
if ((*mutex)->m_owner != curthread) {
|
||||
/*
|
||||
* Return an invalid argument error for no
|
||||
* owner and a permission error otherwise:
|
||||
@ -852,16 +946,16 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
|
||||
* not to override changes in the threads base
|
||||
* priority subsequent to locking the mutex).
|
||||
*/
|
||||
_thread_run->inherited_priority =
|
||||
curthread->inherited_priority =
|
||||
(*mutex)->m_saved_prio;
|
||||
_thread_run->active_priority =
|
||||
MAX(_thread_run->inherited_priority,
|
||||
_thread_run->base_priority);
|
||||
curthread->active_priority =
|
||||
MAX(curthread->inherited_priority,
|
||||
curthread->base_priority);
|
||||
|
||||
/*
|
||||
* This thread now owns one less priority mutex.
|
||||
*/
|
||||
_thread_run->priority_mutex_count--;
|
||||
curthread->priority_mutex_count--;
|
||||
|
||||
/* Remove the mutex from the threads queue. */
|
||||
_MUTEX_ASSERT_IS_OWNED(*mutex);
|
||||
@ -946,7 +1040,7 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
|
||||
* Check if the running thread is not the owner of the
|
||||
* mutex:
|
||||
*/
|
||||
if ((*mutex)->m_owner != _thread_run) {
|
||||
if ((*mutex)->m_owner != curthread) {
|
||||
/*
|
||||
* Return an invalid argument error for no
|
||||
* owner and a permission error otherwise:
|
||||
@ -970,16 +1064,16 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
|
||||
* not to override changes in the threads base
|
||||
* priority subsequent to locking the mutex).
|
||||
*/
|
||||
_thread_run->inherited_priority =
|
||||
curthread->inherited_priority =
|
||||
(*mutex)->m_saved_prio;
|
||||
_thread_run->active_priority =
|
||||
MAX(_thread_run->inherited_priority,
|
||||
_thread_run->base_priority);
|
||||
curthread->active_priority =
|
||||
MAX(curthread->inherited_priority,
|
||||
curthread->base_priority);
|
||||
|
||||
/*
|
||||
* This thread now owns one less priority mutex.
|
||||
*/
|
||||
_thread_run->priority_mutex_count--;
|
||||
curthread->priority_mutex_count--;
|
||||
|
||||
/* Remove the mutex from the threads queue. */
|
||||
_MUTEX_ASSERT_IS_OWNED(*mutex);
|
||||
@ -1477,4 +1571,3 @@ mutex_queue_enq(pthread_mutex_t mutex, pthread_t pthread)
|
||||
pthread->flags |= PTHREAD_FLAGS_IN_MUTEXQ;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -34,12 +34,16 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_mutexattr_getprioceiling=_pthread_mutexattr_getprioceiling
|
||||
#pragma weak pthread_mutexattr_setprioceiling=_pthread_mutexattr_setprioceiling
|
||||
#pragma weak pthread_mutex_getprioceiling=_pthread_mutex_getprioceiling
|
||||
#pragma weak pthread_mutex_setprioceiling=_pthread_mutex_setprioceiling
|
||||
|
||||
int
|
||||
pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
|
||||
_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -54,7 +58,7 @@ pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
|
||||
_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -69,8 +73,8 @@ pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_getprioceiling(pthread_mutex_t *mutex,
|
||||
int *prioceiling)
|
||||
_pthread_mutex_getprioceiling(pthread_mutex_t *mutex,
|
||||
int *prioceiling)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -85,8 +89,8 @@ pthread_mutex_getprioceiling(pthread_mutex_t *mutex,
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
|
||||
int prioceiling, int *old_ceiling)
|
||||
_pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
|
||||
int prioceiling, int *old_ceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -107,4 +111,3 @@ pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -34,12 +34,14 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_mutexattr_getprotocol=_pthread_mutexattr_getprotocol
|
||||
#pragma weak pthread_mutexattr_setprotocol=_pthread_mutexattr_setprotocol
|
||||
|
||||
int
|
||||
pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
|
||||
_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -52,7 +54,7 @@ pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
|
||||
_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -66,4 +68,3 @@ pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
|
||||
return(ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,12 +33,13 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_mutexattr_destroy=_pthread_mutexattr_destroy
|
||||
|
||||
int
|
||||
pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
|
||||
_pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
|
||||
{
|
||||
int ret;
|
||||
if (attr == NULL || *attr == NULL) {
|
||||
@ -50,4 +51,3 @@ pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,14 +33,16 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak nanosleep=__nanosleep
|
||||
|
||||
int
|
||||
_nanosleep(const struct timespec * time_to_sleep,
|
||||
struct timespec * time_remaining)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret = 0;
|
||||
struct timespec current_time;
|
||||
struct timespec current_time1;
|
||||
@ -63,16 +65,16 @@ _nanosleep(const struct timespec * time_to_sleep,
|
||||
TIMEVAL_TO_TIMESPEC(&tv, ¤t_time);
|
||||
|
||||
/* Calculate the time for the current thread to wake up: */
|
||||
_thread_run->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
|
||||
_thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
|
||||
curthread->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
|
||||
curthread->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
|
||||
|
||||
/* Check if the nanosecond field has overflowed: */
|
||||
if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
|
||||
if (curthread->wakeup_time.tv_nsec >= 1000000000) {
|
||||
/* Wrap the nanosecond field: */
|
||||
_thread_run->wakeup_time.tv_sec += 1;
|
||||
_thread_run->wakeup_time.tv_nsec -= 1000000000;
|
||||
curthread->wakeup_time.tv_sec += 1;
|
||||
curthread->wakeup_time.tv_nsec -= 1000000000;
|
||||
}
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
/* Reschedule the current thread to sleep: */
|
||||
_thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__);
|
||||
@ -118,7 +120,7 @@ _nanosleep(const struct timespec * time_to_sleep,
|
||||
}
|
||||
|
||||
/* Check if the sleep was interrupted: */
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
/* Return an EINTR error : */
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
@ -128,7 +130,7 @@ _nanosleep(const struct timespec * time_to_sleep,
|
||||
}
|
||||
|
||||
int
|
||||
nanosleep(const struct timespec * time_to_sleep, struct timespec *
|
||||
__nanosleep(const struct timespec * time_to_sleep, struct timespec *
|
||||
time_remaining)
|
||||
{
|
||||
int ret;
|
||||
@ -139,4 +141,3 @@ nanosleep(const struct timespec * time_to_sleep, struct timespec *
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -31,12 +31,13 @@
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_once=_pthread_once
|
||||
|
||||
int
|
||||
pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
|
||||
_pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
|
||||
{
|
||||
if (once_control->state == PTHREAD_NEEDS_INIT) {
|
||||
if (_thread_initial == NULL)
|
||||
@ -50,4 +51,3 @@ pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
@ -37,10 +37,11 @@
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak open=_open
|
||||
|
||||
int
|
||||
_open(const char *path, int flags,...)
|
||||
{
|
||||
@ -56,12 +57,12 @@ _open(const char *path, int flags,...)
|
||||
va_end(ap);
|
||||
}
|
||||
/* Open the file: */
|
||||
if ((fd = _thread_sys_open(path, flags, mode)) < 0) {
|
||||
if ((fd = __sys_open(path, flags, mode)) < 0) {
|
||||
}
|
||||
/* Initialise the file descriptor table entry: */
|
||||
else if (_thread_fd_table_init(fd) != 0) {
|
||||
/* Quietly close the file: */
|
||||
_thread_sys_close(fd);
|
||||
__sys_close(fd);
|
||||
|
||||
/* Reset the file descriptor: */
|
||||
fd = -1;
|
||||
@ -72,7 +73,7 @@ _open(const char *path, int flags,...)
|
||||
}
|
||||
|
||||
int
|
||||
open(const char *path, int flags,...)
|
||||
__open(const char *path, int flags,...)
|
||||
{
|
||||
int ret;
|
||||
int mode = 0;
|
||||
@ -93,4 +94,3 @@ open(const char *path, int flags,...)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -30,12 +30,13 @@
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pause=_pause
|
||||
|
||||
int
|
||||
pause(void)
|
||||
_pause(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -45,4 +46,3 @@ pause(void)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -33,24 +33,22 @@
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pipe=_pipe
|
||||
|
||||
int
|
||||
_pipe(int fds[2])
|
||||
{
|
||||
int ret;
|
||||
if ((ret = _thread_sys_pipe(fds)) >= 0) {
|
||||
if ((ret = __sys_pipe(fds)) >= 0) {
|
||||
if (_thread_fd_table_init(fds[0]) != 0 ||
|
||||
_thread_fd_table_init(fds[1]) != 0) {
|
||||
_thread_sys_close(fds[0]);
|
||||
_thread_sys_close(fds[1]);
|
||||
__sys_close(fds[0]);
|
||||
__sys_close(fds[1]);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_pipe, pipe);
|
||||
#endif
|
||||
|
@ -38,14 +38,15 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak poll=_poll
|
||||
|
||||
int
|
||||
_poll(struct pollfd *fds, unsigned int nfds, int timeout)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct timespec ts;
|
||||
int numfds = nfds;
|
||||
int i, ret = 0;
|
||||
@ -71,7 +72,7 @@ _poll(struct pollfd *fds, unsigned int nfds, int timeout)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) {
|
||||
if (((ret = __sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) {
|
||||
data.nfds = numfds;
|
||||
data.fds = fds;
|
||||
|
||||
@ -83,10 +84,10 @@ _poll(struct pollfd *fds, unsigned int nfds, int timeout)
|
||||
fds[i].revents = 0;
|
||||
}
|
||||
|
||||
_thread_run->data.poll_data = &data;
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->data.poll_data = &data;
|
||||
curthread->interrupted = 0;
|
||||
_thread_kern_sched_state(PS_POLL_WAIT, __FILE__, __LINE__);
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
} else {
|
||||
@ -96,6 +97,3 @@ _poll(struct pollfd *fds, unsigned int nfds, int timeout)
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_poll, poll);
|
||||
#endif
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/queue.h>
|
||||
#include <string.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -71,7 +70,7 @@ static int _pq_active = 0;
|
||||
} while (0)
|
||||
#define _PQ_ASSERT_PROTECTED(msg) \
|
||||
PTHREAD_ASSERT((_thread_kern_in_sched != 0) || \
|
||||
(_thread_run->sig_defer_count > 0) || \
|
||||
((_get_curthread())->sig_defer_count > 0) ||\
|
||||
(_sig_in_handler != 0), msg);
|
||||
|
||||
#else
|
||||
@ -336,4 +335,3 @@ _waitq_clearactive(void)
|
||||
_PQ_ASSERT_ACTIVE("_waitq_clearactive: ! pq_active");
|
||||
_PQ_CLEAR_ACTIVE();
|
||||
}
|
||||
#endif
|
||||
|
@ -37,13 +37,15 @@
|
||||
#include <sys/uio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak read=__read
|
||||
|
||||
ssize_t
|
||||
_read(int fd, void *buf, size_t nbytes)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
int type;
|
||||
|
||||
@ -66,14 +68,14 @@ _read(int fd, void *buf, size_t nbytes)
|
||||
}
|
||||
|
||||
/* Perform a non-blocking read syscall: */
|
||||
while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) {
|
||||
while ((ret = __sys_read(fd, buf, nbytes)) < 0) {
|
||||
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
|
||||
(errno == EWOULDBLOCK || errno == EAGAIN)) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
_thread_kern_set_timeout(NULL);
|
||||
|
||||
/* Reset the interrupted operation flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
_thread_kern_sched_state(PS_FDR_WAIT,
|
||||
__FILE__, __LINE__);
|
||||
@ -82,7 +84,7 @@ _read(int fd, void *buf, size_t nbytes)
|
||||
* Check if the operation was
|
||||
* interrupted by a signal
|
||||
*/
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
break;
|
||||
@ -97,7 +99,7 @@ _read(int fd, void *buf, size_t nbytes)
|
||||
}
|
||||
|
||||
ssize_t
|
||||
read(int fd, void *buf, size_t nbytes)
|
||||
__read(int fd, void *buf, size_t nbytes)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
@ -107,4 +109,3 @@ read(int fd, void *buf, size_t nbytes)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -37,13 +37,15 @@
|
||||
#include <sys/uio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak readv=_readv
|
||||
|
||||
ssize_t
|
||||
_readv(int fd, const struct iovec * iov, int iovcnt)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
int type;
|
||||
|
||||
@ -61,14 +63,14 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
|
||||
}
|
||||
|
||||
/* Perform a non-blocking readv syscall: */
|
||||
while ((ret = _thread_sys_readv(fd, iov, iovcnt)) < 0) {
|
||||
while ((ret = __sys_readv(fd, iov, iovcnt)) < 0) {
|
||||
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
|
||||
(errno == EWOULDBLOCK || errno == EAGAIN)) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
_thread_kern_set_timeout(NULL);
|
||||
|
||||
/* Reset the interrupted operation flag: */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
_thread_kern_sched_state(PS_FDR_WAIT,
|
||||
__FILE__, __LINE__);
|
||||
@ -77,7 +79,7 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
|
||||
* Check if the operation was
|
||||
* interrupted by a signal
|
||||
*/
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
break;
|
||||
@ -90,6 +92,3 @@ _readv(int fd, const struct iovec * iov, int iovcnt)
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_readv, readv);
|
||||
#endif
|
||||
|
@ -35,28 +35,30 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak recvfrom=_recvfrom
|
||||
|
||||
ssize_t
|
||||
_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from,
|
||||
socklen_t *from_len)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
while ((ret = _thread_sys_recvfrom(fd, buf, len, flags, from, from_len)) < 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))) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(NULL);
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
|
||||
|
||||
/* Check if the wait was interrupted: */
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
/* Return an error status: */
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
@ -71,6 +73,3 @@ _recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from,
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_recvfrom, recvfrom);
|
||||
#endif
|
||||
|
@ -35,27 +35,29 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak recvmsg=_recvmsg
|
||||
|
||||
ssize_t
|
||||
_recvmsg(int fd, struct msghdr *msg, int flags)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
while ((ret = _thread_sys_recvmsg(fd, msg, flags)) < 0) {
|
||||
while ((ret = __sys_recvmsg(fd, msg, flags)) < 0) {
|
||||
if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(NULL);
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
|
||||
|
||||
/* Check if the wait was interrupted: */
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
/* Return an error status: */
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
@ -70,6 +72,3 @@ _recvmsg(int fd, struct msghdr *msg, int flags)
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_recvmsg, recvmsg);
|
||||
#endif
|
||||
|
@ -32,13 +32,14 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_resume_np=_pthread_resume_np
|
||||
|
||||
/* Resume a thread: */
|
||||
int
|
||||
pthread_resume_np(pthread_t thread)
|
||||
_pthread_resume_np(pthread_t thread)
|
||||
{
|
||||
int ret;
|
||||
enum pthread_susp old_suspended;
|
||||
@ -89,4 +90,3 @@ pthread_resume_np(pthread_t thread)
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -26,7 +26,6 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
@ -37,6 +36,14 @@
|
||||
/* maximum number of times a read lock may be obtained */
|
||||
#define MAX_READ_LOCKS (INT_MAX - 1)
|
||||
|
||||
#pragma weak pthread_rwlock_destroy=_pthread_rwlock_destroy
|
||||
#pragma weak pthread_rwlock_init=_pthread_rwlock_init
|
||||
#pragma weak pthread_rwlock_rdlock=_pthread_rwlock_rdlock
|
||||
#pragma weak pthread_rwlock_tryrdlock=_pthread_rwlock_tryrdlock
|
||||
#pragma weak pthread_rwlock_trywrlock=_pthread_rwlock_trywrlock
|
||||
#pragma weak pthread_rwlock_unlock=_pthread_rwlock_unlock
|
||||
#pragma weak pthread_rwlock_wrlock=_pthread_rwlock_wrlock
|
||||
|
||||
static int init_static (pthread_rwlock_t *rwlock);
|
||||
|
||||
static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER;
|
||||
@ -59,7 +66,7 @@ init_static (pthread_rwlock_t *rwlock)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
|
||||
_pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -84,7 +91,7 @@ pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
|
||||
_pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
|
||||
{
|
||||
pthread_rwlock_t prwlock;
|
||||
int ret;
|
||||
@ -127,7 +134,7 @@ pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
|
||||
_pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_t prwlock;
|
||||
int ret;
|
||||
@ -178,7 +185,7 @@ pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
|
||||
_pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_t prwlock;
|
||||
int ret;
|
||||
@ -215,7 +222,7 @@ pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
|
||||
_pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_t prwlock;
|
||||
int ret;
|
||||
@ -250,7 +257,7 @@ pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
|
||||
_pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_t prwlock;
|
||||
int ret;
|
||||
@ -287,7 +294,7 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
|
||||
_pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_t prwlock;
|
||||
int ret;
|
||||
@ -332,4 +339,3 @@ pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
|
||||
return(ret);
|
||||
}
|
||||
|
||||
#endif /* _THREAD_SAFE */
|
||||
|
@ -26,15 +26,19 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_rwlockattr_destroy=_pthread_rwlockattr_destroy
|
||||
#pragma weak pthread_rwlockattr_getpshared=_pthread_rwlockattr_getpshared
|
||||
#pragma weak pthread_rwlockattr_init=_pthread_rwlockattr_init
|
||||
#pragma weak pthread_rwlockattr_setpshared=_pthread_rwlockattr_setpshared
|
||||
|
||||
int
|
||||
pthread_rwlockattr_destroy(pthread_rwlockattr_t *rwlockattr)
|
||||
_pthread_rwlockattr_destroy(pthread_rwlockattr_t *rwlockattr)
|
||||
{
|
||||
pthread_rwlockattr_t prwlockattr;
|
||||
|
||||
@ -52,7 +56,7 @@ pthread_rwlockattr_destroy(pthread_rwlockattr_t *rwlockattr)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *rwlockattr,
|
||||
_pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *rwlockattr,
|
||||
int *pshared)
|
||||
{
|
||||
*pshared = (*rwlockattr)->pshared;
|
||||
@ -61,7 +65,7 @@ pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *rwlockattr,
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlockattr_init(pthread_rwlockattr_t *rwlockattr)
|
||||
_pthread_rwlockattr_init(pthread_rwlockattr_t *rwlockattr)
|
||||
{
|
||||
pthread_rwlockattr_t prwlockattr;
|
||||
|
||||
@ -81,7 +85,7 @@ pthread_rwlockattr_init(pthread_rwlockattr_t *rwlockattr)
|
||||
}
|
||||
|
||||
int
|
||||
pthread_rwlockattr_setpshared(pthread_rwlockattr_t *rwlockattr, int pshared)
|
||||
_pthread_rwlockattr_setpshared(pthread_rwlockattr_t *rwlockattr, int pshared)
|
||||
{
|
||||
/* Only PTHREAD_PROCESS_PRIVATE is supported. */
|
||||
if (pshared != PTHREAD_PROCESS_PRIVATE)
|
||||
@ -92,4 +96,3 @@ pthread_rwlockattr_setpshared(pthread_rwlockattr_t *rwlockattr, int pshared)
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif /* _THREAD_SAFE */
|
||||
|
@ -40,14 +40,16 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak select=_select
|
||||
|
||||
int
|
||||
_select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
|
||||
struct timeval * timeout)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
struct timespec ts;
|
||||
int i, ret = 0, f_wait = 1;
|
||||
int pfd_index, got_one = 0, fd_count = 0;
|
||||
@ -91,9 +93,9 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
|
||||
* Allocate memory for poll data if it hasn't already been
|
||||
* allocated or if previously allocated memory is insufficient.
|
||||
*/
|
||||
if ((_thread_run->poll_data.fds == NULL) ||
|
||||
(_thread_run->poll_data.nfds < fd_count)) {
|
||||
data.fds = (struct pollfd *) realloc(_thread_run->poll_data.fds,
|
||||
if ((curthread->poll_data.fds == NULL) ||
|
||||
(curthread->poll_data.nfds < fd_count)) {
|
||||
data.fds = (struct pollfd *) realloc(curthread->poll_data.fds,
|
||||
sizeof(struct pollfd) * MAX(128, fd_count));
|
||||
if (data.fds == NULL) {
|
||||
errno = ENOMEM;
|
||||
@ -105,13 +107,13 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
|
||||
* indicates what is allocated, not what is
|
||||
* currently being polled.
|
||||
*/
|
||||
_thread_run->poll_data.fds = data.fds;
|
||||
_thread_run->poll_data.nfds = MAX(128, fd_count);
|
||||
curthread->poll_data.fds = data.fds;
|
||||
curthread->poll_data.nfds = MAX(128, fd_count);
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
/* Setup the wait data. */
|
||||
data.fds = _thread_run->poll_data.fds;
|
||||
data.fds = curthread->poll_data.fds;
|
||||
data.nfds = fd_count;
|
||||
|
||||
/*
|
||||
@ -142,12 +144,12 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
|
||||
pfd_index--;
|
||||
}
|
||||
}
|
||||
if (((ret = _thread_sys_poll(data.fds, data.nfds, 0)) == 0) &&
|
||||
if (((ret = __sys_poll(data.fds, data.nfds, 0)) == 0) &&
|
||||
(f_wait != 0)) {
|
||||
_thread_run->data.poll_data = &data;
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->data.poll_data = &data;
|
||||
curthread->interrupted = 0;
|
||||
_thread_kern_sched_state(PS_SELECT_WAIT, __FILE__, __LINE__);
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
data.nfds = 0;
|
||||
ret = -1;
|
||||
@ -203,6 +205,3 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_select, select);
|
||||
#endif
|
||||
|
@ -31,14 +31,14 @@
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_self=_pthread_self
|
||||
|
||||
pthread_t
|
||||
pthread_self(void)
|
||||
_pthread_self(void)
|
||||
{
|
||||
/* Return the running thread pointer: */
|
||||
return (_thread_run);
|
||||
return (_get_curthread());
|
||||
}
|
||||
#endif
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <semaphore.h>
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
@ -43,8 +42,19 @@
|
||||
goto RETURN; \
|
||||
}
|
||||
|
||||
#pragma weak sem_init=_sem_init
|
||||
#pragma weak sem_destroy=_sem_destroy
|
||||
#pragma weak sem_open=_sem_open
|
||||
#pragma weak sem_close=_sem_close
|
||||
#pragma weak sem_unlink=_sem_unlink
|
||||
#pragma weak sem_wait=_sem_wait
|
||||
#pragma weak sem_trywait=_sem_trywait
|
||||
#pragma weak sem_post=_sem_post
|
||||
#pragma weak sem_getvalue=_sem_getvalue
|
||||
|
||||
|
||||
int
|
||||
sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
_sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -103,7 +113,7 @@ sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
}
|
||||
|
||||
int
|
||||
sem_destroy(sem_t *sem)
|
||||
_sem_destroy(sem_t *sem)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -131,28 +141,28 @@ sem_destroy(sem_t *sem)
|
||||
}
|
||||
|
||||
sem_t *
|
||||
sem_open(const char *name, int oflag, ...)
|
||||
_sem_open(const char *name, int oflag, ...)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return SEM_FAILED;
|
||||
}
|
||||
|
||||
int
|
||||
sem_close(sem_t *sem)
|
||||
_sem_close(sem_t *sem)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
sem_unlink(const char *name)
|
||||
_sem_unlink(const char *name)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
sem_wait(sem_t *sem)
|
||||
_sem_wait(sem_t *sem)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -178,7 +188,7 @@ sem_wait(sem_t *sem)
|
||||
}
|
||||
|
||||
int
|
||||
sem_trywait(sem_t *sem)
|
||||
_sem_trywait(sem_t *sem)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -201,7 +211,7 @@ sem_trywait(sem_t *sem)
|
||||
}
|
||||
|
||||
int
|
||||
sem_post(sem_t *sem)
|
||||
_sem_post(sem_t *sem)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -235,7 +245,7 @@ sem_post(sem_t *sem)
|
||||
}
|
||||
|
||||
int
|
||||
sem_getvalue(sem_t *sem, int *sval)
|
||||
_sem_getvalue(sem_t *sem, int *sval)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -249,4 +259,3 @@ sem_getvalue(sem_t *sem, int *sval)
|
||||
RETURN:
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
@ -34,14 +34,16 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <errno.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak sendfile=_sendfile
|
||||
|
||||
int
|
||||
sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
|
||||
_sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
|
||||
off_t *sbytes, int flags)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret, type, blocking;
|
||||
ssize_t wvret, num = 0;
|
||||
off_t n, nwritten = 0;
|
||||
@ -92,7 +94,7 @@ sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
|
||||
*/
|
||||
for (;;) {
|
||||
/* Perform a non-blocking sendfile syscall. */
|
||||
ret = _thread_sys_sendfile(fd, s, offset + num, nbytes - num,
|
||||
ret = __sys_sendfile(fd, s, offset + num, nbytes - num,
|
||||
NULL, &n, flags);
|
||||
|
||||
if (ret == 0) {
|
||||
@ -108,16 +110,16 @@ sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
|
||||
/* Update the count of bytes written. */
|
||||
num += n;
|
||||
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
_thread_kern_set_timeout(NULL);
|
||||
|
||||
/* Reset the interrupted operation flag. */
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
|
||||
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__,
|
||||
__LINE__);
|
||||
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
/* Interrupted by a signal. Return an error. */
|
||||
break;
|
||||
}
|
||||
@ -151,4 +153,3 @@ sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -35,27 +35,29 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak sendmsg=_sendmsg
|
||||
|
||||
ssize_t
|
||||
_sendmsg(int fd, const struct msghdr *msg, int flags)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
|
||||
while ((ret = _thread_sys_sendmsg(fd, msg, flags)) < 0) {
|
||||
while ((ret = __sys_sendmsg(fd, msg, flags)) < 0) {
|
||||
if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(NULL);
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
|
||||
|
||||
/* Check if the operation was interrupted: */
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
break;
|
||||
@ -69,6 +71,3 @@ _sendmsg(int fd, const struct msghdr *msg, int flags)
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_sendmsg, sendmsg);
|
||||
#endif
|
||||
|
@ -35,28 +35,30 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak sendto=_sendto
|
||||
|
||||
ssize_t
|
||||
_sendto(int fd, const void *msg, size_t len, int flags, const struct
|
||||
sockaddr * to, socklen_t to_len)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
|
||||
while ((ret = _thread_sys_sendto(fd, msg, len, flags, to, to_len)) < 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))) {
|
||||
_thread_run->data.fd.fd = fd;
|
||||
curthread->data.fd.fd = fd;
|
||||
|
||||
/* Set the timeout: */
|
||||
_thread_kern_set_timeout(NULL);
|
||||
_thread_run->interrupted = 0;
|
||||
curthread->interrupted = 0;
|
||||
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
|
||||
|
||||
/* Check if the operation was interrupted: */
|
||||
if (_thread_run->interrupted) {
|
||||
if (curthread->interrupted) {
|
||||
errno = EINTR;
|
||||
ret = -1;
|
||||
break;
|
||||
@ -70,6 +72,3 @@ _sendto(int fd, const void *msg, size_t len, int flags, const struct
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_sendto, sendto);
|
||||
#endif
|
||||
|
@ -31,7 +31,6 @@
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
@ -58,4 +57,3 @@ _thread_seterrno(pthread_t thread, int error)
|
||||
*/
|
||||
thread->error = error;
|
||||
}
|
||||
#endif
|
||||
|
@ -31,12 +31,13 @@
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_setprio=_pthread_setprio
|
||||
|
||||
int
|
||||
pthread_setprio(pthread_t pthread, int prio)
|
||||
_pthread_setprio(pthread_t pthread, int prio)
|
||||
{
|
||||
int ret, policy;
|
||||
struct sched_param param;
|
||||
@ -49,4 +50,3 @@ pthread_setprio(pthread_t pthread, int prio)
|
||||
/* Return the error status: */
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,12 +33,13 @@
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak pthread_setschedparam=_pthread_setschedparam
|
||||
|
||||
int
|
||||
pthread_setschedparam(pthread_t pthread, int policy,
|
||||
_pthread_setschedparam(pthread_t pthread, int policy,
|
||||
const struct sched_param *param)
|
||||
{
|
||||
int old_prio, in_readyq = 0, ret = 0;
|
||||
@ -116,4 +117,3 @@ pthread_setschedparam(pthread_t pthread, int policy,
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -33,10 +33,11 @@
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak setsockopt=_setsockopt
|
||||
|
||||
int
|
||||
_setsockopt(int fd, int level, int optname, const void *optval, socklen_t
|
||||
optlen)
|
||||
@ -44,11 +45,8 @@ _setsockopt(int fd, int level, int optname, const void *optval, socklen_t
|
||||
int ret;
|
||||
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_setsockopt(fd, level, optname, optval, optlen);
|
||||
ret = __sys_setsockopt(fd, level, optname, optval, optlen);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_reference(_setsockopt, setsockopt);
|
||||
#endif
|
||||
|
@ -34,10 +34,11 @@
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef _THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#pragma weak shutdown=_shutdown
|
||||
|
||||
int
|
||||
_shutdown(int fd, int how)
|
||||
{
|
||||
@ -46,19 +47,19 @@ _shutdown(int fd, int how)
|
||||
switch (how) {
|
||||
case 0:
|
||||
if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) {
|
||||
ret = _thread_sys_shutdown(fd, how);
|
||||
ret = __sys_shutdown(fd, how);
|
||||
_FD_UNLOCK(fd, FD_READ);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) {
|
||||
ret = _thread_sys_shutdown(fd, how);
|
||||
ret = __sys_shutdown(fd, how);
|
||||
_FD_UNLOCK(fd, FD_WRITE);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
|
||||
ret = _thread_sys_shutdown(fd, how);
|
||||
ret = __sys_shutdown(fd, how);
|
||||
_FD_UNLOCK(fd, FD_RDWR);
|
||||
}
|
||||
break;
|
||||
@ -69,6 +70,3 @@ _shutdown(int fd, int how)
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
__strong_reference(_shutdown, shutdown);
|
||||
#endif
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user