Rev 2071 | Rev 2637 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2359 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | /* IPC resources management |
35 | /* IPC resources management |
36 | * |
36 | * |
37 | * The goal of this source code is to properly manage IPC resources |
37 | * The goal of this source code is to properly manage IPC resources and allow |
38 | * and allow straight and clean clean-up procedure upon task termination. |
38 | * straight and clean clean-up procedure upon task termination. |
39 | * |
39 | * |
40 | * The pattern of usage of the resources is: |
40 | * The pattern of usage of the resources is: |
41 | * - allocate empty phone slot, connect | deallocate slot |
41 | * - allocate empty phone slot, connect | deallocate slot |
42 | * - disconnect connected phone (some messages might be on the fly) |
42 | * - disconnect connected phone (some messages might be on the fly) |
43 | * - find phone in slot and send a message using phone |
43 | * - find phone in slot and send a message using phone |
Line 45... | Line 45... | ||
45 | * - hangup phone (the caller has hung up) |
45 | * - hangup phone (the caller has hung up) |
46 | * - hangup phone (the answerbox is exiting) |
46 | * - hangup phone (the answerbox is exiting) |
47 | * |
47 | * |
48 | * Locking strategy |
48 | * Locking strategy |
49 | * |
49 | * |
50 | * - To use a phone, disconnect a phone etc., the phone must be |
50 | * - To use a phone, disconnect a phone etc., the phone must be first locked and |
51 | * first locked and then checked that it is connected |
51 | * then checked that it is connected |
52 | * - To connect an allocated phone it need not be locked (assigning |
52 | * - To connect an allocated phone it need not be locked (assigning pointer is |
53 | * pointer is atomic on all platforms) |
53 | * atomic on all platforms) |
54 | * |
54 | * |
55 | * - To find an empty phone slot, the TASK must be locked |
55 | * - To find an empty phone slot, the TASK must be locked |
56 | * - To answer a message, the answerbox must be locked |
56 | * - To answer a message, the answerbox must be locked |
57 | * - The locking of phone and answerbox is done at the ipc_ level. |
57 | * - The locking of phone and answerbox is done at the ipc_ level. |
58 | * It is perfectly correct to pass unconnected phone to these functions |
58 | * It is perfectly correct to pass unconnected phone to these functions and |
59 | * and proper reply will be generated. |
59 | * proper reply will be generated. |
60 | * |
60 | * |
61 | * Locking order |
61 | * Locking order |
62 | * |
62 | * |
63 | * - first phone, then answerbox |
63 | * - first phone, then answerbox |
64 | * + Easy locking on calls |
64 | * + Easy locking on calls |
65 | * - Very hard traversing list of phones when disconnecting because |
65 | * - Very hard traversing list of phones when disconnecting because the phones |
66 | * the phones may disconnect during traversal of list of connected phones. |
66 | * may disconnect during traversal of list of connected phones. The only |
67 | * The only possibility is try_lock with restart of list traversal. |
67 | * possibility is try_lock with restart of list traversal. |
68 | * |
68 | * |
69 | * Destroying is less frequent, this approach is taken. |
69 | * Destroying is less frequent, this approach is taken. |
70 | * |
70 | * |
71 | * Phone call |
71 | * Phone call |
72 | * |
72 | * |
73 | * *** Connect_me_to *** |
73 | * *** Connect_me_to *** |
74 | * The caller sends IPC_M_CONNECT_ME_TO to an answerbox. The server |
74 | * The caller sends IPC_M_CONNECT_ME_TO to an answerbox. The server receives |
75 | * receives 'phoneid' of the connecting phone as an ARG3. If it answers |
75 | * 'phoneid' of the connecting phone as an ARG3. If it answers with RETVAL=0, |
76 | * with RETVAL=0, the phonecall is accepted, otherwise it is refused. |
76 | * the phonecall is accepted, otherwise it is refused. |
77 | * |
77 | * |
78 | * *** Connect_to_me *** |
78 | * *** Connect_to_me *** |
79 | * The caller sends IPC_M_CONNECT_TO_ME, with special |
79 | * The caller sends IPC_M_CONNECT_TO_ME. |
80 | * The server receives an automatically |
80 | * The server receives an automatically opened phoneid. If it accepts |
81 | * opened phoneid. If it accepts (RETVAL=0), it can use the phoneid |
81 | * (RETVAL=0), it can use the phoneid immediately. |
82 | * immediately. |
- | |
83 | * Possible race condition can arise, when the client receives messages |
82 | * Possible race condition can arise, when the client receives messages from new |
84 | * from new connection before getting response for connect_to_me message. |
83 | * connection before getting response for connect_to_me message. Userspace |
85 | * Userspace should implement handshake protocol that would control it. |
84 | * should implement handshake protocol that would control it. |
86 | * |
85 | * |
87 | * Phone hangup |
86 | * Phone hangup |
88 | * |
87 | * |
89 | * *** The caller hangs up (sys_ipc_hangup) *** |
88 | * *** The caller hangs up (sys_ipc_hangup) *** |
90 | * - The phone is disconnected (no more messages can be sent over this phone), |
89 | * - The phone is disconnected (no more messages can be sent over this phone), |
91 | * all in-progress messages are correctly handled. The anwerbox receives |
90 | * all in-progress messages are correctly handled. The answerbox receives |
92 | * IPC_M_PHONE_HUNGUP call from the phone that hung up. When all async |
91 | * IPC_M_PHONE_HUNGUP call from the phone that hung up. When all async |
93 | * calls are answered, the phone is deallocated. |
92 | * calls are answered, the phone is deallocated. |
94 | * |
93 | * |
95 | * *** The answerbox hangs up (ipc_answer(EHANGUP)) |
94 | * *** The answerbox hangs up (ipc_answer(EHANGUP)) |
96 | * - The phone is disconnected. EHANGUP response code is sent |
95 | * - The phone is disconnected. EHANGUP response code is sent |