37,7 → 37,9 |
* First the answerbox, then the phone. |
*/ |
|
#include <synch/synch.h> |
#include <synch/spinlock.h> |
#include <synch/mutex.h> |
#include <synch/waitq.h> |
#include <synch/synch.h> |
#include <ipc/ipc.h> |
141,7 → 143,7 |
*/ |
void ipc_phone_connect(phone_t *phone, answerbox_t *box) |
{ |
spinlock_lock(&phone->lock); |
mutex_lock(&phone->lock); |
|
phone->state = IPC_PHONE_CONNECTED; |
phone->callee = box; |
150,7 → 152,7 |
list_append(&phone->link, &box->connected_phones); |
spinlock_unlock(&box->lock); |
|
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
} |
|
/** Initialize a phone structure. |
159,7 → 161,7 |
*/ |
void ipc_phone_init(phone_t *phone) |
{ |
spinlock_initialize(&phone->lock, "phone_lock"); |
mutex_initialize(&phone->lock); |
phone->callee = NULL; |
phone->state = IPC_PHONE_FREE; |
atomic_set(&phone->active_calls, 0); |
262,9 → 264,9 |
{ |
answerbox_t *box; |
|
spinlock_lock(&phone->lock); |
mutex_lock(&phone->lock); |
if (phone->state != IPC_PHONE_CONNECTED) { |
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
if (call->flags & IPC_CALL_FORWARDED) { |
IPC_SET_RETVAL(call->data, EFORWARD); |
_ipc_answer_free_call(call); |
279,7 → 281,7 |
box = phone->callee; |
_ipc_call(phone, box, call); |
|
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
return 0; |
} |
|
298,11 → 300,11 |
answerbox_t *box; |
call_t *call; |
|
spinlock_lock(&phone->lock); |
mutex_lock(&phone->lock); |
if (phone->state == IPC_PHONE_FREE || |
phone->state == IPC_PHONE_HUNGUP || |
phone->state == IPC_PHONE_CONNECTING) { |
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
return -1; |
} |
box = phone->callee; |
321,7 → 323,7 |
} |
|
phone->state = IPC_PHONE_HUNGUP; |
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
|
return 0; |
} |
447,7 → 449,7 |
while (!list_empty(&box->connected_phones)) { |
phone = list_get_instance(box->connected_phones.next, |
phone_t, link); |
if (!spinlock_trylock(&phone->lock)) { |
if (SYNCH_FAILED(mutex_trylock(&phone->lock))) { |
spinlock_unlock(&box->lock); |
interrupts_restore(ipl); |
DEADLOCK_PROBE(p_phonelck, DEADLOCK_THRESHOLD); |
461,7 → 463,7 |
phone->state = IPC_PHONE_SLAMMED; |
|
if (notify_box) { |
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
spinlock_unlock(&box->lock); |
interrupts_restore(ipl); |
|
482,7 → 484,7 |
goto restart_phones; |
} |
|
spinlock_unlock(&phone->lock); |
mutex_unlock(&phone->lock); |
} |
|
spinlock_unlock(&box->lock); |
625,7 → 627,10 |
/* Print opened phones & details */ |
printf("PHONE:\n"); |
for (i = 0; i < IPC_MAX_PHONES; i++) { |
spinlock_lock(&task->phones[i].lock); |
if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) { |
printf("%d: mutex busy\n", i); |
continue; |
} |
if (task->phones[i].state != IPC_PHONE_FREE) { |
printf("%d: ", i); |
switch (task->phones[i].state) { |
650,7 → 655,7 |
printf("active: %d\n", |
atomic_get(&task->phones[i].active_calls)); |
} |
spinlock_unlock(&task->phones[i].lock); |
mutex_unlock(&task->phones[i].lock); |
} |
|
|