thr_resume_np.c (127485) | thr_resume_np.c (129484) |
---|---|
1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/lib/libthr/thread/thr_resume_np.c 127485 2004-03-27 14:39:21Z mtm $ | 32 * $FreeBSD: head/lib/libthr/thread/thr_resume_np.c 129484 2004-05-20 12:06:16Z mtm $ |
33 */ 34#include <errno.h> 35#include <pthread.h> 36#include <stdlib.h> 37#include "thr_private.h" 38 39static void resume_common(struct pthread *); 40 41__weak_reference(_pthread_resume_np, pthread_resume_np); 42__weak_reference(_pthread_resume_all_np, pthread_resume_all_np); 43 44/* Resume a thread: */ 45int 46_pthread_resume_np(pthread_t thread) 47{ 48 int ret; 49 50 /* Find the thread in the list of active threads: */ 51 if ((ret = _find_thread(thread)) == 0) { | 33 */ 34#include <errno.h> 35#include <pthread.h> 36#include <stdlib.h> 37#include "thr_private.h" 38 39static void resume_common(struct pthread *); 40 41__weak_reference(_pthread_resume_np, pthread_resume_np); 42__weak_reference(_pthread_resume_all_np, pthread_resume_all_np); 43 44/* Resume a thread: */ 45int 46_pthread_resume_np(pthread_t thread) 47{ 48 int ret; 49 50 /* Find the thread in the list of active threads: */ 51 if ((ret = _find_thread(thread)) == 0) { |
52 _thread_critical_enter(thread); | 52 PTHREAD_LOCK(thread); |
53 54 if ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) 55 resume_common(thread); 56 | 53 54 if ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) 55 resume_common(thread); 56 |
57 _thread_critical_exit(thread); | 57 PTHREAD_UNLOCK(thread); |
58 } 59 return (ret); 60} 61 62void 63_pthread_resume_all_np(void) 64{ 65 struct pthread *thread; 66 | 58 } 59 return (ret); 60} 61 62void 63_pthread_resume_all_np(void) 64{ 65 struct pthread *thread; 66 |
67 _thread_sigblock(); |
|
67 THREAD_LIST_LOCK; 68 TAILQ_FOREACH(thread, &_thread_list, tle) { | 68 THREAD_LIST_LOCK; 69 TAILQ_FOREACH(thread, &_thread_list, tle) { |
70 PTHREAD_LOCK(thread); |
|
69 if ((thread != curthread) && | 71 if ((thread != curthread) && |
70 ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0)) { 71 _thread_critical_enter(thread); | 72 ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0)) |
72 resume_common(thread); | 73 resume_common(thread); |
73 _thread_critical_exit(thread); 74 } | 74 PTHREAD_UNLOCK(thread); |
75 } 76 THREAD_LIST_UNLOCK; | 75 } 76 THREAD_LIST_UNLOCK; |
77 _thread_sigunblock(); |
|
77} 78 79/* 80 * The caller is required to have locked the thread before 81 * calling this function. 82 */ 83static void 84resume_common(struct pthread *thread) 85{ 86 thread->flags &= ~PTHREAD_FLAGS_SUSPENDED; 87 thr_wake(thread->thr_id); 88} | 78} 79 80/* 81 * The caller is required to have locked the thread before 82 * calling this function. 83 */ 84static void 85resume_common(struct pthread *thread) 86{ 87 thread->flags &= ~PTHREAD_FLAGS_SUSPENDED; 88 thr_wake(thread->thr_id); 89} |