Subversion Repositories HelenOS

Rev

Rev 3495 | Rev 3620 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3495 Rev 3496
Line 89... Line 89...
89
    ipc_cleanup_call_list(&TASK->kernel_box.dispatched_calls);
89
    ipc_cleanup_call_list(&TASK->kernel_box.dispatched_calls);
90
    ipc_cleanup_call_list(&TASK->kernel_box.calls);
90
    ipc_cleanup_call_list(&TASK->kernel_box.calls);
91
    spinlock_unlock(&TASK->kernel_box.lock);
91
    spinlock_unlock(&TASK->kernel_box.lock);
92
}
92
}
93
 
93
 
-
 
94
/** Handle hangup message in kbox.
94
 
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
 **/
95
static void kbox_thread_proc(void *arg)
100
static void kbox_proc_phone_hungup(call_t *call, bool *last)
96
{
101
{
97
    call_t *call;
-
 
98
    int method;
-
 
99
    bool done;
-
 
100
    ipl_t ipl;
102
    ipl_t ipl;
101
 
103
 
102
    (void)arg;
-
 
103
    LOG("kbox_thread_proc()\n");
104
    LOG("kbox_proc_phone_hungup()\n");
104
    done = false;
-
 
105
 
-
 
106
    while (!done) {
-
 
107
        call = ipc_wait_for_call(&TASK->kernel_box, SYNCH_NO_TIMEOUT,
-
 
108
            SYNCH_FLAGS_NONE);
-
 
109
 
-
 
110
        if (call != NULL) {
-
 
111
            method = IPC_GET_METHOD(call->data);
-
 
112
 
-
 
113
            if (method == IPC_M_DEBUG_ALL) {
-
 
114
                udebug_call_receive(call);
-
 
115
            }
-
 
116
 
-
 
117
            if (method == IPC_M_PHONE_HUNGUP) {
-
 
118
                LOG("kbox: handle hangup message\n");
-
 
119
 
105
 
120
                /* Was it our debugger, who hung up? */
106
    /* Was it our debugger, who hung up? */
121
                if (call->sender == TASK->udebug.debugger) {
107
    if (call->sender == TASK->udebug.debugger) {
122
                    /* Terminate debugging session (if any) */
108
        /* Terminate debugging session (if any) */
123
                    LOG("kbox: terminate debug session\n");
109
        LOG("kbox: terminate debug session\n");
Line 137... Line 123...
137
                ipl = interrupts_disable();
123
    ipl = interrupts_disable();
138
                spinlock_lock(&TASK->lock);
124
    spinlock_lock(&TASK->lock);
139
                spinlock_lock(&TASK->answerbox.lock);
125
    spinlock_lock(&TASK->answerbox.lock);
140
                if (list_empty(&TASK->answerbox.connected_phones)) {
126
    if (list_empty(&TASK->answerbox.connected_phones)) {
141
                    /*
127
        /*
142
                     * Last phone has been disconnected.
128
         * Last phone has been disconnected. Detach this thread so it
143
                     * Detach this thread so it gets
-
 
144
                     * freed and terminate.
129
         * gets freed and signal to the caller.
145
                     */
130
         */
146
 
131
 
147
                    /* Only need to detach thread unless already terminating. */
132
        /* Only detach kbox thread unless already terminating. */
148
                    mutex_lock(&TASK->kb_cleanup_lock);
133
        mutex_lock(&TASK->kb_cleanup_lock);
149
                    if (&TASK->kb_finished == false) {
134
        if (&TASK->kb_finished == false) {
150
                        /* Detach thread so it gets freed. */
135
            /* Detach kbox thread so it gets freed from memory. */
151
                        thread_detach(TASK->kb_thread);
136
            thread_detach(TASK->kb_thread);
152
                        TASK->kb_thread = NULL;
137
            TASK->kb_thread = NULL;
153
                    }
138
        }
154
                    mutex_unlock(&TASK->kb_cleanup_lock);
139
        mutex_unlock(&TASK->kb_cleanup_lock);
155
                    done = true;
-
 
-
 
140
 
156
                    LOG("phone list is empty\n");
141
        LOG("phone list is empty\n");
-
 
142
        *last = true;
-
 
143
    } else {
-
 
144
        *last = false;
157
                }
145
    }
-
 
146
 
158
                spinlock_unlock(&TASK->answerbox.lock);
147
    spinlock_unlock(&TASK->answerbox.lock);
159
                spinlock_unlock(&TASK->lock);
148
    spinlock_unlock(&TASK->lock);
160
                interrupts_restore(ipl);
149
    interrupts_restore(ipl);
161
            }
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;
162
        }
194
        }
163
    }
195
    }
164
 
196
 
165
    LOG("kbox: finished\n");
197
    LOG("kbox: finished\n");
166
}
198
}