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/libpthread/thread/thr_info.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/libpthread/thread/thr_info.c')
-rw-r--r-- | lib/libpthread/thread/thr_info.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/libpthread/thread/thr_info.c b/lib/libpthread/thread/thr_info.c index 956ae7c..9c85e84 100644 --- a/lib/libpthread/thread/thr_info.c +++ b/lib/libpthread/thread/thr_info.c @@ -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 |