]>
Commit | Line | Data |
---|---|---|
946b016d AR |
1 | /** |
2 | \defgroup AsyncCalls Asynchronous Calls | |
3 | \ingroup Components | |
4 | ||
5 | ||
6 | \section Terminology Terminology | |
7 | ||
8 | - \b Call: an AsyncCall object meant to be delivered from the Caller to the | |
9 | Recipient. | |
10 | - \b Recipient: the code being the destination of the Call. The specific | |
11 | function receiving the call is often called "handler". | |
12 | - \b Caller: the code scheduling or placing the Call. | |
13 | - \b Creator: the code creating the Call. | |
14 | - \b Dialing: the final act of delivering the Call to the Recipient. | |
15 | - \b Canceling: preventing the call from being dialed in the future. | |
16 | - <b>Pending call</b>: the call which has been scheduled but no attempt to dial | |
17 | it has been made. | |
18 | - <b>Live call</b>: the in-progress call that has been dialed and the Recipient | |
19 | (receiving) function has not finished yet. | |
20 | ||
21 | ||
22 | \section Life Typical life cycle | |
23 | ||
24 | -# Creator creates a Call object and stores its pointer, possibly in a | |
25 | temporary variable. If Creator is the future Recipient of the Call, it | |
26 | is customary to talk about a "callback". In such context, Creator gives | |
27 | the Call pointer to some other code (the future Caller). Calls are | |
28 | refcounted and the AsyncCall::Pointer class must be used to point and | |
29 | share them. | |
30 | -# Time passes and something triggers the need to dial the call. | |
31 | -# Caller schedules (a.k.a, places) the Call. The Call is placed in the | |
32 | AsyncCallQueue. The queue preserves the scheduling call order. | |
33 | -# Time passes and it is now time to dial the call. | |
34 | -# AsyncCallQueue checks whether the call can be dialed. If yes, | |
35 | AsyncCallQueue dials the Call and the Recipient receives it. Otherwise, | |
36 | only a debugging message is logged (if enabled). Dialing a call involves | |
37 | several state checks at several stages, depending on the Call type. | |
38 | -# The Call is alive while the Recipient is handling it. That state ends | |
39 | when the Recipient code (a.k.a., handler) returns. At that point, the | |
40 | AsyncCallQueue proceeds to handle other calls. | |
41 | -# The Call object is destroyed when the last reference to it is gone. | |
42 | One should not try to invalidate or delete the call. | |
43 | ||
44 | ||
45 | \section Rules Basic rules | |
46 | ||
47 | - Callbacks must be called: If a Caller has a Call pointer as a | |
48 | callback, the Caller must make that Call when conditions are right | |
49 | (possibly with a call-specific error indicator). Whether that Call will | |
50 | be dialed is irrelevant here. | |
51 | ||
52 | - Unwanted calls must be canceled: If Recipient may not be able to | |
53 | handle the call back, then it must cancel it. Whether that Call will be | |
54 | scheduled is irrelevant here. If the Recipient has an AsyncCall pointer, | |
55 | calling AsyncCall::cancel is sufficient, but the code should use | |
56 | call-specific APIs when possible (e.g., comm_read_cancel or comm_close). | |
57 | ||
58 | - Processed calls should be forgotten: If you scheduled, received, or | |
59 | cancel the call, set its pointer to NULL. The Caller should forget the | |
60 | call after scheduling it. the recipient should forget the call when it | |
61 | receives or cancels it. These are just cleanup rules to avoid | |
62 | double-scheduling or double-cancellation as well as situations where the | |
63 | code assumes it can still change a pending Call (which will not work for | |
64 | SMP code). | |
65 | ||
66 | - The calls are received in the order they were scheduled. | |
67 | ||
68 | - The Recipient is guaranteed to receive at most one Call at a time. An | |
69 | attempt to dial call B while some call A is alive is a bug, and call B | |
70 | will not be dialed. | |
71 | ||
72 | ||
73 | \section Canceling Call Canceling | |
74 | ||
75 | - A call may be canceled at any time. | |
76 | ||
77 | - A canceled call will not be dialed. | |
78 | ||
79 | - Cancellation has immediate effect: The call will never be dialed | |
80 | after cancel() is called | |
81 | ||
82 | - Cancellation by non-Recipients is discouraged because it may not work | |
83 | in an SMP environment. | |
84 | ||
85 | - A late call cancellation is cancellation that is performed after the Call | |
86 | has already been dialed (i.e., the call is or was alive at the time of the | |
87 | cancellation). Late cancellation is a no-op. It is not a bug to cancel | |
88 | something late, but the canceling code should be aware of that possibility. | |
89 | ||
90 | ||
91 | */ |