Deleted Added
full compact
thr_resume_np.c (76909) thr_resume_np.c (97204)
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/libkse/thread/thr_resume_np.c 76909 2001-05-20 23:08:33Z jasone $
32 * $FreeBSD: head/lib/libkse/thread/thr_resume_np.c 97204 2002-05-24 04:32:28Z deischen $
33 */
34#include <errno.h>
35#include <pthread.h>
36#include "pthread_private.h"
37
33 */
34#include <errno.h>
35#include <pthread.h>
36#include "pthread_private.h"
37
38static void resume_common(struct pthread *);
39
38__weak_reference(_pthread_resume_np, pthread_resume_np);
40__weak_reference(_pthread_resume_np, pthread_resume_np);
41__weak_reference(_pthread_resume_all_np, pthread_resume_all_np);
39
40/* Resume a thread: */
41int
42_pthread_resume_np(pthread_t thread)
43{
42
43/* Resume a thread: */
44int
45_pthread_resume_np(pthread_t thread)
46{
44 int ret;
45 enum pthread_susp old_suspended;
47 int ret;
46
47 /* Find the thread in the list of active threads: */
48 if ((ret = _find_thread(thread)) == 0) {
48
49 /* Find the thread in the list of active threads: */
50 if ((ret = _find_thread(thread)) == 0) {
49 /* Cancel any pending suspensions: */
50 old_suspended = thread->suspended;
51 thread->suspended = SUSP_NO;
51 /*
52 * Defer signals to protect the scheduling queues
53 * from access by the signal handler:
54 */
55 _thread_kern_sig_defer();
52
56
53 /* Is it currently suspended? */
54 if (thread->state == PS_SUSPENDED) {
55 /*
56 * Defer signals to protect the scheduling queues
57 * from access by the signal handler:
58 */
59 _thread_kern_sig_defer();
57 if ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0)
58 resume_common(thread);
60
59
61 switch (old_suspended) {
62 case SUSP_MUTEX_WAIT:
63 /* Set the thread's state back. */
64 PTHREAD_SET_STATE(thread,PS_MUTEX_WAIT);
65 break;
66 case SUSP_COND_WAIT:
67 /* Set the thread's state back. */
68 PTHREAD_SET_STATE(thread,PS_COND_WAIT);
69 break;
70 case SUSP_JOIN:
71 /* Set the thread's state back. */
72 PTHREAD_SET_STATE(thread,PS_JOIN);
73 break;
74 case SUSP_NOWAIT:
75 /* Allow the thread to run. */
76 PTHREAD_SET_STATE(thread,PS_RUNNING);
77 PTHREAD_WAITQ_REMOVE(thread);
78 PTHREAD_PRIOQ_INSERT_TAIL(thread);
79 break;
80 case SUSP_NO:
81 case SUSP_YES:
82 /* Allow the thread to run. */
83 PTHREAD_SET_STATE(thread,PS_RUNNING);
84 PTHREAD_PRIOQ_INSERT_TAIL(thread);
85 break;
86 }
60 /*
61 * Undefer and handle pending signals, yielding if
62 * necessary:
63 */
64 _thread_kern_sig_undefer();
65 }
66 return (ret);
67}
87
68
88 /*
89 * Undefer and handle pending signals, yielding if
90 * necessary:
91 */
92 _thread_kern_sig_undefer();
93 }
69void
70_pthread_resume_all_np(void)
71{
72 struct pthread *curthread = _get_curthread();
73 struct pthread *thread;
74
75 /*
76 * Defer signals to protect the scheduling queues from access
77 * by the signal handler:
78 */
79 _thread_kern_sig_defer();
80
81 TAILQ_FOREACH(thread, &_thread_list, tle) {
82 if ((thread != curthread) &&
83 ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0))
84 resume_common(thread);
94 }
85 }
95 return(ret);
86
87 /*
88 * Undefer and handle pending signals, yielding if necessary:
89 */
90 _thread_kern_sig_undefer();
96}
91}
92
93static void
94resume_common(struct pthread *thread)
95{
96 /* Clear the suspend flag: */
97 thread->flags &= ~PTHREAD_FLAGS_SUSPENDED;
98
99 /*
100 * If the thread's state is suspended, that means it is
101 * now runnable but not in any scheduling queue. Set the
102 * state to running and insert it into the run queue.
103 */
104 if (thread->state == PS_SUSPENDED) {
105 PTHREAD_SET_STATE(thread, PS_RUNNING);
106 if (thread->priority_mutex_count > 0)
107 PTHREAD_PRIOQ_INSERT_HEAD(thread);
108 else
109 PTHREAD_PRIOQ_INSERT_TAIL(thread);
110 }
111}