Rev 4617 | Rev 4619 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4617 | Rev 4618 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Martin Decky |
2 | * Copyright (c) 2009 Martin Decky |
- | 3 | * Copyright (c) 2009 Jiri Svoboda |
|
3 | * All rights reserved. |
4 | * All rights reserved. |
4 | * |
5 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * are met: |
8 | * |
9 | * |
9 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
16 | * |
17 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | */ |
28 | 29 | ||
29 | /** @addtogroup ns |
30 | /** @addtogroup ns |
30 | * @{ |
31 | * @{ |
31 | */ |
32 | */ |
32 | 33 | ||
33 | #include <ipc/ipc.h> |
34 | #include <ipc/ipc.h> |
34 | #include <adt/hash_table.h> |
35 | #include <adt/hash_table.h> |
35 | #include <bool.h> |
36 | #include <bool.h> |
36 | #include <errno.h> |
37 | #include <errno.h> |
37 | #include <assert.h> |
38 | #include <assert.h> |
38 | #include <stdio.h> |
39 | #include <stdio.h> |
39 | #include <macros.h> |
40 | #include <macros.h> |
40 | #include "task.h" |
41 | #include "task.h" |
41 | #include "ns.h" |
42 | #include "ns.h" |
42 | 43 | ||
43 | #define TASK_HASH_TABLE_CHAINS 256 |
44 | #define TASK_HASH_TABLE_CHAINS 256 |
- | 45 | #define P2I_HASH_TABLE_CHAINS 256 |
|
- | 46 | ||
- | 47 | static int get_id_by_phone(ipcarg_t phone_hash, task_id_t *id); |
|
44 | 48 | ||
45 | /* TODO: |
49 | /* TODO: |
46 | * |
50 | * |
47 | * The current implementation of waiting on a task is not perfect. If somebody |
51 | * The current implementation of waiting on a task is not perfect. If somebody |
48 | * wants to wait on a task which has already finished before the NS asked |
- | |
49 | * the kernel to receive notifications, it would block indefinitively. |
- | |
50 | * |
- | |
51 | * A solution to this is to fail immediately on a task for which no creation |
- | |
52 | * notification was received yet. However, there is a danger of a race condition |
- | |
53 | * in this solution -- the caller has to make sure that it is not trying to wait |
52 | * The caller has to make sure that it is not trying to wait |
54 | * before the NS has a change to receive the task creation notification. This |
53 | * before the NS has a change to receive the task creation notification. This |
55 | * can be assured by waiting for this event in task_spawn(). |
54 | * can be assured by waiting for this event in task_spawn(). |
56 | * |
55 | * |
57 | * Finally, as there is currently no convention that each task has to be waited |
56 | * Finally, as there is currently no convention that each task has to be waited |
58 | * for, the NS can leak memory because of the zombie tasks. |
57 | * for, the NS can leak memory because of the zombie tasks. |
59 | * |
58 | * |
60 | */ |
59 | */ |
61 | 60 | ||
62 | /** Task hash table item. */ |
61 | /** Task hash table item. */ |
63 | typedef struct { |
62 | typedef struct { |
64 | link_t link; |
63 | link_t link; |
65 | task_id_t id; /**< Task ID. */ |
64 | task_id_t id; /**< Task ID. */ |
66 | int retval; |
65 | int retval; |
67 | bool destroyed; |
66 | bool destroyed; |
68 | } hashed_task_t; |
67 | } hashed_task_t; |
69 | 68 | ||
70 | /** Compute hash index into task hash table. |
69 | /** Compute hash index into task hash table. |
71 | * |
70 | * |
72 | * @param key Pointer keys. However, only the first key (i.e. truncated task |
71 | * @param key Pointer keys. However, only the first key (i.e. truncated task |
73 | * number) is used to compute the hash index. |
72 | * number) is used to compute the hash index. |
74 | * |
73 | * |
75 | * @return Hash index corresponding to key[0]. |
74 | * @return Hash index corresponding to key[0]. |
76 | * |
75 | * |
77 | */ |
76 | */ |
78 | static hash_index_t task_hash(unsigned long *key) |
77 | static hash_index_t task_hash(unsigned long *key) |
79 | { |
78 | { |
80 | assert(key); |
79 | assert(key); |
81 | return (LOWER32(*key) % TASK_HASH_TABLE_CHAINS); |
80 | return (LOWER32(*key) % TASK_HASH_TABLE_CHAINS); |
82 | } |
81 | } |
83 | 82 | ||
84 | /** Compare a key with hashed item. |
83 | /** Compare a key with hashed item. |
85 | * |
84 | * |
86 | * @param key Array of keys. |
85 | * @param key Array of keys. |
87 | * @param keys Must be lesser or equal to 2. |
86 | * @param keys Must be less than or equal to 2. |
88 | * @param item Pointer to a hash table item. |
87 | * @param item Pointer to a hash table item. |
89 | * |
88 | * |
90 | * @return Non-zero if the key matches the item, zero otherwise. |
89 | * @return Non-zero if the key matches the item, zero otherwise. |
91 | * |
90 | * |
92 | */ |
91 | */ |
93 | static int task_compare(unsigned long key[], hash_count_t keys, link_t *item) |
92 | static int task_compare(unsigned long key[], hash_count_t keys, link_t *item) |
94 | { |
93 | { |
95 | assert(key); |
94 | assert(key); |
96 | assert(keys <= 2); |
95 | assert(keys <= 2); |
97 | assert(item); |
96 | assert(item); |
98 | 97 | ||
99 | hashed_task_t *ht = hash_table_get_instance(item, hashed_task_t, link); |
98 | hashed_task_t *ht = hash_table_get_instance(item, hashed_task_t, link); |
100 | 99 | ||
101 | if (keys == 2) |
100 | if (keys == 2) |
102 | return ((LOWER32(key[1]) == UPPER32(ht->id)) |
101 | return ((LOWER32(key[1]) == UPPER32(ht->id)) |
103 | && (LOWER32(key[0]) == LOWER32(ht->id))); |
102 | && (LOWER32(key[0]) == LOWER32(ht->id))); |
104 | else |
103 | else |
105 | return (LOWER32(key[0]) == LOWER32(ht->id)); |
104 | return (LOWER32(key[0]) == LOWER32(ht->id)); |
106 | } |
105 | } |
107 | 106 | ||
108 | /** Perform actions after removal of item from the hash table. |
107 | /** Perform actions after removal of item from the hash table. |
109 | * |
108 | * |
110 | * @param item Item that was removed from the hash table. |
109 | * @param item Item that was removed from the hash table. |
111 | * |
110 | * |
112 | */ |
111 | */ |
113 | static void task_remove(link_t *item) |
112 | static void task_remove(link_t *item) |
114 | { |
113 | { |
115 | assert(item); |
114 | assert(item); |
116 | free(hash_table_get_instance(item, hashed_task_t, link)); |
115 | free(hash_table_get_instance(item, hashed_task_t, link)); |
117 | } |
116 | } |
118 | 117 | ||
119 | /** Operations for task hash table. */ |
118 | /** Operations for task hash table. */ |
120 | static hash_table_operations_t task_hash_table_ops = { |
119 | static hash_table_operations_t task_hash_table_ops = { |
121 | .hash = task_hash, |
120 | .hash = task_hash, |
122 | .compare = task_compare, |
121 | .compare = task_compare, |
123 | .remove_callback = task_remove |
122 | .remove_callback = task_remove |
124 | }; |
123 | }; |
125 | 124 | ||
126 | /** Task hash table structure. */ |
125 | /** Task hash table structure. */ |
127 | static hash_table_t task_hash_table; |
126 | static hash_table_t task_hash_table; |
128 | 127 | ||
- | 128 | typedef struct { |
|
- | 129 | link_t link; |
|
- | 130 | ipcarg_t phash; /**< Task ID. */ |
|
- | 131 | task_id_t id; /**< Task ID. */ |
|
- | 132 | } p2i_entry_t; |
|
- | 133 | ||
- | 134 | /** Compute hash index into task hash table. |
|
- | 135 | * |
|
- | 136 | * @param key Array of keys. |
|
- | 137 | * @return Hash index corresponding to key[0]. |
|
- | 138 | * |
|
- | 139 | */ |
|
- | 140 | static hash_index_t p2i_hash(unsigned long *key) |
|
- | 141 | { |
|
- | 142 | assert(key); |
|
- | 143 | return (*key % TASK_HASH_TABLE_CHAINS); |
|
- | 144 | } |
|
- | 145 | ||
- | 146 | /** Compare a key with hashed item. |
|
- | 147 | * |
|
- | 148 | * @param key Array of keys. |
|
- | 149 | * @param keys Must be less than or equal to 1. |
|
- | 150 | * @param item Pointer to a hash table item. |
|
- | 151 | * |
|
- | 152 | * @return Non-zero if the key matches the item, zero otherwise. |
|
- | 153 | * |
|
- | 154 | */ |
|
- | 155 | static int p2i_compare(unsigned long key[], hash_count_t keys, link_t *item) |
|
- | 156 | { |
|
- | 157 | assert(key); |
|
- | 158 | assert(keys == 1); |
|
- | 159 | assert(item); |
|
- | 160 | ||
- | 161 | p2i_entry_t *e = hash_table_get_instance(item, p2i_entry_t, link); |
|
- | 162 | ||
- | 163 | return (key[0] == e->phash); |
|
- | 164 | } |
|
- | 165 | ||
- | 166 | /** Perform actions after removal of item from the hash table. |
|
- | 167 | * |
|
- | 168 | * @param item Item that was removed from the hash table. |
|
- | 169 | * |
|
- | 170 | */ |
|
- | 171 | static void p2i_remove(link_t *item) |
|
- | 172 | { |
|
- | 173 | assert(item); |
|
- | 174 | free(hash_table_get_instance(item, p2i_entry_t, link)); |
|
- | 175 | } |
|
- | 176 | ||
- | 177 | /** Operations for task hash table. */ |
|
- | 178 | static hash_table_operations_t p2i_ops = { |
|
- | 179 | .hash = p2i_hash, |
|
- | 180 | .compare = p2i_compare, |
|
- | 181 | .remove_callback = p2i_remove |
|
- | 182 | }; |
|
- | 183 | ||
- | 184 | /** Map phone hash to task ID */ |
|
- | 185 | static hash_table_t phone_to_id; |
|
- | 186 | ||
129 | /** Pending task wait structure. */ |
187 | /** Pending task wait structure. */ |
130 | typedef struct { |
188 | typedef struct { |
131 | link_t link; |
189 | link_t link; |
132 | task_id_t id; /**< Task ID. */ |
190 | task_id_t id; /**< Task ID. */ |
133 | ipc_callid_t callid; /**< Call ID waiting for the connection */ |
191 | ipc_callid_t callid; /**< Call ID waiting for the connection */ |
134 | } pending_wait_t; |
192 | } pending_wait_t; |
135 | 193 | ||
136 | static link_t pending_wait; |
194 | static link_t pending_wait; |
137 | 195 | ||
138 | int task_init(void) |
196 | int task_init(void) |
139 | { |
197 | { |
140 | if (!hash_table_create(&task_hash_table, TASK_HASH_TABLE_CHAINS, |
198 | if (!hash_table_create(&task_hash_table, TASK_HASH_TABLE_CHAINS, |
141 | 2, &task_hash_table_ops)) { |
199 | 2, &task_hash_table_ops)) { |
142 | printf(NAME ": No memory available for tasks\n"); |
200 | printf(NAME ": No memory available for tasks\n"); |
143 | return ENOMEM; |
201 | return ENOMEM; |
144 | } |
202 | } |
- | 203 | ||
- | 204 | if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS, |
|
- | 205 | 1, &p2i_ops)) { |
|
- | 206 | printf(NAME ": No memory available for tasks\n"); |
|
- | 207 | return ENOMEM; |
|
- | 208 | } |
|
145 | 209 | ||
146 | if (event_subscribe(EVENT_WAIT, 0) != EOK) |
210 | if (event_subscribe(EVENT_WAIT, 0) != EOK) |
147 | printf(NAME ": Error registering wait notifications\n"); |
211 | printf(NAME ": Error registering wait notifications\n"); |
148 | 212 | ||
149 | list_initialize(&pending_wait); |
213 | list_initialize(&pending_wait); |
150 | 214 | ||
151 | return EOK; |
215 | return EOK; |
152 | } |
216 | } |
153 | 217 | ||
154 | /** Process pending wait requests */ |
218 | /** Process pending wait requests */ |
155 | void process_pending_wait(void) |
219 | void process_pending_wait(void) |
156 | { |
220 | { |
157 | link_t *cur; |
221 | link_t *cur; |
158 | 222 | ||
159 | loop: |
223 | loop: |
160 | for (cur = pending_wait.next; cur != &pending_wait; cur = cur->next) { |
224 | for (cur = pending_wait.next; cur != &pending_wait; cur = cur->next) { |
161 | pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link); |
225 | pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link); |
162 | 226 | ||
163 | unsigned long keys[2] = { |
227 | unsigned long keys[2] = { |
164 | LOWER32(pr->id), |
228 | LOWER32(pr->id), |
165 | UPPER32(pr->id) |
229 | UPPER32(pr->id) |
166 | }; |
230 | }; |
167 | 231 | ||
168 | link_t *link = hash_table_find(&task_hash_table, keys); |
232 | link_t *link = hash_table_find(&task_hash_table, keys); |
169 | if (!link) |
233 | if (!link) |
170 | continue; |
234 | continue; |
171 | 235 | ||
172 | hashed_task_t *ht = hash_table_get_instance(link, hashed_task_t, link); |
236 | hashed_task_t *ht = hash_table_get_instance(link, hashed_task_t, link); |
173 | if (!ht->destroyed) |
237 | if (!ht->destroyed) |
174 | continue; |
238 | continue; |
175 | 239 | ||
176 | if (!(pr->callid & IPC_CALLID_NOTIFICATION)) |
240 | if (!(pr->callid & IPC_CALLID_NOTIFICATION)) |
177 | ipc_answer_1(pr->callid, EOK, ht->retval); |
241 | ipc_answer_1(pr->callid, EOK, ht->retval); |
178 | 242 | ||
179 | hash_table_remove(&task_hash_table, keys, 2); |
243 | hash_table_remove(&task_hash_table, keys, 2); |
180 | list_remove(cur); |
244 | list_remove(cur); |
181 | free(pr); |
245 | free(pr); |
182 | goto loop; |
246 | goto loop; |
183 | } |
247 | } |
184 | } |
248 | } |
185 | 249 | ||
186 | static void fail_pending_wait(task_id_t id, int rc) |
250 | static void fail_pending_wait(task_id_t id, int rc) |
187 | { |
251 | { |
188 | link_t *cur; |
252 | link_t *cur; |
189 | 253 | ||
190 | loop: |
254 | loop: |
191 | for (cur = pending_wait.next; cur != &pending_wait; cur = cur->next) { |
255 | for (cur = pending_wait.next; cur != &pending_wait; cur = cur->next) { |
192 | pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link); |
256 | pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link); |
193 | 257 | ||
194 | if (pr->id == id) { |
258 | if (pr->id == id) { |
195 | if (!(pr->callid & IPC_CALLID_NOTIFICATION)) |
259 | if (!(pr->callid & IPC_CALLID_NOTIFICATION)) |
196 | ipc_answer_0(pr->callid, rc); |
260 | ipc_answer_0(pr->callid, rc); |
197 | 261 | ||
198 | list_remove(cur); |
262 | list_remove(cur); |
199 | free(pr); |
263 | free(pr); |
200 | goto loop; |
264 | goto loop; |
201 | } |
265 | } |
202 | } |
266 | } |
203 | } |
267 | } |
204 | 268 | ||
205 | void wait_notification(wait_type_t et, task_id_t id) |
269 | void wait_notification(wait_type_t et, task_id_t id) |
206 | { |
270 | { |
207 | unsigned long keys[2] = { |
271 | unsigned long keys[2] = { |
208 | LOWER32(id), |
272 | LOWER32(id), |
209 | UPPER32(id) |
273 | UPPER32(id) |
210 | }; |
274 | }; |
211 | 275 | ||
212 | link_t *link = hash_table_find(&task_hash_table, keys); |
276 | link_t *link = hash_table_find(&task_hash_table, keys); |
213 | 277 | ||
214 | if (link == NULL) { |
278 | if (link == NULL) { |
215 | hashed_task_t *ht = |
279 | hashed_task_t *ht = |
216 | (hashed_task_t *) malloc(sizeof(hashed_task_t)); |
280 | (hashed_task_t *) malloc(sizeof(hashed_task_t)); |
217 | if (ht == NULL) { |
281 | if (ht == NULL) { |
218 | fail_pending_wait(id, ENOMEM); |
282 | fail_pending_wait(id, ENOMEM); |
219 | return; |
283 | return; |
220 | } |
284 | } |
221 | 285 | ||
222 | link_initialize(&ht->link); |
286 | link_initialize(&ht->link); |
223 | ht->id = id; |
287 | ht->id = id; |
224 | ht->destroyed = (et == TASK_CREATE) ? false : true; |
288 | ht->destroyed = (et == TASK_CREATE) ? false : true; |
225 | ht->retval = -1; |
289 | ht->retval = -1; |
226 | hash_table_insert(&task_hash_table, keys, &ht->link); |
290 | hash_table_insert(&task_hash_table, keys, &ht->link); |
227 | } else { |
291 | } else { |
228 | hashed_task_t *ht = |
292 | hashed_task_t *ht = |
229 | hash_table_get_instance(link, hashed_task_t, link); |
293 | hash_table_get_instance(link, hashed_task_t, link); |
230 | ht->destroyed = (et == TASK_CREATE) ? false : true; |
294 | ht->destroyed = (et == TASK_CREATE) ? false : true; |
231 | } |
295 | } |
232 | } |
296 | } |
233 | 297 | ||
234 | void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid) |
298 | void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid) |
235 | { |
299 | { |
236 | ipcarg_t retval; |
300 | ipcarg_t retval; |
237 | unsigned long keys[2] = { |
301 | unsigned long keys[2] = { |
238 | LOWER32(id), |
302 | LOWER32(id), |
239 | UPPER32(id) |
303 | UPPER32(id) |
240 | }; |
304 | }; |
241 | 305 | ||
242 | link_t *link = hash_table_find(&task_hash_table, keys); |
306 | link_t *link = hash_table_find(&task_hash_table, keys); |
243 | hashed_task_t *ht = (link != NULL) ? |
307 | hashed_task_t *ht = (link != NULL) ? |
244 | hash_table_get_instance(link, hashed_task_t, link) : NULL; |
308 | hash_table_get_instance(link, hashed_task_t, link) : NULL; |
- | 309 | ||
- | 310 | if (ht == NULL) { |
|
- | 311 | retval = ENOENT; |
|
- | 312 | goto out; |
|
245 | 313 | } |
|
- | 314 | ||
246 | if ((ht == NULL) || (!ht->destroyed)) { |
315 | if (!ht->destroyed) { |
247 | /* Add to pending list */ |
316 | /* Add to pending list */ |
248 | pending_wait_t *pr = |
317 | pending_wait_t *pr = |
249 | (pending_wait_t *) malloc(sizeof(pending_wait_t)); |
318 | (pending_wait_t *) malloc(sizeof(pending_wait_t)); |
250 | if (!pr) { |
319 | if (!pr) { |
251 | retval = ENOMEM; |
320 | retval = ENOMEM; |
252 | goto out; |
321 | goto out; |
253 | } |
322 | } |
254 | 323 | ||
255 | pr->id = id; |
324 | pr->id = id; |
256 | pr->callid = callid; |
325 | pr->callid = callid; |
257 | list_append(&pr->link, &pending_wait); |
326 | list_append(&pr->link, &pending_wait); |
258 | return; |
327 | return; |
259 | } |
328 | } |
260 | 329 | ||
261 | hash_table_remove(&task_hash_table, keys, 2); |
330 | hash_table_remove(&task_hash_table, keys, 2); |
262 | retval = EOK; |
331 | retval = EOK; |
263 | 332 | ||
264 | out: |
333 | out: |
265 | if (!(callid & IPC_CALLID_NOTIFICATION)) |
334 | if (!(callid & IPC_CALLID_NOTIFICATION)) |
266 | ipc_answer_1(callid, retval, ht->retval); |
335 | ipc_answer_1(callid, retval, ht->retval); |
267 | } |
336 | } |
268 | 337 | ||
- | 338 | int ns_task_id_intro(ipc_call_t *call) |
|
- | 339 | { |
|
- | 340 | task_id_t id; |
|
- | 341 | unsigned long keys[1]; |
|
- | 342 | link_t *link; |
|
- | 343 | p2i_entry_t *e; |
|
- | 344 | ||
- | 345 | id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); |
|
- | 346 | ||
- | 347 | keys[0] = call->in_phone_hash; |
|
- | 348 | ||
- | 349 | link = hash_table_find(&phone_to_id, keys); |
|
- | 350 | if (link != NULL) |
|
- | 351 | return EEXISTS; |
|
- | 352 | ||
- | 353 | e = (p2i_entry_t *) malloc(sizeof(p2i_entry_t)); |
|
- | 354 | if (e == NULL) |
|
- | 355 | return ENOMEM; |
|
- | 356 | ||
- | 357 | link_initialize(&e->link); |
|
- | 358 | e->phash = call->in_phone_hash; |
|
- | 359 | e->id = id; |
|
- | 360 | hash_table_insert(&phone_to_id, keys, &e->link); |
|
- | 361 | ||
- | 362 | return EOK; |
|
- | 363 | } |
|
- | 364 | ||
269 | int ns_task_retval(ipc_call_t *call) |
365 | int ns_task_retval(ipc_call_t *call) |
270 | { |
366 | { |
271 | task_id_t id; |
367 | task_id_t id; |
272 | unsigned long keys[2]; |
368 | unsigned long keys[2]; |
- | 369 | int rc; |
|
273 | 370 | ||
274 | id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); |
371 | rc = get_id_by_phone(call->in_phone_hash, &id); |
- | 372 | if (rc != EOK) |
|
- | 373 | return rc; |
|
275 | 374 | ||
276 | keys[0] = LOWER32(id); |
375 | keys[0] = LOWER32(id); |
277 | keys[1] = UPPER32(id); |
376 | keys[1] = UPPER32(id); |
278 | 377 | ||
279 | link_t *link = hash_table_find(&task_hash_table, keys); |
378 | link_t *link = hash_table_find(&task_hash_table, keys); |
280 | hashed_task_t *ht = (link != NULL) ? |
379 | hashed_task_t *ht = (link != NULL) ? |
281 | hash_table_get_instance(link, hashed_task_t, link) : NULL; |
380 | hash_table_get_instance(link, hashed_task_t, link) : NULL; |
282 | 381 | ||
283 | if ((ht == NULL) || ht->destroyed) |
382 | if ((ht == NULL) || ht->destroyed) |
284 | return EINVAL; |
383 | return EINVAL; |
285 | 384 | ||
286 | ht->retval = IPC_GET_ARG3(*call); |
385 | ht->retval = IPC_GET_ARG1(*call); |
- | 386 | ||
- | 387 | return EOK; |
|
- | 388 | } |
|
- | 389 | ||
- | 390 | int ns_task_disconnect(ipc_call_t *call) |
|
- | 391 | { |
|
- | 392 | unsigned long keys[1]; |
|
- | 393 | ||
- | 394 | keys[0] = call->in_phone_hash; |
|
- | 395 | hash_table_remove(&phone_to_id, keys, 1); |
|
- | 396 | ||
- | 397 | return EOK; |
|
- | 398 | } |
|
- | 399 | ||
- | 400 | static int get_id_by_phone(ipcarg_t phone_hash, task_id_t *id) |
|
- | 401 | { |
|
- | 402 | unsigned long keys[1]; |
|
- | 403 | link_t *link; |
|
- | 404 | p2i_entry_t *e; |
|
- | 405 | ||
- | 406 | keys[0] = phone_hash; |
|
- | 407 | link = hash_table_find(&phone_to_id, keys); |
|
- | 408 | if (link == NULL) |
|
- | 409 | return ENOENT; |
|
- | 410 | ||
- | 411 | e = hash_table_get_instance(link, p2i_entry_t, link); |
|
- | 412 | *id = e->id; |
|
287 | 413 | ||
288 | return EOK; |
414 | return EOK; |
289 | } |
415 | } |
290 | 416 | ||
291 | /** |
417 | /** |
292 | * @} |
418 | * @} |
293 | */ |
419 | */ |
294 | 420 |