Subversion Repositories HelenOS

Rev

Rev 3362 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3362 Rev 4407
Line 158... Line 158...
158
    }
158
    }
159
    spinlock_unlock(&TASK->answerbox.lock);
159
    spinlock_unlock(&TASK->answerbox.lock);
160
    return result;
160
    return result;
161
}
161
}
162
 
162
 
163
/** Allocate new phone slot in the current TASK structure.
163
/** Allocate new phone slot in the specified task.
-
 
164
 *
-
 
165
 * @param t     Task for which to allocate a new phone.
164
 *
166
 *
165
 * @return      New phone handle or -1 if the phone handle limit is
167
 * @return      New phone handle or -1 if the phone handle limit is
166
 *          exceeded.
168
 *          exceeded.
167
 */
169
 */
168
int phone_alloc(void)
170
int phone_alloc(task_t *t)
169
{
171
{
170
    int i;
172
    int i;
171
 
173
 
172
    spinlock_lock(&TASK->lock);
174
    spinlock_lock(&t->lock);
173
    for (i = 0; i < IPC_MAX_PHONES; i++) {
175
    for (i = 0; i < IPC_MAX_PHONES; i++) {
174
        if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
176
        if (t->phones[i].state == IPC_PHONE_HUNGUP &&
175
            atomic_get(&TASK->phones[i].active_calls) == 0)
177
            atomic_get(&t->phones[i].active_calls) == 0)
176
            TASK->phones[i].state = IPC_PHONE_FREE;
178
            t->phones[i].state = IPC_PHONE_FREE;
177
 
179
 
178
        if (TASK->phones[i].state == IPC_PHONE_FREE) {
180
        if (t->phones[i].state == IPC_PHONE_FREE) {
179
            TASK->phones[i].state = IPC_PHONE_CONNECTING;
181
            t->phones[i].state = IPC_PHONE_CONNECTING;
180
            break;
182
            break;
181
        }
183
        }
182
    }
184
    }
183
    spinlock_unlock(&TASK->lock);
185
    spinlock_unlock(&t->lock);
184
 
186
 
185
    if (i == IPC_MAX_PHONES)
187
    if (i == IPC_MAX_PHONES)
186
        return -1;
188
        return -1;
187
 
189
 
188
    return i;
190
    return i;