Changeset ba81cab in mainline for generic/src/ipc/ipc.c
- Timestamp:
- 2006-03-18T01:06:13Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fbcfd458
- Parents:
- 81c4c6da
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/ipc/ipc.c
r81c4c6da rba81cab 50 50 static slab_cache_t *ipc_call_slab; 51 51 52 /* Initialize new call */ 53 static void _ipc_call_init(call_t *call) 54 { 55 memsetb((__address)call, sizeof(*call), 0); 56 call->callerbox = &TASK->answerbox; 57 call->sender = TASK; 58 } 59 52 60 /** Allocate & initialize call structure 53 61 * … … 60 68 61 69 call = slab_alloc(ipc_call_slab, 0); 62 memsetb((__address)call, sizeof(*call), 0); 63 call->callerbox = &TASK->answerbox; 64 call->sender = TASK; 70 _ipc_call_init(call); 65 71 66 72 return call; … … 68 74 69 75 /** Initialize allocated call */ 70 void ipc_call_init(call_t *call) 71 { 72 call->callerbox = &TASK->answerbox; 73 call->flags = IPC_CALL_STATIC_ALLOC; 74 call->sender = TASK; 76 void ipc_call_static_init(call_t *call) 77 { 78 _ipc_call_init(call); 79 call->flags |= IPC_CALL_STATIC_ALLOC; 75 80 } 76 81 … … 97 102 void ipc_phone_connect(phone_t *phone, answerbox_t *box) 98 103 { 104 spinlock_lock(&phone->lock); 105 99 106 ASSERT(!phone->callee); 100 107 phone->busy = 1; … … 104 111 list_append(&phone->list, &box->connected_phones); 105 112 spinlock_unlock(&box->lock); 113 114 spinlock_unlock(&phone->lock); 106 115 } 107 116 … … 115 124 } 116 125 117 /** Disconnect phone from answerbox */ 126 /** Disconnect phone from answerbox 127 * 128 * It is allowed to call disconnect on already disconnected phone\ 129 */ 118 130 void ipc_phone_destroy(phone_t *phone) 119 131 { … … 122 134 ASSERT(box); 123 135 124 spinlock_lock(&box->lock); 125 list_remove(&phone->list); 126 spinlock_unlock(&box->lock); 136 spinlock_lock(&phone->lock); 137 spinlock_lock(&box->lock); 138 139 if (phone->callee) { 140 list_remove(&phone->list); 141 phone->callee = NULL; 142 } 143 144 spinlock_unlock(&box->lock); 145 spinlock_unlock(&phone->lock); 127 146 } 128 147 … … 141 160 } 142 161 162 /** Answer message that was not dispatched and is not entered in 163 * any queue 164 */ 165 static void _ipc_answer_free_call(call_t *call) 166 { 167 answerbox_t *callerbox = call->callerbox; 168 169 call->flags &= ~IPC_CALL_DISPATCHED; 170 call->flags |= IPC_CALL_ANSWERED; 171 172 spinlock_lock(&callerbox->lock); 173 list_append(&call->list, &callerbox->answers); 174 spinlock_unlock(&callerbox->lock); 175 waitq_wakeup(&callerbox->wq, 0); 176 } 177 178 /** Answer message, that is in callee queue 179 * 180 * @param box Answerbox that is answering the message 181 * @param call Modified request that is being sent back 182 */ 183 void ipc_answer(answerbox_t *box, call_t *call) 184 { 185 /* Remove from active box */ 186 spinlock_lock(&box->lock); 187 list_remove(&call->list); 188 spinlock_unlock(&box->lock); 189 /* Send back answer */ 190 _ipc_answer_free_call(call); 191 } 192 143 193 /** Send a asynchronous request using phone to answerbox 144 194 * … … 148 198 void ipc_call(phone_t *phone, call_t *call) 149 199 { 150 answerbox_t *box = phone->callee; 151 152 ASSERT(box); 200 answerbox_t *box; 201 202 spinlock_lock(&phone->lock); 203 box = phone->callee; 204 if (!box) { 205 /* Trying to send over disconnected phone */ 206 IPC_SET_RETVAL(call->data, ENOENT); 207 _ipc_answer_free_call(call); 208 return; 209 } 153 210 154 211 spinlock_lock(&box->lock); … … 156 213 spinlock_unlock(&box->lock); 157 214 waitq_wakeup(&box->wq, 0); 215 216 spinlock_unlock(&phone->lock); 158 217 } 159 218 … … 164 223 * @param oldbox Old answerbox 165 224 */ 166 void ipc_forward(call_t *call, answerbox_t *newbox, answerbox_t *oldbox)225 void ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox) 167 226 { 168 227 spinlock_lock(&oldbox->lock); … … 170 229 spinlock_unlock(&oldbox->lock); 171 230 172 spinlock_lock(&newbox->lock); 173 list_append(&call->list, &newbox->calls); 174 spinlock_lock(&newbox->lock); 175 waitq_wakeup(&newbox->wq, 0); 176 } 177 178 /** Answer message back to phone 179 * 180 * @param box Answerbox that is answering the message 181 * @param request Modified request that is being sent back 182 */ 183 void ipc_answer(answerbox_t *box, call_t *request) 184 { 185 answerbox_t *callerbox = request->callerbox; 186 187 request->flags &= ~IPC_CALL_DISPATCHED; 188 request->flags |= IPC_CALL_ANSWERED; 189 190 spinlock_lock(&box->lock); 191 list_remove(&request->list); 192 spinlock_unlock(&box->lock); 193 194 spinlock_lock(&callerbox->lock); 195 list_append(&request->list, &callerbox->answers); 196 spinlock_unlock(&callerbox->lock); 197 waitq_wakeup(&callerbox->wq, 0); 198 } 231 ipc_call(newphone, call); 232 } 233 199 234 200 235 /** Wait for phone call
Note:
See TracChangeset
for help on using the changeset viewer.