Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/ipc.c

    r1b20da0 ra35b458  
    127127        kobject_initialize(kobj, KOBJECT_TYPE_CALL, call, &call_kobject_ops);
    128128        call->kobject = kobj;
    129        
     129
    130130        return call;
    131131}
     
    212212        answerbox_t *mybox = slab_alloc(answerbox_cache, 0);
    213213        ipc_answerbox_init(mybox, TASK);
    214        
     214
    215215        /* We will receive data in a special box. */
    216216        request->callerbox = mybox;
    217        
     217
    218218        errno_t rc = ipc_call(phone, request);
    219219        if (rc != EOK) {
     
    247247                        ipc_forget_call(request);       /* releases locks */
    248248                        rc = EINTR;
    249                        
     249
    250250                } else {
    251251                        spinlock_unlock(&TASK->active_calls_lock);
     
    264264        }
    265265        assert(!answer || request == answer);
    266        
     266
    267267        slab_free(answerbox_cache, mybox);
    268268        return rc;
     
    305305            &call->sender->answerbox;
    306306        bool do_lock = ((!selflocked) || (callerbox != &TASK->answerbox));
    307        
     307
    308308        call->flags |= IPC_CALL_ANSWERED;
    309        
     309
    310310        call->data.task_id = TASK->taskid;
    311        
     311
    312312        if (do_lock)
    313313                irq_spinlock_lock(&callerbox->lock, true);
    314        
     314
    315315        list_append(&call->ab_link, &callerbox->answers);
    316        
     316
    317317        if (do_lock)
    318318                irq_spinlock_unlock(&callerbox->lock, true);
    319        
     319
    320320        waitq_wakeup(&callerbox->wq, WAKEUP_FIRST);
    321321}
     
    333333        list_remove(&call->ab_link);
    334334        irq_spinlock_unlock(&box->lock, true);
    335        
     335
    336336        /* Send back answer */
    337337        _ipc_answer_free_call(call, false);
     
    395395        caller->ipc_info.call_sent++;
    396396        irq_spinlock_unlock(&caller->lock, true);
    397        
     397
    398398        if (!(call->flags & IPC_CALL_FORWARDED))
    399399                _ipc_call_actions_internal(phone, call, preforget);
    400        
     400
    401401        irq_spinlock_lock(&box->lock, true);
    402402        list_append(&call->ab_link, &box->calls);
    403403        irq_spinlock_unlock(&box->lock, true);
    404        
     404
    405405        waitq_wakeup(&box->wq, WAKEUP_FIRST);
    406406}
     
    426426                                ipc_backsend_err(phone, call, ENOENT);
    427427                }
    428                
     428
    429429                return ENOENT;
    430430        }
    431        
     431
    432432        answerbox_t *box = phone->callee;
    433433        _ipc_call(phone, box, call, false);
    434        
     434
    435435        mutex_unlock(&phone->lock);
    436436        return 0;
     
    457457                return EINVAL;
    458458        }
    459        
     459
    460460        answerbox_t *box = phone->callee;
    461461        if (phone->state != IPC_PHONE_SLAMMED) {
     
    467467                /* Drop the answerbox reference */
    468468                kobject_put(phone->kobject);
    469                
     469
    470470                call_t *call = ipc_call_alloc(0);
    471471                IPC_SET_IMETHOD(call->data, IPC_M_PHONE_HUNGUP);
     
    474474                _ipc_call(phone, box, call, false);
    475475        }
    476        
     476
    477477        phone->state = IPC_PHONE_HUNGUP;
    478478        mutex_unlock(&phone->lock);
    479        
     479
    480480        return EOK;
    481481}
     
    504504        list_remove(&call->ab_link);
    505505        irq_spinlock_unlock(&oldbox->lock, true);
    506        
     506
    507507        if (mode & IPC_FF_ROUTE_FROM_ME) {
    508508                call->data.phone = newphone;
    509509                call->data.task_id = TASK->taskid;
    510510        }
    511        
     511
    512512        return ipc_call(newphone, call);
    513513}
     
    536536        uint64_t call_cnt = 0;
    537537        errno_t rc;
    538        
     538
    539539restart:
    540540        rc = waitq_sleep_timeout(&box->wq, usec, flags, NULL);
    541541        if (rc != EOK)
    542542                return NULL;
    543        
     543
    544544        irq_spinlock_lock(&box->lock, true);
    545545        if (!list_empty(&box->irq_notifs)) {
    546546                /* Count received IRQ notification */
    547547                irq_cnt++;
    548                
     548
    549549                irq_spinlock_lock(&box->irq_lock, false);
    550                
     550
    551551                request = list_get_instance(list_first(&box->irq_notifs),
    552552                    call_t, ab_link);
    553553                list_remove(&request->ab_link);
    554                
     554
    555555                irq_spinlock_unlock(&box->irq_lock, false);
    556556        } else if (!list_empty(&box->answers)) {
    557557                /* Count received answer */
    558558                answer_cnt++;
    559                
     559
    560560                /* Handle asynchronous answers */
    561561                request = list_get_instance(list_first(&box->answers),
     
    566566                /* Count received call */
    567567                call_cnt++;
    568                
     568
    569569                /* Handle requests */
    570570                request = list_get_instance(list_first(&box->calls),
    571571                    call_t, ab_link);
    572572                list_remove(&request->ab_link);
    573                
     573
    574574                /* Append request to dispatch queue */
    575575                list_append(&request->ab_link, &box->dispatched_calls);
     
    579579                goto restart;
    580580        }
    581        
     581
    582582        irq_spinlock_pass(&box->lock, &TASK->lock);
    583        
     583
    584584        TASK->ipc_info.irq_notif_received += irq_cnt;
    585585        TASK->ipc_info.answer_received += answer_cnt;
    586586        TASK->ipc_info.call_received += call_cnt;
    587        
     587
    588588        irq_spinlock_unlock(&TASK->lock, true);
    589        
     589
    590590        return request;
    591591}
     
    602602                call_t *call = list_get_instance(list_first(lst), call_t,
    603603                    ab_link);
    604                
     604
    605605                list_remove(&call->ab_link);
    606606
     
    631631        phone_t *phone;
    632632        DEADLOCK_PROBE_INIT(p_phonelck);
    633        
     633
    634634        /* Disconnect all phones connected to our answerbox */
    635635restart_phones:
     
    643643                        goto restart_phones;
    644644                }
    645                
     645
    646646                /* Disconnect phone */
    647647                assert(phone->state == IPC_PHONE_CONNECTED);
    648                
     648
    649649                list_remove(&phone->link);
    650650                phone->state = IPC_PHONE_SLAMMED;
    651                
     651
    652652                if (notify_box) {
    653653                        task_hold(phone->caller);
     
    671671
    672672                        kobject_put(phone->kobject);
    673                        
     673
    674674                        /* Must start again */
    675675                        goto restart_phones;
    676676                }
    677                
     677
    678678                mutex_unlock(&phone->lock);
    679679                kobject_put(phone->kobject);
    680680        }
    681        
     681
    682682        irq_spinlock_unlock(&box->lock, true);
    683683}
     
    727727                return;
    728728        }
    729        
     729
    730730        call = list_get_instance(list_first(&TASK->active_calls), call_t,
    731731            ta_link);
     
    811811        if (restart)
    812812                goto restart;
    813        
     813
    814814        call = ipc_wait_for_call(&TASK->answerbox, SYNCH_NO_TIMEOUT,
    815815            SYNCH_FLAGS_NONE);
     
    872872        caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_PHONE,
    873873            phone_cap_cleanup_cb, NULL);
    874        
     874
    875875        /* Unsubscribe from any event notifications. */
    876876        event_cleanup_answerbox(&TASK->answerbox);
    877        
     877
    878878        /* Disconnect all connected IRQs */
    879879        caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_IRQ, irq_cap_cleanup_cb,
    880880            NULL);
    881        
     881
    882882        /* Disconnect all phones connected to our regular answerbox */
    883883        ipc_answerbox_slam_phones(&TASK->answerbox, false);
    884        
     884
    885885#ifdef CONFIG_UDEBUG
    886886        /* Clean up kbox thread and communications */
     
    891891        caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_CALL, call_cap_cleanup_cb,
    892892            NULL);
    893        
     893
    894894        /* Answer all messages in 'calls' and 'dispatched_calls' queues */
    895895        ipc_cleanup_call_list(&TASK->answerbox, &TASK->answerbox.calls);
    896896        ipc_cleanup_call_list(&TASK->answerbox,
    897897            &TASK->answerbox.dispatched_calls);
    898        
     898
    899899        ipc_forget_all_active_calls();
    900900        ipc_wait_for_all_answered_calls();
     
    921921                printf("%10p ", call);
    922922#endif
    923                
     923
    924924#ifdef __64_BITS__
    925925                printf("%18p ", call);
    926926#endif
    927                
     927
    928928                spinlock_lock(&call->forget_lock);
    929929
     
    954954                printf("%-11d %7" PRIun " ", cap->handle,
    955955                    atomic_get(&phone->active_calls));
    956                
     956
    957957                switch (phone->state) {
    958958                case IPC_PHONE_CONNECTING:
     
    973973                        break;
    974974                }
    975                
     975
    976976                printf("\n");
    977977        }
     
    996996        task_hold(task);
    997997        irq_spinlock_unlock(&tasks_lock, true);
    998        
     998
    999999        printf("[phone cap] [calls] [state\n");
    1000        
     1000
    10011001        caps_apply_to_kobject_type(task, KOBJECT_TYPE_PHONE,
    10021002            print_task_phone_cb, NULL);
    1003        
     1003
    10041004        irq_spinlock_lock(&task->lock, true);
    10051005        irq_spinlock_lock(&task->answerbox.lock, false);
    1006        
     1006
    10071007#ifdef __32_BITS__
    10081008        printf("[call id ] [method] [arg1] [arg2] [arg3] [arg4] [arg5]"
    10091009            " [flags] [sender\n");
    10101010#endif
    1011        
     1011
    10121012#ifdef __64_BITS__
    10131013        printf("[call id         ] [method] [arg1] [arg2] [arg3] [arg4]"
    10141014            " [arg5] [flags] [sender\n");
    10151015#endif
    1016        
     1016
    10171017        printf(" --- incomming calls ---\n");
    10181018        ipc_print_call_list(&task->answerbox.calls);
     
    10211021        printf(" --- incoming answers ---\n");
    10221022        ipc_print_call_list(&task->answerbox.answers);
    1023        
     1023
    10241024        irq_spinlock_unlock(&task->answerbox.lock, false);
    10251025        irq_spinlock_unlock(&task->lock, true);
Note: See TracChangeset for help on using the changeset viewer.