1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <hurd/signal.h>
21: #include <hurd/interrupt.h>
22: #include <assert.h>
23: #include <thread_state.h>
24:
25:
26:
27: extern mach_port_t _hurdsig_abort_rpcs (struct hurd_sigstate *ss,
28: int signo, int sigthread,
29: struct machine_thread_all_state *,
30: int *state_change,
31: mach_port_t *reply_port,
32: mach_msg_type_name_t reply_port_type,
33: int untraced);
34:
35: error_t
36: hurd_thread_cancel (thread_t thread)
37: {
38: struct hurd_sigstate *ss = _hurd_thread_sigstate (thread);
39: struct machine_thread_all_state state;
40: int state_change;
41: error_t err;
42:
43: if (! ss)
44: return EINVAL;
45: if (ss == _hurd_self_sigstate ())
46: {
47:
48:
49:
50:
51: ss->cancel = 1;
52: return 0;
53: }
54:
55: assert (! __spin_lock_locked (&ss->critical_section_lock));
56: __spin_lock (&ss->critical_section_lock);
57: __spin_lock (&ss->lock);
58: err = __thread_suspend (thread);
59: __spin_unlock (&ss->lock);
60:
61: if (! err)
62: {
63:
64: ss->cancel = 1;
65:
66:
67: state.set = 0;
68: _hurdsig_abort_rpcs (ss, 0, 0, &state, &state_change, NULL, 0, 0);
69: if (state_change)
70: err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
71: (natural_t *) &state.basic,
72: MACHINE_THREAD_STATE_COUNT);
73:
74: if (ss->cancel_hook)
75:
76:
77:
78: (*ss->cancel_hook) ();
79:
80: __thread_resume (thread);
81: }
82:
83: _hurd_critical_section_unlock (ss);
84: return err;
85: }
86:
87:
88: int
89: hurd_check_cancel (void)
90: {
91: struct hurd_sigstate *ss = _hurd_self_sigstate ();
92: int cancel;
93:
94: __spin_lock (&ss->lock);
95: assert (! __spin_lock_locked (&ss->critical_section_lock));
96: cancel = ss->cancel;
97: ss->cancel = 0;
98: __spin_unlock (&ss->lock);
99:
100: return cancel;
101: }