diff options
author | deischen <deischen@FreeBSD.org> | 2001-01-24 13:03:38 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2001-01-24 13:03:38 +0000 |
commit | ee1de6a067c70fbd8cb73facd64c3b0b275f9f83 (patch) | |
tree | 71d2853de2f283028592fa4119320bab82c18d68 /lib/libkse/thread/thr_select.c | |
parent | 274959d59337555267567d4bde9a5a841c47d84f (diff) | |
download | FreeBSD-src-ee1de6a067c70fbd8cb73facd64c3b0b275f9f83.zip FreeBSD-src-ee1de6a067c70fbd8cb73facd64c3b0b275f9f83.tar.gz |
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
Diffstat (limited to 'lib/libkse/thread/thr_select.c')
-rw-r--r-- | lib/libkse/thread/thr_select.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c index 0a7c0d4..547046a 100644 --- a/lib/libkse/thread/thr_select.c +++ b/lib/libkse/thread/thr_select.c @@ -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 |