Rev 3448 | Rev 3674 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3448 | Rev 3535 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | #include <udebug/udebug_ipc.h> |
43 | #include <udebug/udebug_ipc.h> |
44 | #include <ipc/kbox.h> |
44 | #include <ipc/kbox.h> |
45 | 45 | ||
46 | void ipc_kbox_cleanup(void) |
46 | void ipc_kbox_cleanup(void) |
47 | { |
47 | { |
- | 48 | ipl_t ipl; |
|
48 | bool have_kb_thread; |
49 | bool have_kb_thread; |
49 | 50 | ||
50 | /* Only hold kb_cleanup_lock while setting kb_finished - this is enough */ |
51 | /* Only hold kb_cleanup_lock while setting kb_finished - this is enough */ |
51 | mutex_lock(&TASK->kb_cleanup_lock); |
52 | mutex_lock(&TASK->kb_cleanup_lock); |
52 | TASK->kb_finished = true; |
53 | TASK->kb_finished = true; |
Line 62... | Line 63... | ||
62 | * disconnected phone. This ensures the kbox thread is going to |
63 | * disconnected phone. This ensures the kbox thread is going to |
63 | * wake up and terminate. |
64 | * wake up and terminate. |
64 | */ |
65 | */ |
65 | ipc_answerbox_slam_phones(&TASK->kernel_box, have_kb_thread); |
66 | ipc_answerbox_slam_phones(&TASK->kernel_box, have_kb_thread); |
66 | 67 | ||
- | 68 | /* |
|
- | 69 | * If the task was being debugged, clean up debugging session. |
|
- | 70 | * This is necessarry as slamming the phones won't force |
|
- | 71 | * kbox thread to clean it up since sender != debugger. |
|
- | 72 | */ |
|
- | 73 | ipl = interrupts_disable(); |
|
- | 74 | spinlock_lock(&TASK->lock); |
|
- | 75 | udebug_task_cleanup(TASK); |
|
- | 76 | spinlock_unlock(&TASK->lock); |
|
- | 77 | interrupts_restore(ipl); |
|
- | 78 | ||
67 | if (have_kb_thread) { |
79 | if (have_kb_thread) { |
68 | LOG("join kb_thread..\n"); |
80 | LOG("join kb_thread..\n"); |
69 | thread_join(TASK->kb_thread); |
81 | thread_join(TASK->kb_thread); |
70 | thread_detach(TASK->kb_thread); |
82 | thread_detach(TASK->kb_thread); |
71 | LOG("join done\n"); |
83 | LOG("join done\n"); |
Line 77... | Line 89... | ||
77 | ipc_cleanup_call_list(&TASK->kernel_box.dispatched_calls); |
89 | ipc_cleanup_call_list(&TASK->kernel_box.dispatched_calls); |
78 | ipc_cleanup_call_list(&TASK->kernel_box.calls); |
90 | ipc_cleanup_call_list(&TASK->kernel_box.calls); |
79 | spinlock_unlock(&TASK->kernel_box.lock); |
91 | spinlock_unlock(&TASK->kernel_box.lock); |
80 | } |
92 | } |
81 | 93 | ||
- | 94 | /** Handle hangup message in kbox. |
|
82 | 95 | * |
|
- | 96 | * @param call The IPC_M_PHONE_HUNGUP call structure. |
|
- | 97 | * @param last Output, the function stores @c true here if |
|
- | 98 | * this was the last phone, @c false otherwise. |
|
- | 99 | **/ |
|
83 | static void kbox_thread_proc(void *arg) |
100 | static void kbox_proc_phone_hungup(call_t *call, bool *last) |
84 | { |
101 | { |
85 | call_t *call; |
- | |
86 | int method; |
- | |
87 | bool done; |
- | |
88 | ipl_t ipl; |
102 | ipl_t ipl; |
89 | 103 | ||
90 | (void)arg; |
- | |
91 | LOG("kbox_thread_proc()\n"); |
104 | LOG("kbox_proc_phone_hungup()\n"); |
92 | done = false; |
- | |
93 | - | ||
94 | while (!done) { |
- | |
95 | call = ipc_wait_for_call(&TASK->kernel_box, SYNCH_NO_TIMEOUT, |
- | |
96 | SYNCH_FLAGS_NONE); |
- | |
97 | - | ||
98 | if (call != NULL) { |
- | |
99 | method = IPC_GET_METHOD(call->data); |
- | |
100 | - | ||
101 | if (method == IPC_M_DEBUG_ALL) { |
- | |
102 | udebug_call_receive(call); |
- | |
103 | } |
- | |
104 | - | ||
105 | if (method == IPC_M_PHONE_HUNGUP) { |
- | |
106 | LOG("kbox: handle hangup message\n"); |
- | |
107 | 105 | ||
108 | /* Was it our debugger, who hung up? */ |
106 | /* Was it our debugger, who hung up? */ |
109 | if (call->sender == TASK->udebug.debugger) { |
107 | if (call->sender == TASK->udebug.debugger) { |
110 | /* Terminate debugging session (if any) */ |
108 | /* Terminate debugging session (if any) */ |
111 | LOG("kbox: terminate debug session\n"); |
109 | LOG("kbox: terminate debug session\n"); |
Line 124... | Line 122... | ||
124 | 122 | ||
125 | ipl = interrupts_disable(); |
123 | ipl = interrupts_disable(); |
126 | spinlock_lock(&TASK->lock); |
124 | spinlock_lock(&TASK->lock); |
127 | spinlock_lock(&TASK->answerbox.lock); |
125 | spinlock_lock(&TASK->answerbox.lock); |
128 | if (list_empty(&TASK->answerbox.connected_phones)) { |
126 | if (list_empty(&TASK->answerbox.connected_phones)) { |
- | 127 | /* |
|
129 | /* Last phone has been disconnected */ |
128 | * Last phone has been disconnected. Detach this thread so it |
- | 129 | * gets freed and signal to the caller. |
|
- | 130 | */ |
|
- | 131 | ||
- | 132 | /* Only detach kbox thread unless already terminating. */ |
|
- | 133 | mutex_lock(&TASK->kb_cleanup_lock); |
|
- | 134 | if (&TASK->kb_finished == false) { |
|
- | 135 | /* Detach kbox thread so it gets freed from memory. */ |
|
- | 136 | thread_detach(TASK->kb_thread); |
|
130 | TASK->kb_thread = NULL; |
137 | TASK->kb_thread = NULL; |
- | 138 | } |
|
131 | done = true; |
139 | mutex_unlock(&TASK->kb_cleanup_lock); |
- | 140 | ||
132 | LOG("phone list is empty\n"); |
141 | LOG("phone list is empty\n"); |
- | 142 | *last = true; |
|
- | 143 | } else { |
|
- | 144 | *last = false; |
|
133 | } |
145 | } |
- | 146 | ||
134 | spinlock_unlock(&TASK->answerbox.lock); |
147 | spinlock_unlock(&TASK->answerbox.lock); |
135 | spinlock_unlock(&TASK->lock); |
148 | spinlock_unlock(&TASK->lock); |
136 | interrupts_restore(ipl); |
149 | interrupts_restore(ipl); |
137 | } |
150 | } |
- | 151 | ||
- | 152 | /** Implementing function for the kbox thread. |
|
- | 153 | * |
|
- | 154 | * This function listens for debug requests. It terminates |
|
- | 155 | * when all phones are disconnected from the kbox. |
|
- | 156 | * |
|
- | 157 | * @param arg Ignored. |
|
- | 158 | */ |
|
- | 159 | static void kbox_thread_proc(void *arg) |
|
- | 160 | { |
|
- | 161 | call_t *call; |
|
- | 162 | bool done; |
|
- | 163 | ||
- | 164 | (void)arg; |
|
- | 165 | LOG("kbox_thread_proc()\n"); |
|
- | 166 | done = false; |
|
- | 167 | ||
- | 168 | while (!done) { |
|
- | 169 | call = ipc_wait_for_call(&TASK->kernel_box, SYNCH_NO_TIMEOUT, |
|
- | 170 | SYNCH_FLAGS_NONE); |
|
- | 171 | ||
- | 172 | if (call == NULL) |
|
- | 173 | continue; /* Try again. */ |
|
- | 174 | ||
- | 175 | switch (IPC_GET_METHOD(call->data)) { |
|
- | 176 | ||
- | 177 | case IPC_M_DEBUG_ALL: |
|
- | 178 | /* Handle debug call. */ |
|
- | 179 | udebug_call_receive(call); |
|
- | 180 | break; |
|
- | 181 | ||
- | 182 | case IPC_M_PHONE_HUNGUP: |
|
- | 183 | /* |
|
- | 184 | * Process the hangup call. If this was the last |
|
- | 185 | * phone, done will be set to true and the |
|
- | 186 | * while loop will terminate. |
|
- | 187 | */ |
|
- | 188 | kbox_proc_phone_hungup(call, &done); |
|
- | 189 | break; |
|
- | 190 | ||
- | 191 | default: |
|
- | 192 | /* Ignore */ |
|
- | 193 | break; |
|
138 | } |
194 | } |
139 | } |
195 | } |
140 | 196 | ||
141 | LOG("kbox: finished\n"); |
197 | LOG("kbox: finished\n"); |
142 | } |
198 | } |