From e5106342c6de9cbe26c4827e4e29bae309cd8cfb Mon Sep 17 00:00:00 2001 From: Daniel Eischen Date: Wed, 24 Jan 2001 13:03:38 +0000 Subject: 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 --- lib/libpthread/thread/thr_write.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/libpthread/thread/thr_write.c') diff --git a/lib/libpthread/thread/thr_write.c b/lib/libpthread/thread/thr_write.c index 5d9ef35f3fbc..b841726c8d10 100644 --- a/lib/libpthread/thread/thr_write.c +++ b/lib/libpthread/thread/thr_write.c @@ -37,13 +37,15 @@ #include #include #include -#ifdef _THREAD_SAFE #include #include "pthread_private.h" +#pragma weak write=__write + ssize_t _write(int fd, const void *buf, size_t nbytes) { + struct pthread *curthread = _get_curthread(); int blocking; int type; ssize_t n; @@ -76,7 +78,7 @@ _write(int fd, const void *buf, size_t nbytes) */ while (ret == 0) { /* Perform a non-blocking write syscall: */ - n = _thread_sys_write(fd, buf + num, nbytes - num); + n = __sys_write(fd, buf + num, nbytes - num); /* Check if one or more bytes were written: */ if (n > 0) @@ -94,11 +96,11 @@ _write(int fd, const void *buf, size_t nbytes) */ if (blocking && ((n < 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) || (n >= 0 && num < nbytes))) { - _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__); @@ -107,7 +109,7 @@ _write(int fd, const void *buf, size_t nbytes) * Check if the operation was * interrupted by a signal */ - if (_thread_run->interrupted) { + if (curthread->interrupted) { /* Return an error: */ ret = -1; } @@ -133,7 +135,7 @@ _write(int fd, const void *buf, size_t nbytes) } ssize_t -write(int fd, const void *buf, size_t nbytes) +__write(int fd, const void *buf, size_t nbytes) { ssize_t ret; @@ -143,4 +145,3 @@ write(int fd, const void *buf, size_t nbytes) return ret; } -#endif -- cgit v1.2.3