From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 524 invoked by alias); 2 May 2004 13:09:04 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 507 invoked from network); 2 May 2004 13:09:03 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.15.26) by sources.redhat.com with SMTP; 2 May 2004 13:09:03 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id i42Auo3j016892; Sun, 2 May 2004 12:56:50 +0200 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id i42AuokA016886; Sun, 2 May 2004 12:56:50 +0200 Date: Sun, 02 May 2004 13:09:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Use *_not_cancel instead of __libc_* in linuxthreads Message-ID: <20040502105650.GE5191@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2004-05/txt/msg00003.txt.bz2 Hi! Probably it is not necessary in all places, but certainly in the past the __libc_{read,write,close,waitpid} routines weren't a cancellation point and if linuxthreads wanted to use cancellation point, it would just use the non-__libc_ variants. 2004-05-02 Jakub Jelinek * manager.c: Include not-cancel.h. (__pthread_manager): Use read_not_cancel instead of __libc_read. (pthread_start_thread, __pthread_manager_sighandler): Use write_not_cancel instead of __libc_write. (pthread_reap_children): Use waitpid_not_cancel instead of __libc_waitpid. * pthread.c: Include not-cancel.h. (__pthread_initialize_minimal, __pthread_create_2_1, pthread_onexit_process, __pthread_message): Use write_not_cancel instead of __libc_write. (__pthread_initialize_manager): Likewise. Use close_not_cancel instead of __libc_close. (__pthread_reset_main_thread): Use close_not_cancel instead of __libc_close. * join.c: Include not-cancel.h. (__pthread_do_exit, pthread_join, pthread_detach): Use write_not_cancel instead of __libc_write. * semaphore.c: Include not-cancel.h. (__new_sem_post): Use write_not_cancel instead of __libc_write. * specific.c: Include not-cancel.h. (pthread_key_delete): Use write_not_cancel instead of __libc_write. --- libc/linuxthreads/manager.c.jj 2004-05-02 12:56:45.000000000 +0200 +++ libc/linuxthreads/manager.c 2004-05-02 13:02:39.760579503 +0200 @@ -36,6 +36,7 @@ #include "spinlock.h" #include "restart.h" #include "semaphore.h" +#include /* For debugging purposes put the maximum number of threads in a variable. */ const int __linuxthreads_pthread_threads_max = PTHREAD_THREADS_MAX; @@ -141,8 +142,8 @@ __pthread_manager(void *arg) /* Raise our priority to match that of main thread */ __pthread_manager_adjust_prio(__pthread_main_thread->p_priority); /* Synchronize debugging of the thread manager */ - n = TEMP_FAILURE_RETRY(__libc_read(reqfd, (char *)&request, - sizeof(request))); + n = TEMP_FAILURE_RETRY(read_not_cancel(reqfd, (char *)&request, + sizeof(request))); ASSERT(n == sizeof(request) && request.req_kind == REQ_DEBUG); ufd.fd = reqfd; ufd.events = POLLIN; @@ -162,8 +163,8 @@ __pthread_manager(void *arg) } /* Read and execute request */ if (n == 1 && (ufd.revents & POLLIN)) { - n = TEMP_FAILURE_RETRY(__libc_read(reqfd, (char *)&request, - sizeof(request))); + n = TEMP_FAILURE_RETRY(read_not_cancel(reqfd, (char *)&request, + sizeof(request))); #ifdef DEBUG if (n < 0) { char d[64]; @@ -301,8 +302,8 @@ pthread_start_thread(void *arg) if (__pthread_threads_debug && __pthread_sig_debug > 0) { request.req_thread = self; request.req_kind = REQ_DEBUG; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); suspend(self); } /* Run the thread code */ @@ -970,7 +971,7 @@ static void pthread_reap_children(void) pid_t pid; int status; - while ((pid = __libc_waitpid(-1, &status, WNOHANG | __WCLONE)) > 0) { + while ((pid = waitpid_not_cancel(-1, &status, WNOHANG | __WCLONE)) > 0) { pthread_exited(pid); if (WIFSIGNALED(status)) { /* If a thread died due to a signal, send the same signal to @@ -1090,8 +1091,8 @@ void __pthread_manager_sighandler(int si struct pthread_request request; request.req_thread = 0; request.req_kind = REQ_KICK; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); } } --- libc/linuxthreads/pthread.c.jj 2003-12-19 17:54:29.000000000 +0100 +++ libc/linuxthreads/pthread.c 2004-05-02 13:45:42.000000000 +0200 @@ -34,6 +34,7 @@ #include #include #include +#include /* Sanity check. */ #if !defined __SIGRTMIN || (__SIGRTMAX - __SIGRTMIN) < 3 @@ -328,8 +329,8 @@ __pthread_initialize_minimal(void) { static const char msg[] = "\ cannot allocate TLS data structures for initial thread\n"; - TEMP_FAILURE_RETRY (__libc_write (STDERR_FILENO, - msg, sizeof msg - 1)); + TEMP_FAILURE_RETRY (write_not_cancel (STDERR_FILENO, + msg, sizeof msg - 1)); abort (); } const char *lossage = TLS_INIT_TP (tcbp, 0); @@ -337,11 +338,11 @@ cannot allocate TLS data structures for { static const char msg[] = "cannot set up thread-local storage: "; const char nl = '\n'; - TEMP_FAILURE_RETRY (__libc_write (STDERR_FILENO, - msg, sizeof msg - 1)); - TEMP_FAILURE_RETRY (__libc_write (STDERR_FILENO, - lossage, strlen (lossage))); - TEMP_FAILURE_RETRY (__libc_write (STDERR_FILENO, &nl, 1)); + TEMP_FAILURE_RETRY (write_not_cancel (STDERR_FILENO, + msg, sizeof msg - 1)); + TEMP_FAILURE_RETRY (write_not_cancel (STDERR_FILENO, + lossage, strlen (lossage))); + TEMP_FAILURE_RETRY (write_not_cancel (STDERR_FILENO, &nl, 1)); } /* Though it was allocated with libc's malloc, that was done without @@ -657,8 +658,8 @@ int __pthread_initialize_manager(void) tcbp = _dl_allocate_tls (NULL); if (tcbp == NULL) { free(__pthread_manager_thread_bos); - __libc_close(manager_pipe[0]); - __libc_close(manager_pipe[1]); + close_not_cancel(manager_pipe[0]); + close_not_cancel(manager_pipe[1]); return -1; } @@ -787,8 +788,8 @@ int __pthread_initialize_manager(void) _dl_deallocate_tls (tcbp, true); #endif free(__pthread_manager_thread_bos); - __libc_close(manager_pipe[0]); - __libc_close(manager_pipe[1]); + close_not_cancel(manager_pipe[0]); + close_not_cancel(manager_pipe[1]); return -1; } mgr->p_tid = 2* PTHREAD_THREADS_MAX + 1; @@ -803,8 +804,8 @@ int __pthread_initialize_manager(void) } /* Synchronize debugging of the thread manager */ request.req_kind = REQ_DEBUG; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); return 0; } @@ -826,8 +827,8 @@ int __pthread_create_2_1(pthread_t *thre request.req_args.create.arg = arg; sigprocmask(SIG_SETMASK, (const sigset_t *) NULL, &request.req_args.create.mask); - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); suspend(self); retval = THREAD_GETMEM(self, p_retcode); if (__builtin_expect (retval, 0) == 0) @@ -1004,8 +1005,8 @@ static void pthread_onexit_process(int r request.req_thread = self; request.req_kind = REQ_PROCESS_EXIT; request.req_args.exit.code = retcode; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); suspend(self); /* Main thread should accumulate times for thread manager and its children, so that timings for main thread account for all threads. */ @@ -1127,8 +1128,8 @@ void __pthread_reset_main_thread(void) free(__pthread_manager_thread_bos); __pthread_manager_thread_bos = __pthread_manager_thread_tos = NULL; /* Close the two ends of the pipe */ - __libc_close(__pthread_manager_request); - __libc_close(__pthread_manager_reader); + close_not_cancel(__pthread_manager_request); + close_not_cancel(__pthread_manager_reader); __pthread_manager_request = __pthread_manager_reader = -1; } @@ -1399,7 +1400,7 @@ void __pthread_message(const char * fmt, va_start(args, fmt); vsnprintf(buffer + 8, sizeof(buffer) - 8, fmt, args); va_end(args); - TEMP_FAILURE_RETRY(__libc_write(2, buffer, strlen(buffer))); + TEMP_FAILURE_RETRY(write_not_cancel(2, buffer, strlen(buffer))); } #endif --- libc/linuxthreads/join.c.jj 2004-05-02 12:56:31.000000000 +0200 +++ libc/linuxthreads/join.c 2004-05-02 14:06:45.263415328 +0200 @@ -22,6 +22,7 @@ #include "internals.h" #include "spinlock.h" #include "restart.h" +#include void __pthread_exit(void * retval) { @@ -78,8 +79,8 @@ void __pthread_do_exit(void *retval, cha if (self == __pthread_main_thread && __pthread_manager_request >= 0) { request.req_thread = self; request.req_kind = REQ_MAIN_THREAD_EXIT; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *)&request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *)&request, sizeof(request))); suspend(self); /* Main thread flushes stdio streams and runs atexit functions. It also calls a handler within LinuxThreads which sends a process exit @@ -174,8 +175,8 @@ int pthread_join(pthread_t thread_id, vo request.req_thread = self; request.req_kind = REQ_FREE; request.req_args.free.thread_id = thread_id; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); } return 0; } @@ -212,8 +213,8 @@ int pthread_detach(pthread_t thread_id) request.req_thread = thread_self(); request.req_kind = REQ_FREE; request.req_args.free.thread_id = thread_id; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); } return 0; } --- libc/linuxthreads/semaphore.c.jj 2004-04-28 20:43:02.000000000 +0200 +++ libc/linuxthreads/semaphore.c 2004-05-02 13:46:11.000000000 +0200 @@ -22,6 +22,7 @@ #include "restart.h" #include "queue.h" #include +#include int __new_sem_init(sem_t *sem, int pshared, unsigned int value) { @@ -168,8 +169,8 @@ int __new_sem_post(sem_t * sem) } request.req_kind = REQ_POST; request.req_args.post = sem; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); } return 0; } --- libc/linuxthreads/specific.c.jj 2003-02-20 00:59:44.000000000 +0100 +++ libc/linuxthreads/specific.c 2004-05-02 13:46:55.000000000 +0200 @@ -22,7 +22,7 @@ #include "spinlock.h" #include "restart.h" #include - +#include /* Table of keys. */ @@ -120,8 +120,8 @@ int pthread_key_delete(pthread_key_t key request.req_args.for_each.arg = &args; request.req_args.for_each.fn = pthread_key_delete_helper; - TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request, - (char *) &request, sizeof(request))); + TEMP_FAILURE_RETRY(write_not_cancel(__pthread_manager_request, + (char *) &request, sizeof(request))); suspend(self); } Jakub