Changes in kernel/generic/src/ipc/ipc.c [c1f68b0:cde999a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ipc/ipc.c
rc1f68b0 rcde999a 66 66 answerbox_t *ipc_phone_0 = NULL; 67 67 68 static slab_cache_t *call_ slab;69 static slab_cache_t *answerbox_ slab;70 71 slab_cache_t *phone_ slab= NULL;68 static slab_cache_t *call_cache; 69 static slab_cache_t *answerbox_cache; 70 71 slab_cache_t *phone_cache = NULL; 72 72 73 73 /** Initialize a call structure. … … 87 87 } 88 88 89 void ipc_call_hold(call_t *call) 90 { 91 atomic_inc(&call->refcnt); 92 } 93 94 void ipc_call_release(call_t *call) 95 { 96 if (atomic_predec(&call->refcnt) == 0) { 97 if (call->buffer) 98 free(call->buffer); 99 if (call->caller_phone) 100 kobject_put(call->caller_phone->kobject); 101 slab_free(call_slab, call); 102 } 103 } 89 static void call_destroy(void *arg) 90 { 91 call_t *call = (call_t *) arg; 92 93 if (call->buffer) 94 free(call->buffer); 95 if (call->caller_phone) 96 kobject_put(call->caller_phone->kobject); 97 slab_free(call_cache, call); 98 } 99 100 static kobject_ops_t call_kobject_ops = { 101 .destroy = call_destroy 102 }; 104 103 105 104 /** Allocate and initialize a call structure. … … 116 115 call_t *ipc_call_alloc(unsigned int flags) 117 116 { 118 call_t *call = slab_alloc(call_slab, flags); 119 if (call) { 120 _ipc_call_init(call); 121 ipc_call_hold(call); 122 } 117 call_t *call = slab_alloc(call_cache, flags); 118 if (!call) 119 return NULL; 120 kobject_t *kobj = (kobject_t *) malloc(sizeof(kobject_t), flags); 121 if (!kobj) { 122 slab_free(call_cache, call); 123 return NULL; 124 } 125 126 _ipc_call_init(call); 127 kobject_initialize(kobj, KOBJECT_TYPE_CALL, call, &call_kobject_ops); 128 call->kobject = kobj; 123 129 124 130 return call; 125 }126 127 /** Deallocate a call structure.128 *129 * @param call Call structure to be freed.130 *131 */132 void ipc_call_free(call_t *call)133 {134 ipc_call_release(call);135 131 } 136 132 … … 209 205 * @param request Call structure with request. 210 206 * 211 * @return EOK on success or a negativeerror code.207 * @return EOK on success or an error code. 212 208 * 213 209 */ 214 210 int ipc_call_sync(phone_t *phone, call_t *request) 215 211 { 216 answerbox_t *mybox = slab_alloc(answerbox_ slab, 0);212 answerbox_t *mybox = slab_alloc(answerbox_cache, 0); 217 213 ipc_answerbox_init(mybox, TASK); 218 214 … … 222 218 int rc = ipc_call(phone, request); 223 219 if (rc != EOK) { 224 slab_free(answerbox_ slab, mybox);220 slab_free(answerbox_cache, mybox); 225 221 return rc; 226 222 } … … 269 265 assert(!answer || request == answer); 270 266 271 slab_free(answerbox_ slab, mybox);267 slab_free(answerbox_cache, mybox); 272 268 return rc; 273 269 } … … 290 286 /* This is a forgotten call and call->sender is not valid. */ 291 287 spinlock_unlock(&call->forget_lock); 292 ipc_call_free(call);288 kobject_put(call->kobject); 293 289 return; 294 290 } else { … … 375 371 * 376 372 */ 377 void ipc_backsend_err(phone_t *phone, call_t *call, sysarg_t err)373 void ipc_backsend_err(phone_t *phone, call_t *call, int err) 378 374 { 379 375 _ipc_call_actions_internal(phone, call, false); … … 448 444 * @param phone Phone structure to be hung up. 449 445 * 450 * @return 0if the phone is disconnected.451 * @return -1if the phone was already disconnected.446 * @return EOK if the phone is disconnected. 447 * @return EINVAL if the phone was already disconnected. 452 448 * 453 449 */ … … 459 455 phone->state == IPC_PHONE_CONNECTING) { 460 456 mutex_unlock(&phone->lock); 461 return -1;457 return EINVAL; 462 458 } 463 459 … … 482 478 mutex_unlock(&phone->lock); 483 479 484 return 0;480 return EOK; 485 481 } 486 482 … … 542 538 543 539 restart: 544 rc = waitq_sleep_timeout(&box->wq, usec, flags );545 if ( SYNCH_FAILED(rc))540 rc = waitq_sleep_timeout(&box->wq, usec, flags, NULL); 541 if (rc != EOK) 546 542 return NULL; 547 543 … … 642 638 phone = list_get_instance(list_first(&box->connected_phones), 643 639 phone_t, link); 644 if ( SYNCH_FAILED(mutex_trylock(&phone->lock))) {640 if (mutex_trylock(&phone->lock) != EOK) { 645 641 irq_spinlock_unlock(&box->lock, true); 646 642 DEADLOCK_PROBE(p_phonelck, DEADLOCK_THRESHOLD); … … 705 701 * must hold a reference to it. 706 702 */ 707 ipc_call_hold(call);703 kobject_add_ref(call->kobject); 708 704 709 705 spinlock_unlock(&call->forget_lock); … … 714 710 SYSIPC_OP(request_forget, call); 715 711 716 ipc_call_release(call);712 kobject_put(call->kobject); 717 713 } 718 714 … … 822 818 SYSIPC_OP(answer_process, call); 823 819 824 ipc_call_free(call);820 kobject_put(call->kobject); 825 821 goto restart; 826 822 } … … 839 835 { 840 836 ipc_irq_unsubscribe(&TASK->answerbox, cap->handle); 837 return true; 838 } 839 840 static bool call_cap_cleanup_cb(cap_t *cap, void *arg) 841 { 842 /* 843 * Here we just free the capability and release the kobject. 844 * The kernel answers the remaining calls elsewhere in ipc_cleanup(). 845 */ 846 kobject_t *kobj = cap_unpublish(cap->task, cap->handle, 847 KOBJECT_TYPE_CALL); 848 kobject_put(kobj); 849 cap_free(cap->task, cap->handle); 841 850 return true; 842 851 } … … 878 887 ipc_kbox_cleanup(); 879 888 #endif 889 890 /* Destroy all call capabilities */ 891 caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_CALL, call_cap_cleanup_cb, 892 NULL); 880 893 881 894 /* Answer all messages in 'calls' and 'dispatched_calls' queues */ … … 893 906 void ipc_init(void) 894 907 { 895 call_ slab= slab_cache_create("call_t", sizeof(call_t), 0, NULL,908 call_cache = slab_cache_create("call_t", sizeof(call_t), 0, NULL, 896 909 NULL, 0); 897 phone_ slab= slab_cache_create("phone_t", sizeof(phone_t), 0, NULL,910 phone_cache = slab_cache_create("phone_t", sizeof(phone_t), 0, NULL, 898 911 NULL, 0); 899 answerbox_ slab= slab_cache_create("answerbox_t", sizeof(answerbox_t),912 answerbox_cache = slab_cache_create("answerbox_t", sizeof(answerbox_t), 900 913 0, NULL, NULL, 0); 901 914 }
Note:
See TracChangeset
for help on using the changeset viewer.