diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-08-03 07:29:27 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-08-03 07:29:27 +0000 |
commit | 139a4d957a49107e0528e60913f3eb565c691da3 (patch) | |
tree | 0d37efcd9c246629ad935e631efb83006eed6faf /linuxthreads | |
parent | aaf688e85f11a2e6d2fc7b9afbf81e15e146f766 (diff) | |
download | glibc-139a4d957a49107e0528e60913f3eb565c691da3.tar glibc-139a4d957a49107e0528e60913f3eb565c691da3.tar.gz glibc-139a4d957a49107e0528e60913f3eb565c691da3.tar.bz2 glibc-139a4d957a49107e0528e60913f3eb565c691da3.zip |
Update.
2000-08-03 Ulrich Drepper <drepper@redhat.com>
* iconvdata/big5.c: Updated.
Patch by Tung-Han Hsieh <thhsieh@twcpro.phys.ntu.edu.tw>.
Diffstat (limited to 'linuxthreads')
-rw-r--r-- | linuxthreads/ChangeLog | 15 | ||||
-rw-r--r-- | linuxthreads/internals.h | 1 | ||||
-rw-r--r-- | linuxthreads/mutex.c | 3 | ||||
-rw-r--r-- | linuxthreads/pthread.c | 49 | ||||
-rw-r--r-- | linuxthreads/rwlock.c | 44 | ||||
-rw-r--r-- | linuxthreads/spinlock.h | 15 |
6 files changed, 76 insertions, 51 deletions
diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog index 65816bb8b0..e80114f174 100644 --- a/linuxthreads/ChangeLog +++ b/linuxthreads/ChangeLog @@ -1,3 +1,18 @@ +2000-08-03 Ulrich Drepper <drepper@redhat.com> + + * pthread.c: Move definition of __pthread_set_own_extricate_if... + * spinlock.h: ...here. Remove locking. + * internals.h: Remove __pthread_set_own_extricate_if prototype. + + * rwlock.c: Use THREAD_GETMEM And THREAD_SETMEM. + (rwlock_rd_extricate_func): Don't determine self, let + __pthread_lock do it. + (rwlock_wr_extricate_func): Likewise. + (rwlock_have_already): Optimize *pself handling a bit. + + * mutex.c: Use __builtin_expect. + * pthread.c: Likewise. + 2000-08-02 Andreas Jaeger <aj@suse.de> * linuxthreads/sysdeps/s390/pspinlock.c: New file. diff --git a/linuxthreads/internals.h b/linuxthreads/internals.h index 93ec93620c..fa6bf6b9cd 100644 --- a/linuxthreads/internals.h +++ b/linuxthreads/internals.h @@ -434,7 +434,6 @@ void __flockfilelist(void); void __funlockfilelist(void); void __fresetlockfiles(void); void __pthread_manager_adjust_prio(int thread_prio); -void __pthread_set_own_extricate_if(pthread_descr self, pthread_extricate_if *peif); extern int __pthread_attr_setguardsize (pthread_attr_t *__attr, size_t __guardsize); diff --git a/linuxthreads/mutex.c b/linuxthreads/mutex.c index d7674ffadd..ae070e5b93 100644 --- a/linuxthreads/mutex.c +++ b/linuxthreads/mutex.c @@ -118,7 +118,8 @@ int __pthread_mutex_timedlock (pthread_mutex_t *mutex, pthread_descr self; int res; - if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) + if (__builtin_expect (abstime->tv_nsec, 0) < 0 + || __builtin_expect (abstime->tv_nsec, 0) >= 1000000000) return EINVAL; switch(mutex->__m_kind) { diff --git a/linuxthreads/pthread.c b/linuxthreads/pthread.c index 41fbdc0f24..8aaa4b4ccd 100644 --- a/linuxthreads/pthread.c +++ b/linuxthreads/pthread.c @@ -250,7 +250,7 @@ static void init_rtsigs (void) { #if !__ASSUME_REALTIME_SIGNALS - if (!kernel_has_rtsig ()) + if (__builtin_expect (!kernel_has_rtsig (), 0)) { current_rtmin = -1; current_rtmax = -1; @@ -286,7 +286,7 @@ int __libc_current_sigrtmin (void) { #ifdef __SIGRTMIN - if (!rtsigs_initialized) + if (__builtin_expect (!rtsigs_initialized, 0)) init_rtsigs (); #endif return current_rtmin; @@ -297,7 +297,7 @@ int __libc_current_sigrtmax (void) { #ifdef __SIGRTMIN - if (!rtsigs_initialized) + if (__builtin_expect (!rtsigs_initialized, 0)) init_rtsigs (); #endif return current_rtmax; @@ -312,9 +312,10 @@ __libc_allocate_rtsig (int high) #ifndef __SIGRTMIN return -1; #else - if (!rtsigs_initialized) + if (__builtin_expect (!rtsigs_initialized, 0)) init_rtsigs (); - if (current_rtmin == -1 || current_rtmin > current_rtmax) + if (__builtin_expect (current_rtmin == -1, 0) + || __builtin_expect (current_rtmin > current_rtmax, 0)) /* We don't have anymore signal available. */ return -1; @@ -343,7 +344,7 @@ is_smp_system (void) { /*This was not successful. Now try reading the /proc filesystem. */ int fd = __open ("/proc/sys/kernel/version", O_RDONLY); - if (fd == -1 + if (__builtin_expect (fd, 0) == -1 || (reslen = __read (fd, buf, sizeof (buf))) <= 0) /* This also didn't work. We give up and say it's a UP machine. */ buf[0] = '\0'; @@ -430,7 +431,7 @@ static void pthread_initialize(void) /* Register an exit function to kill all other threads. */ /* Do it early so that user-registered atexit functions are called before pthread_exit_process. */ - if (&__dso_handle != NULL) + if (__builtin_expect (&__dso_handle != NULL, 1)) /* The cast is a bit unclean. The function expects two arguments but we can only pass one. Fortunately this is not a problem since the second argument of `pthread_exit_process' is simply ignored. */ @@ -483,7 +484,7 @@ int __pthread_initialize_manager(void) } /* Start the thread manager */ pid = 0; - if (__pthread_initial_thread.p_report_events) + if (__builtin_expect (__pthread_initial_thread.p_report_events, 0)) { /* It's a bit more complicated. We have to report the creation of the manager thread. */ @@ -531,7 +532,7 @@ int __pthread_initialize_manager(void) } } - if (pid == 0) + if (__builtin_expect (pid, 0) == 0) { #ifdef NEED_SEPARATE_REGISTER_STACK pid = __clone2(__pthread_manager, (void **) __pthread_manager_thread_bos, @@ -544,7 +545,7 @@ int __pthread_initialize_manager(void) (void *)(long)manager_pipe[0]); #endif } - if (pid == -1) { + if (__builtin_expect (pid, 0) == -1) { free(__pthread_manager_thread_bos); __libc_close(manager_pipe[0]); __libc_close(manager_pipe[1]); @@ -555,7 +556,7 @@ int __pthread_initialize_manager(void) __pthread_manager_thread.p_tid = 2* PTHREAD_THREADS_MAX + 1; __pthread_manager_thread.p_pid = pid; /* Make gdb aware of new thread manager */ - if (__pthread_threads_debug && __pthread_sig_debug > 0) + if (__builtin_expect (__pthread_threads_debug, 0) && __pthread_sig_debug > 0) { raise(__pthread_sig_debug); /* We suspend ourself and gdb will wake us up when it is @@ -576,7 +577,7 @@ int __pthread_create_2_1(pthread_t *thread, const pthread_attr_t *attr, pthread_descr self = thread_self(); struct pthread_request request; int retval; - if (__pthread_manager_request < 0) { + if (__builtin_expect (__pthread_manager_request, 0) < 0) { if (__pthread_initialize_manager() < 0) return EAGAIN; } request.req_thread = self; @@ -589,7 +590,7 @@ int __pthread_create_2_1(pthread_t *thread, const pthread_attr_t *attr, __libc_write(__pthread_manager_request, (char *) &request, sizeof(request)); suspend(self); retval = THREAD_GETMEM(self, p_retcode); - if (retval == 0) + if (__builtin_expect (retval, 0) == 0) *thread = (pthread_t) THREAD_GETMEM(self, p_retval); return retval; } @@ -663,12 +664,13 @@ int pthread_setschedparam(pthread_t thread, int policy, pthread_descr th; __pthread_lock(&handle->h_lock, NULL); - if (invalid_handle(handle, thread)) { + if (__builtin_expect (invalid_handle(handle, thread), 0)) { __pthread_unlock(&handle->h_lock); return ESRCH; } th = handle->h_descr; - if (__sched_setscheduler(th->p_pid, policy, param) == -1) { + if (__builtin_expect (__sched_setscheduler(th->p_pid, policy, param) == -1, + 0)) { __pthread_unlock(&handle->h_lock); return errno; } @@ -686,14 +688,14 @@ int pthread_getschedparam(pthread_t thread, int *policy, int pid, pol; __pthread_lock(&handle->h_lock, NULL); - if (invalid_handle(handle, thread)) { + if (__builtin_expect (invalid_handle(handle, thread), 0)) { __pthread_unlock(&handle->h_lock); return ESRCH; } pid = handle->h_descr->p_pid; __pthread_unlock(&handle->h_lock); pol = __sched_getscheduler(pid); - if (pol == -1) return errno; + if (__builtin_expect (pol, 0) == -1) return errno; if (__sched_getparam(pid, param) == -1) return errno; *policy = pol; return 0; @@ -713,7 +715,7 @@ static void pthread_exit_process(int retcode, void *arg) struct pthread_request request; pthread_descr self = thread_self(); - if (__pthread_manager_request >= 0) { + if (__builtin_expect (__pthread_manager_request, 0) >= 0) { request.req_thread = self; request.req_kind = REQ_PROCESS_EXIT; request.req_args.exit.code = retcode; @@ -754,14 +756,14 @@ static void pthread_handle_sigcancel(int sig) __pthread_manager_sighandler(sig); return; } - if (__pthread_exit_requested) { + if (__builtin_expect (__pthread_exit_requested, 0)) { /* Main thread should accumulate times for thread manager and its children, so that timings for main thread account for all threads. */ if (self == __pthread_main_thread) waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE); _exit(__pthread_exit_code); } - if (THREAD_GETMEM(self, p_canceled) + if (__builtin_expect (THREAD_GETMEM(self, p_canceled), 0) && THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE) { if (THREAD_GETMEM(self, p_canceltype) == PTHREAD_CANCEL_ASYNCHRONOUS) pthread_exit(PTHREAD_CANCELED); @@ -868,13 +870,6 @@ int __pthread_getconcurrency(void) } weak_alias (__pthread_getconcurrency, pthread_getconcurrency) -void __pthread_set_own_extricate_if(pthread_descr self, pthread_extricate_if *peif) -{ - __pthread_lock(THREAD_GETMEM(self, p_lock), self); - THREAD_SETMEM(self, p_extricate, peif); - __pthread_unlock(THREAD_GETMEM (self, p_lock)); -} - /* Primitives for controlling thread execution */ void __pthread_wait_for_restart_signal(pthread_descr self) diff --git a/linuxthreads/rwlock.c b/linuxthreads/rwlock.c index 9258978e2f..635f4655df 100644 --- a/linuxthreads/rwlock.c +++ b/linuxthreads/rwlock.c @@ -32,11 +32,10 @@ static int rwlock_rd_extricate_func(void *obj, pthread_descr th) { - volatile pthread_descr self = thread_self(); pthread_rwlock_t *rwlock = obj; int did_remove = 0; - __pthread_lock((struct _pthread_fastlock *) &rwlock->__rw_lock, self); + __pthread_lock((struct _pthread_fastlock *) &rwlock->__rw_lock, NULL); did_remove = remove_from_queue(&rwlock->__rw_read_waiting, th); __pthread_unlock((struct _pthread_fastlock *) &rwlock->__rw_lock); @@ -45,11 +44,10 @@ static int rwlock_rd_extricate_func(void *obj, pthread_descr th) static int rwlock_wr_extricate_func(void *obj, pthread_descr th) { - volatile pthread_descr self = thread_self(); pthread_rwlock_t *rwlock = obj; int did_remove = 0; - __pthread_lock((struct _pthread_fastlock *) &rwlock->__rw_lock, self); + __pthread_lock((struct _pthread_fastlock *) &rwlock->__rw_lock, NULL); did_remove = remove_from_queue(&rwlock->__rw_write_waiting, th); __pthread_unlock((struct _pthread_fastlock *) &rwlock->__rw_lock); @@ -67,7 +65,8 @@ rwlock_is_in_list(pthread_descr self, pthread_rwlock_t *rwlock) { pthread_readlock_info *info; - for (info = self->p_readlock_list; info != NULL; info = info->pr_next) + for (info = THREAD_GETMEM (self, p_readlock_list); info != NULL; + info = info->pr_next) { if (info->pr_lock == rwlock) return info; @@ -87,10 +86,10 @@ rwlock_is_in_list(pthread_descr self, pthread_rwlock_t *rwlock) static pthread_readlock_info * rwlock_add_to_list(pthread_descr self, pthread_rwlock_t *rwlock) { - pthread_readlock_info *info = self->p_readlock_free; + pthread_readlock_info *info = THREAD_GETMEM (self, p_readlock_free); if (info != NULL) - self->p_readlock_free = info->pr_next; + THREAD_SETMEM (self, p_readlock_free, info->pr_next); else info = malloc(sizeof *info); @@ -99,8 +98,8 @@ rwlock_add_to_list(pthread_descr self, pthread_rwlock_t *rwlock) info->pr_lock_count = 1; info->pr_lock = rwlock; - info->pr_next = self->p_readlock_list; - self->p_readlock_list = info; + info->pr_next = THREAD_GETMEM (self, p_readlock_list); + THREAD_SETMEM (self, p_readlock_list, info); return info; } @@ -190,11 +189,12 @@ rwlock_have_already(pthread_descr *pself, pthread_rwlock_t *rwlock, if (rwlock->__rw_kind == PTHREAD_RWLOCK_PREFER_WRITER_NP) { if (!self) - self = thread_self(); + *pself = self = thread_self(); existing = rwlock_is_in_list(self, rwlock); - if (existing != NULL || self->p_untracked_readlock_count > 0) + if (existing != NULL + || THREAD_GETMEM (self, p_untracked_readlock_count) > 0) have_lock_already = 1; else { @@ -206,7 +206,6 @@ rwlock_have_already(pthread_descr *pself, pthread_rwlock_t *rwlock, *pout_of_mem = out_of_mem; *pexisting = existing; - *pself = self; return have_lock_already; } @@ -286,9 +285,9 @@ __pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) if (have_lock_already || out_of_mem) { if (existing != NULL) - existing->pr_lock_count++; + ++existing->pr_lock_count; else - self->p_untracked_readlock_count++; + ++self->p_untracked_readlock_count; } return 0; @@ -357,9 +356,9 @@ __pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, if (have_lock_already || out_of_mem) { if (existing != NULL) - existing->pr_lock_count++; + ++existing->pr_lock_count; else - self->p_untracked_readlock_count++; + ++self->p_untracked_readlock_count; } return 0; @@ -398,9 +397,9 @@ __pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) if (have_lock_already || out_of_mem) { if (existing != NULL) - existing->pr_lock_count++; + ++existing->pr_lock_count; else - self->p_untracked_readlock_count++; + ++self->p_untracked_readlock_count; } } @@ -574,14 +573,15 @@ __pthread_rwlock_unlock (pthread_rwlock_t *rwlock) { if (victim->pr_lock_count == 0) { - victim->pr_next = self->p_readlock_free; - self->p_readlock_free = victim; + victim->pr_next = THREAD_GETMEM (self, p_readlock_free); + THREAD_SETMEM (self, p_readlock_free, victim); } } else { - if (self->p_untracked_readlock_count > 0) - self->p_untracked_readlock_count--; + int val = THREAD_GETMEM (self, p_untracked_readlock_count); + if (val > 0) + THREAD_SETMEM (self, p_untracked_readlock_count, val - 1); } } } diff --git a/linuxthreads/spinlock.h b/linuxthreads/spinlock.h index 6d3d3433f9..f88e8f3b0e 100644 --- a/linuxthreads/spinlock.h +++ b/linuxthreads/spinlock.h @@ -209,3 +209,18 @@ static inline long atomic_decrement(struct pthread_atomic *pa) } #define ATOMIC_INITIALIZER { 0, 0 } + + +static inline void +__pthread_set_own_extricate_if(pthread_descr self, pthread_extricate_if *peif) +{ +#if 0 + __pthread_lock(THREAD_GETMEM(self, p_lock), self); + THREAD_SETMEM(self, p_extricate, peif); + __pthread_unlock(THREAD_GETMEM (self, p_lock)); +#else + /* I don't think that getting the lock is necessary. All we do is an + atomic write. */ + THREAD_SETMEM(self, p_extricate, peif); +#endif +} |